func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; const double PI = 2 * acos(0.0); mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); mt19937_64 rng_64(chrono::steady_clock::now().time_since_epoch().count()); const string DIGITS = 0123456789 ; const string ALPH = abcdefghijklmnopqrstuvwxyz ;...
#include <bits/stdc++.h> int nextInt() { int x; scanf( %d , &x); return x; } double nextDouble() { double x; scanf( %lf , &x); return x; } long long nextLong() { long long x; scanf( %I64d , &x); return x; } char nextChar() { char x; scanf( %c , &x); return x...
#include <bits/stdc++.h> using namespace std; int qtable[9][9]; int x_min[9]; int x_max[9]; int y_min[9]; int y_max[9]; int solve_problem() { int n, m, k, s; if (scanf( %d %d %d %d , &n, &m, &k, &s) != 4) return 1; fill(x_min, x_min + k, numeric_limits<int>::max()); fill(x_max, x_max + k, ...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:66777216 ) using namespace std; void sIO(); void iIO(); void fIO(string fn); const long long INF = 1000000003LL; const long long BI = (long long)1e18; int n; long long c, a[1111], b[1111], lg, l, r, m; long long check(long long x) { long l...
#include <bits/stdc++.h> using namespace std; int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1}; int dy8[] = {1, -1, 1, -1, 0, 0, -1, 1}; const double PI = acos(-1.0); const double EPS = 1e-6; const int MOD = (int)1e9 + 7; const int maxn = (int)2e5 + 5; int cnt[maxn]; int main() { ios_base::sync_with_stdio(...
#include <bits/stdc++.h> const int INF = 0x3f3f3f3f; using namespace std; const int N = 255; int t, n, m, k; char s[N][N]; int dx[8] = {-1, -1, -1, 0, 0, 1, 1, 1}; int dy[8] = {-1, 0, 1, -1, 1, -1, 0, 1}; void dfs(int x, int y) { s[x][y] = ! ; k++; for (int i = 0; i <= 7; i++) { int x...
#include <bits/stdc++.h> using namespace std; long long two(int x) { return 1LL << x; } int get(long long p, int i) { return (p >> (i - 1)) & 1; } long long count(int n, int k, long long pre) { long long ret = 0; bool rev = true, inv = true; for (int i = 1; i + i <= n; i++) { if (i <= k && n -...
#include <bits/stdc++.h> using namespace std; const int N = (int)2e5 + 50, LOGN = 17; const int INF = (int)1e9; int n, k; int ord[N], in[N], tim = 0; char las[N]; int lc[N], rc[N]; int res[N]; string str; void dfs(int v) { if (lc[v] != -1) dfs(lc[v]); ord[tim] = v; in[v] = tim++; if ...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; vector<int> a(n); for (size_t i = 0; i < n; i++) { cin >> a[i]; } sort(a.begin(), a.end(), greater<int>()); int x = a[0], y = 0; for (size_t i = 0; i ...
#include <bits/stdc++.h> using namespace std; unordered_map<long long, vector<long long>> m3; vector<long long int> v; long long a; int dfs(long long i, long long p) { long long k, k1, j, t; k = -1; k1 = 0; for (j = 0; j < m3[i].size(); j++) { long long d = m3[i][j]; if (d != p) { ...
#include <bits/stdc++.h> using namespace std; int32_t main() { long long t = 1; while (t--) { long long n, d; cin >> n >> d; vector<long long> temp(n); vector<long long> temp2(n); for (long long i = 0; i < n; i++) { cin >> temp[i]; } for (long long i = 0; i ...
#include <bits/stdc++.h> using namespace std; int main() { ifstream ff( file.txt ); int n, k; cin >> n >> k; string s1; cin >> s1; n = s1.length(); if (k == 0) { cout << s1 << endl; return 0; } int j = 0; bool b1 = false, b2 = false; for (int i = 0; i < n - 2;...
#include <bits/stdc++.h> using namespace std; int get() { int x = 0; char s = getchar(); while (s < 0 || s > 9 ) s = getchar(); while (s >= 0 && s <= 9 ) x = (x << 3) + (x << 1) + (s ^ 48), s = getchar(); return x; } int Min(const int x, const int y) { if (x < y) return x; ...
#include <bits/stdc++.h> using namespace std; struct st { int t, x, id; }; const int INF = 1000 * 1000 * 1000; bool operator<(const st &a, const st &b) { return a.x < b.x || a.x == b.x && a.t < b.t; } int main() { st st_inf; st_inf.x = INF; st_inf.t = INF; st_inf.id = INF; int ...
#include <bits/stdc++.h> using namespace std; long long sq(long long k) { return k * k; } long long knan(long long k, long long n) { if (n == 1) return k; else if (n == 0) return 1; else { if (n % 2 == 0) return sq(knan(k, n / 2)) % 1000000007; else return (k * ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long int t; cin >> t; while (t--) { long long int n, k; cin >> n >> k; long long int a, b, c, d; cin >> a >> b; cin >> c >> d; ...
#include <bits/stdc++.h> using namespace std; template <class T> inline void rd(T &x) { char ch; x = 0; bool fl = false; while (!isdigit(ch = getchar())) (ch == - ) && (fl = true); for (x = (ch ^ 0 ); isdigit(ch = getchar()); x = x * 10 + (ch ^ 0 )) ; (fl == true) && (x = -x); }...
#include <bits/stdc++.h> using namespace std; int n, b, m; int a[100009], sum[100009]; map<int, int> h; int main() { cin >> b >> m >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; sum[i] = (sum[i - 1] + a[i]) % (b - 1); } long long zero = 0, t = 0; for (int i = 1; i <= n; i++)...
#include <bits/stdc++.h> using namespace std; int c(int x) { int rev = 0; int tambah = 1; while (x != 0) { int temp = x % 10; if (temp == 4 || temp == 7) { rev += (tambah * (temp)); tambah *= 10; } x /= 10; } return rev; } int main() { int a, b; ...
#include <bits/stdc++.h> using namespace std; const int MOD(1000000007); const int INF((1 << 30) - 1); const int MAXN(55); int a[MAXN]; string b[MAXN]; string gen(int x) { string ret = ; if (x < 26) ret += A ; else ret += B ; ret += ( a + x % 26); return ret; } int...
#include <bits/stdc++.h> using namespace std; const int N = 15; int k, n, m, x, y, ans; int dz[6] = {0, 0, 0, 0, 1, -1}; int dx[6] = {0, 0, 1, -1, 0, 0}; int dy[6] = {1, -1, 0, 0, 0, 0}; char plt[N][N][N]; bool mark[N][N][N]; bool isval(int a, int b, int c) { if (a < k && a >= 0 && b < n && b >= 0...
#include <bits/stdc++.h> using namespace std; using vi = vector<int>; using vvi = vector<vi>; int main() { int N; cin >> N; vvi tree(N); for (int i = 0; i < N - 1; ++i) { int a, b; cin >> a >> b; a--; b--; tree[a].push_back(b); tree[b].push_back(a); } ...
#include <bits/stdc++.h> using namespace std; inline void file() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } int main() { char b[10000]; int a; cin >> a; int c = 0; for (int i = 0; i < a; ++i) { cin >> b[0] >> b[1] >> b[2]; if (b[0] == - and...
#include <bits/stdc++.h> using namespace std; int a[1000005]; int main() { int t, n; cin >> t; while (t--) { cin >> n; int g = 0, s = 0, b = 0; int m = n / 2; for (int i = 1; i <= n; i++) { cin >> a[i]; } int i = 1; while (a[i] == a[1] && i <= m) { ...
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 500; char s[N]; int son[N][26]; int fail[N], pos[N]; int n, m; int cnt; inline void insert(char s[], int n, int id) { int i, cur = 0; for (i = 1; i <= n; i++) { if (!son[cur][s[i] - a ]) son[cur][s[i] - a ] = ++cnt; ...
#include <bits/stdc++.h> using namespace std; int main() { int n; string s; cin >> n; cin >> s; if (!(n % 2)) { for (int i = 0; i < n; ++i) { cout << s[i]; if (i % 2 && i != n - 1) cout << - ; } } else { for (int i = 0; i < n - 3; ++i) { cout << s[i...
#include <bits/stdc++.h> int main() { int n, k; scanf( %d %d , &n, &k); while (k > 0) { if (n % 10 == 0) n /= 10; else n--; k--; } printf( %d , n); }
#include <bits/stdc++.h> using namespace std; long long n, m, s, tmp1, tmp2; vector<long long> ans; vector<vector<long long>> g(100000); bool vs[2][100000]; bool vs1[100000] = {0}, rc[100000] = {0}; bool a = false, w = false, d = false, t = false; long long cnt = 0; void hasc(long long v) { vs1[v ...
#include <bits/stdc++.h> using namespace std; vector<vector<pair<int, int> > > Adj; vector<int> Col; bool DFS(int u, int f) { Col[u] = 1 + f; bool pos = 0; for (auto i : Adj[u]) { if (Col[i.first]) { if ((f ^ i.second) == Col[i.first] - 1) continue; else ret...
#include <bits/stdc++.h> using namespace std; int N; char s[1005], z[1005]; int solve1() { int ans = 0; int lz, rz, ls, rs; lz = ls = 0; rz = rs = N - 1; while (ls <= rs) { if (z[rz] >= s[rs]) rz--, rs--; else ans++, lz++, rs--; } return ans; } int sol...
#include <bits/stdc++.h> using namespace std; const int N = 105; int dr8[] = {0, 0, 1, -1, 1, 1, -1, -1}; int dc8[] = {1, -1, 0, 0, -1, 1, -1, 1}; int dr4[] = {0, 1, -1, 0}; int dc4[] = {1, 0, 0, -1}; int dp[N][N][15][15][2]; int n1, n2, n, k1, k2; int calc(int f, int h, int tf, int th, int pr) { ...
#include <bits/stdc++.h> using namespace std; inline int rd() { int x = 0, f = 1; char ch = getchar(); while (!isdigit(ch)) { if (ch == - ) f = -1; ch = getchar(); } while (isdigit(ch)) x = x * 10 + (ch ^ 48), ch = getchar(); return x * f; } const int N = 100009; int n, m,...
#include <bits/stdc++.h> using namespace std; vector<int> adj[1100]; int need[1100]; bool visit[1100]; vector<pair<int, int> > vec; int exist[1100]; void bfs(int st) { queue<pair<int, int> > q; memset(visit, 0, sizeof visit); q.push({st, 0}); while (!q.empty()) { int u = q.front().fi...
#include <bits/stdc++.h> using namespace std; int N; pair<int, int> P[105]; int main() { cin >> N; for (int i = 1; i <= N; i++) cin >> P[i].first >> P[i].second; int K; cin >> K; for (int i = 1; i <= N; i++) if (K >= P[i].first && K <= P[i].second) { cout << N - i + 1 << n ; ...
#include <bits/stdc++.h> using namespace std; const int N = 300005; const long long int inf = 1e18; long long int a[N]; long long int b[N]; long long int dp[N][3]; int main() { int t; cin >> t; while (t--) { int n; scanf( %d , &n); for (int i = 1; i <= n; i++) scanf( %lld %ll...
#include <bits/stdc++.h> using namespace std; const int N = (int)1e7 + 2; const int M = (int)5e5 + 2; const int mod = (int)1e9 + 7; int mu[N], cnt[N]; int n, mx, x, p[M]; long long res; int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); if (fopen( test ...
#include <bits/stdc++.h> using namespace std; unordered_map<string, int> M; vector<string> WHAT; vector<int> LEFT, RIGHT; int check(int v, int place) { vector<int> V = {v}; for (int i = 0; i < (int)WHAT.size(); i++) { if (WHAT[i][0] == 0 or WHAT[i][0] == 1 ) V.push_back(WHAT[i][place]...
#include <bits/stdc++.h> int main() { const int N = 8; std::string pokemons[] = { vaporeon , jolteon , flareon , espeon , umbreon , leafeon , glaceon , sylveon }; int n; scanf( %d n , &n); std::string hidden; std::cin >> hidden; std::string output = ...
#include <bits/stdc++.h> using namespace std; int main() { long n, m; while (cin >> n >> m) { long long a[100100], b[101000], p, x, i, j, mm, l, r, cc = 0, pp, y, m1, qq = 0; l = 1; r = n + 1; while (l <= r) { x = (l...
#include <bits/stdc++.h> using namespace std; int main() { int a, b, i, n = 0, j = 0; cin >> a >> b; int k = sqrt(a); if (a == b) { cout << infinity << endl; } else ; if (a != b) { for (i = 1; i * i <= a; i++) { if ((a - b) % i == 0 && i > b) n++; if ((a -...
#include <bits/stdc++.h> using namespace std; const int maxn = 6e5 + 10; int n, k, l[maxn][2]; int fa[maxn], sz[maxn]; string s; int get_fa(int x) { if (x == fa[x]) return x; return fa[x] = get_fa(fa[x]); } int calc(int x) { int y; if (x <= k) y = x + k; else y = x - k; ...
#include <bits/stdc++.h> using namespace std; template <typename t> t in(t q) { cin >> q; return q; } template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { os << [ ; for (int i = 0; i < ((int)(v).size()); ++i) { os << v[i]; if (i != ((int)(v).size()) - 1) ...
#include <bits/stdc++.h> using namespace std; const int MAXN = (1LL << 21) + 10; int N, T, len, Imakf, bits[MAXN]; long long a[MAXN], b[MAXN]; char tem[MAXN]; void fi(const char* tem) { if (!strlen(tem)) return; char A[50]; const char B[4] = { . , i , n , 0}, C[5] = { . , o , u , t , 0}; ...
#include <bits/stdc++.h> using namespace std; long long r, m, n, x, y, a[5000005], b[5000005]; long long fb(long long i, long long j, long long p) { if (p < b[i]) return i - 1; if (p >= b[j]) return j; long long mid = (i + j) / 2; if (b[mid] >= p && b[mid + 1] < p) return mid; if (b[mid] > p) ...
#include <bits/stdc++.h> using namespace std; vector<long long> graph[300005]; long long col[300005]; long long ans, r, b; pair<long long, long long> dfs(long long x, long long p = -1) { long long a1, b1; a1 = 0; b1 = 0; if (col[x] == 1) a1++; if (col[x] == 2) b1++; for (long long i = ...
#include <bits/stdc++.h> using namespace std; int t; string s; int main() { cin >> t; while (t--) { cin >> s; int n = s.size(); int ans = n + 1, l = 0, c[4] = {0}; for (int i = 0; i < n; i++) { c[s[i] - 0 ]++; while (c[1] > 0 && c[2] > 0 && c[3] > 0) { ...
#include <bits/stdc++.h> using namespace std; int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); int tt; cin >> tt; while (tt--) { int n, Q; cin >> n >> Q; string s; cin >> s; vector<int> pre(n, 0); pre[0] = s[0] == + ? 1 : -1; for (int i = 1; ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; long long a[200005]; long long b[200005]; int i; for (i = 0; i < n; i++) { cin >> a[i]; a[i] = a[i] * (i + 1) * (n - i); } for (i = 0; i < n; i++) { cin >> b[i]; } sort(a, a + n); ...
/** Micro Mezz Macro Flation -- Overheated Economy ., Last Update: Mar. 3th 2013 **/ //{ /** Header .. **/ //{ #define LOCAL #include <functional> #include <algorithm> #include <iostream> #include <fstream> #include <sstream> #include <iomanip> #include <numeric> #include <cstring> #include ...
#include <bits/stdc++.h> using namespace std; int h; long long n, des; long long GetRes(long long l) { if (l == 1) return 0; if ((l + l / 2) % 2) { return 1 + GetRes(l / 2); } else { return pow(2, h - (int)(log2(l)) + 1) + GetRes(l / 2); } } int main() { while (cin >> h >> n)...
#include <bits/stdc++.h> using namespace std; int main() { int a[1000]; int b[1000]; for (int i = 0; i < 1000; i++) a[i] = 1; int n, k, r = 1, fl; cin >> n >> k; for (int i = 0; i < k; i++) { cin >> b[i]; a[b[i]] = 0; } for (int i = 0; i < k; i++) { fl = 1; co...
#include <bits/stdc++.h> const int maxn = 2e5 + 10; const int inf = 0x3f3f3f3f; const long long INF = 0x3f3f3f3f3f3f3f3f; using namespace std; int q, op, pos, r, x, len, l; char ch[10], str[maxn]; int tr[26][maxn]; int lowbit(int x) { return x & (-x); } void update(int x, int y, int n, int p) { fo...
#include <bits/stdc++.h> using namespace std; struct Data { int sgn; long long delta; set<pair<long long, long long>> ranges; void flip(int a) { sgn = -sgn, delta = a - delta; } void trim(int l, int r) { if (l > r) return; long long xl = sgn * (l - delta), xr = sgn * (r - delta); ...
#include <bits/stdc++.h> using namespace std; const int INF = 1000000000; int n, k, m; int a[1000000]; int main() { ios_base::sync_with_stdio(0); cin >> n >> k; int d = 0; if (n % 2 == 1) { d = (n / 2 + 1) * (n / 2 + 1); d += (n / 2) * (n / 2); } else { d = (n / 2) * (n /...
#include <bits/stdc++.h> using namespace std; const int maxn = 2e4 + 100; const int maxq = 2e4 + 100; const int maxd = 15; const int ha1 = 317, ha2 = 443, mod = 364417; struct Que_Typ { int y, id; Que_Typ(int a = 0, int b = 0) { y = a, id = b; } }; int N, Que; vector<Que_Typ> ope[maxn]; long...
#include <bits/stdc++.h> using namespace std; using std::cin; using std::cout; long long MOD = 998244353; int main() { long long n, q; cin >> n >> q; for (int i = 0; i < q; i++) { long long curr; cin >> curr; string s; cin >> s; for (int c = 0; c < s.size(); c++) { ...
#include <bits/stdc++.h> using namespace std; const int NN = 100 * 1000 + 5; map<pair<pair<int, long long>, int>, long long> dp; vector<int> adj[NN]; vector<long long> x; long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } const int mod = (int)1e9 + 7; int rec(int node, int pa...
#include <bits/stdc++.h> using namespace std; vector<long long int> graph[100001]; bool vis[100001]; vector<long long int> ans; void dfs(long long int root) { vis[root] = true; ans.push_back(root); sort(graph[root].begin(), graph[root].end()); for (int i = 0; i < graph[root].size(); i++) { ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int cost; double amount; cin >> cost; string s[n]; for (int i = 0; i < n; i++) { cin >> s[i]; } int counter = 0; double sum = 0.0; for (int i = n - 1; i >= 0; i--) { if (s[i] == halfp...
#include <bits/stdc++.h> using namespace std; int read() { int x = 0, y = 1; char ch = ; for (; (ch != - && (ch > 9 || ch < 0 )); ch = getchar()) ; if (ch == - ) y = -1, ch = getchar(); for (; ch >= 0 && ch <= 9 ; ch = getchar()) x = x * 10 + ch - 48; return x * y; } co...
#include <bits/stdc++.h> using namespace std; bool tep(pair<string, int> a, pair<string, int> b) { return a.second > b.second; } bool f(string s) { for (int i = 0; i < 10; i++) { if ((i == 2 || i == 5) && s[i] != - ) return 0; if ((i != 2 && i != 5) && s[i] == - ) return 0; } if (s...
#include <bits/stdc++.h> using namespace std; double pie = 3.14159265358979323846; bool isPowerOfTwo(long long int n) { if (n == 0) return false; return (ceill(log2l(n)) == floorl(log2l(n))); } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long int ...
#include <bits/stdc++.h> using namespace std; void solve() { int n; cin >> n; string s; cin >> s; int ans = n; for (int i = 0; i < n / 2; i++) { string temp1 = s.substr(0, i + 1); string temp2 = s.substr(i + 1, i + 1); if (temp1 == temp2) ans = min(ans, n - i); } co...
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; const int M = 2e3 + 50; const int INF = 0x7fffffff; const int mod = 1e9 + 7; const int sz = 18; const double eps = 1e-10; const double pi = acos(-1); long long n, m; char str[N]; int f[N]; template <class T> inline void read(...
#include <bits/stdc++.h> int main(void) { int n, m; scanf( %d%d , &n, &m); char c; scanf( %c , &c); int i, j; char word[n + 2][m + 2]; for (i = 0; i < n + 2; i++) for (j = 0; j < m + 2; j++) word[i][j] = W ; int v[n + 1], h[m + 1]; for (i = 0; i <= n; i++) v[i] = 0; for ...
#include <bits/stdc++.h> #pragma GCC optimize(4) using namespace std; char _buf[100000], *_p1 = _buf, *_p2 = _buf; inline int gi() { int x = 0, f = 1; char ch = getchar(); while (ch < 0 || ch > 9 ) { if (ch == - ) f = -1; ch = getchar(); } while (ch >= 0 && ch <= 9 ) { ...
#include <bits/stdc++.h> using namespace std; int main() { long long l, r, k, p, num; cin >> l >> r >> k; num = 1; int ans = 0; while (num <= r) { if (num >= l && num <= r) { cout << num; ans++; } num *= k; if (ans != 0) cout << endl; if (num % k != ...
#include <bits/stdc++.h> using namespace std; int main() { int ttt; cin >> ttt; for (int tttt = 0; tttt < ttt; tttt++) { long long n, m, a, b, x, y, xw1, yw1, xw2, yw2, xb1, yb1, xb2, yb2, sumw = 0, sumb = 0, tb, tw, x1, y1, x2, y2; cin >> n >> m; cin >> xw1 >> yw1 >> xw2 >> ...
#include <bits/stdc++.h> using namespace std; string s, p; int cnt[26], cnt1[26], ans; bool check() { for (int i = 0; i < 26; i++) if (cnt[i] > cnt1[i]) return false; return true; } int main() { cin >> s >> p; if (p.size() > s.size()) { cout << 0; return 0; } for (i...
#include <bits/stdc++.h> using namespace std; int n; string name[1001]; int fen[1001]; vector<pair<string, int> > old; vector<pair<int, string> > xin; vector<int> ff; int main(int argc, char *argv[]) { cin >> n; for (int i = 0; i < n; i++) { cin >> name[i] >> fen[i]; old.push_back(ma...
#include <bits/stdc++.h> using namespace std; const int MAXN = 300; char s[MAXN]; int n; void solve() { int maxv = 0, x = 0, y = 0, sum = 0, f = 0; s[n++] = _ ; s[n] = 0; for (int i = 0; i < n; ++i) { if (!f) { if (s[i] == _ ) { x = 0; } else if (s[i] != ( ) ...
#include <bits/stdc++.h> using namespace std; int main() { int n, m, num, maxs = INT_MIN, mins = INT_MAX, mins2 = INT_MAX; cin >> n >> m; vector<int> v1; vector<int> v2; for (int i = 0; i < n; i++) { cin >> num; v1.push_back(num); maxs = max(maxs, num); mins2 = min(mins2,...
#include <bits/stdc++.h> using namespace std; int main() { int n, r = 0, m = 0; string s; cin >> n; while (!cin.eof()) { cin >> s; for (int i = 0; i < s.size(); i++) { if (int(s[i]) > 64 && int(s[i]) < 91) { r++; } } if (r > m) { m = r; ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 212345, OFFSET = 3; struct BITree { long long a[MAXN]; void clear() { memset(a, 0, sizeof(a)); } int lowbit(int i) { return (i & -i); } long long sum(int i) { long long ret = 0; for (i += OFFSET; i > 0; i -= lowbit(i)) ret ...
#include <bits/stdc++.h> using namespace std; int main() { long long n, m; cin >> n >> m; vector<long long> a(n); for (long long i = 0; i < n; i++) { cin >> a[i]; } sort(a.begin(), a.end()); long long sum = 0; for (long long i = 0; i < m; i++) { if (a[i] <= 0) sum += a[i]...
#include <bits/stdc++.h> using namespace std; const int MAXN = 1000; bool g[MAXN][MAXN]; bool mh[MAXN], mv[MAXN]; bool use[MAXN]; int main() { int n, m; cin >> n >> m; for (int i = 0; i < m; i++) { int a, b; cin >> a >> b; a--; b--; g[a][b] = true; mv[a] = tru...
#include <bits/stdc++.h> using namespace std; vector<vector<long long int> > v, dp; long long int ans, k; void dfs(long long int u, long long int par) { long long int i; dp[u][0] = 1; for (auto it : v[u]) { if (it == par) continue; dfs(it, u); for (i = 1; i <= k; i++) ans += dp[it]...
#include <bits/stdc++.h> using namespace std; const int N = 4e4 + 1; int n, m, x[N], y[N], freq[N], q[N], vis[N], match[N], T, ans[N]; vector<int> g[N]; bool get(int u) { vis[u] = T; for (auto i : g[u]) { if (match[i] != -1 && vis[match[i]] == T) continue; if (match[i] == -1 || get(match[i...
#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; const int kMod = 998244353; int inv(int b) { int e = kMod - 2; int r = 1; while (e) { if (e ...
#include <bits/stdc++.h> using namespace std; int main() { int n; scanf( %d , &n); int arr[n], odd = 0, even = 0; for (int i = 0; i < n; i++) { scanf( %d , arr + i); if (arr[i] % 2) odd++; else even++; } sort(arr, arr + n); reverse(arr, arr + n); lon...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(NULL); int m, n; cin >> m >> n; set<int> v[m]; for (int i = 0; i < m; i++) { int s; cin >> s; for (int j = 0; j < s; j++) { int x; cin >> x; ...
#include <bits/stdc++.h> using namespace std; struct Point { long long x, y; Point() {} Point(long long x0, long long y0) : x(x0), y(y0) {} void in() { scanf( %I64d %I64d , &x, &y); } long long operator*(Point pt) { return x * pt.y - y * pt.x; } Point operator-(Point pt) { return Point(x - p...
#include <bits/stdc++.h> using namespace std; vector<int> L[200005], W[200005]; vector<pair<long long, int> > path; int a[200005], add[200005], rmv[200005]; int res[200005]; void DFS(int u, long long dis) { int v, w, rem1 = 0, rem2 = 0; path.push_back(make_pair(dis, u)); for (int i = 0; i < L[u]...
#include <bits/stdc++.h> using namespace std; long long getint() { long long summ = 0, f = 1; char ch; for (ch = getchar(); !isdigit(ch) && ch != - ; ch = getchar()) ; if (ch == - ) { f = -1; ch = getchar(); } for (; isdigit(ch); ch = getchar()) summ = (summ << 3) +...
#include <bits/stdc++.h> using namespace std; const int maxn = 3e5 + 10; struct edge { long long to; long long cost; }; vector<edge> mp[maxn]; long long dis[maxn]; long long vis[maxn]; long long dis1[maxn]; long long a[maxn]; long long b[maxn]; long long N, M, k; long long cot[maxn]; b...
#include <bits/stdc++.h> using namespace std; const int ans[401] = { 0, 1, 9, 245, 126565, 54326037, 321837880, 323252721, 754868154, 328083248, 838314395, 220816781, 893672292, 166441208, 251255697, 114256285, 118775501, 482714697, 11784725, 460862131, 550384565...
#include <bits/stdc++.h> using namespace std; const int INF = INT_MAX; const long long LINF = LLONG_MAX; int main() { std::ios_base::sync_with_stdio(false); int n, m; cin >> n >> m; vector<int> a(n, 0); int ind = 0, length = n + 1; for (int i = 0; i < m; i++) { int l, r; cin ...
#include <bits/stdc++.h> using namespace std; int main() { int n, z = 0; cin >> n; char *colours = new char[50]; for (int x = 0; x < n; x++) { cin >> colours[x]; } for (int i = 0; i < n - 1; i++) { if (colours[i] == colours[i + 1]) { z++; } } delete[] colour...
#include <bits/stdc++.h> using namespace std; const int maxn = 1000100; const int INF = (1 << 29); const double EPS = 0.000000001; const double Pi = acos(-1.0); int n; long long x[maxn]; int main() { while (cin >> n) { for (int i = 1; i <= n; i++) scanf( %I64d , &x[i]); sort(x + 1, x + n...
#include <bits/stdc++.h> using namespace std; const double eps = 0.000000000000001; int n, k; double P[21]; bool eq(long double a, long double b) { if (abs(a - b) < 0.000000000000001) return true; return false; } bool memo[1 << 21]; long double dp[1 << 21]; long double doit(int msk) { if (...
#include <bits/stdc++.h> using namespace std; template <typename T, typename U> inline void smin(T &a, const U &b) { if (a > b) a = b; } template <typename T, typename U> inline void smax(T &a, const U &b) { if (a < b) a = b; } template <class T> inline void gn(T &first) { char c, sg = 0; ...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cout.precision(10); int n; cin >> n; set<string> st; while (n--) { string s, ss; cin >> s; for (int i = s.size() - 1; i >= 0; i--) { if (s[i] == u ) { ss += oo ; ...
#include <bits/stdc++.h> using namespace std; long long cnt, ans, i, j, temp, flag; string s, heavy = heavy , metal = metal ; int main() { cin >> s; for (i = 0; i < s.length(); i++) { temp = i; flag = 0; for (j = 0; j < 5; j++) { if (s[temp] == heavy[j]) ++temp; ...
#include <bits/stdc++.h> using namespace std; map<long long int, map<long long int, bool> > my; int main() { long long int n; cin >> n; my[1][n] = 1; if (n % 2 == 0) { cout << white << endl; cout << 1 << << 2 << endl; } else cout << black << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const long long INF = 1e9 + 7; const int N = 5e2 + 10; int a[N][N]; int b[N][N]; int c[N][N]; int minv[N]; int main() { int n, m, k; scanf( %d%d%d , &n, &m, &k); memset((minv), (0x3f), sizeof(minv)); for (int i = 1; i <= n; i++) { scanf...
#include <bits/stdc++.h> const int INF = 1e9 + 1; const int MOD = 1e9 + 7; using namespace std; void solve() { int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; i += 1) cin >> a[i]; ; sort(a.begin(), a.end()); vector<int> ans; for (int i = 0; i < n; i += 1) { for (i...
#include <bits/stdc++.h> using namespace std; int graph[101][101]; int dp[101][101][26]; int dfs(int x, int y, int curr, int n) { if (dp[x][y][curr] != -1) { return dp[x][y][curr]; } for (int i = 0; i < n; i++) { if (graph[x][i] >= curr) { if (!dfs(y, i, graph[x][i], n)) { ...
#include <bits/stdc++.h> using namespace std; int main() { int n, i, f[1001], l[1001]; bool rated = false; cin >> n; for (i = 0; i < n; i++) { cin >> f[i] >> l[i]; if (f[i] != l[i]) { rated = true; cout << rated << endl; return 0; } } if (!rated) {...
#include <bits/stdc++.h> using namespace std; const int N = 800005; int n, m, q, sa[N], sb[N], s[N]; set<int> a[N], b[N]; void modify(int x, int l, int r, int k, int val, int id) { if (l == r) { if (id) sa[x] = val; else sb[x] = val; s[x] = (sa[x] <= -sb[x]); return...
#include <bits/stdc++.h> using namespace std; int soch(int a) { if (a == 3) return 1; return soch(a - 1) * a / (a - 3); } int main() { int n, num, i, j, k, raz, dob, num1, dob1, sum = 0, flag = 0, flag1 = 0; bool graf[105][105]; bool graf1[6][6]; vector<pair<int, int>> ver; vector<in...