func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; long long arr[200005], pos[200005]; int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); ; long long n; cin >> n; cout << n << ; if (n == 1) { cout << 1 ; return 0; } if (n % 2) { long long tmp = 1; ...
#include <bits/stdc++.h> using namespace std; long long n, r1, r2, r3, d; const int N = 1e6 + 4; long long dp[N][2]; long long a[N]; void debug() { cout << -----debug----- << endl; for (int i = 1; i <= n; ++i) { printf( dp[%d][%d]=%lld dp[%d][%d]=%lld n , i, 0, dp[i][0], i, 1, dp[i][1]); ...
#include <bits/stdc++.h> int main(void) { int n; int a[1100]; while (scanf( %d , &n) == 1) { for (int i = 0; i < n; i++) scanf( %d , a + i); int cnt = 1, ans = 0; int j = 0; if (n <= 2) { printf( %d n , ans); break; } if (a[0] > a[1]) j = -1; ...
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; vector<set<int> > g(n + 1); map<int, int> co; for (int i = 0; i < m; i++) { int n1, n2; cin >> n1 >> n2; g[n1].insert(n2); g[n2].insert(n1); co[n1]++; co[n2]++; } int m...
// REMEMBER USING MOD INVERSE WHILE DOING COMBINATORICS // REMEMBER using int32_t while typecasting size into int #include<bits/stdc++.h> using namespace std; #define pb push_back #define int long long #define all(x) x.begin(),x.end() #define nl n #define ok cout<< OK n #define ios ios_base::...
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; const double PI = acos(-1.); const double eps = 1e-10; const int INF = 0x3f3f3f3f; const long long INFll = 0x3f3f3f3f3f3f3f3f; const int MAXN = 1e6 + 5; const int MX = 123456; const int inf = 0x3f3f3f3f; const int MXE = 1e7; st...
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) #pragma GCC optimize( unroll-loops ) #pragma GCC target( avx,avx2,tune=native ) template <typename T> using Prior = std::priority_queue<T>; template <typename T> using prior = std::priority_queue<T, std::vector<T>, std::greater<T>>; using namespace ...
#include <bits/stdc++.h> using namespace std; inline long long maxi(long long &a, long long b) { if (b > a) { a = b; return 1; } return 0; } inline long long mini(long long &a, long long b) { if (b < a) { a = b; return 1; } return 0; } inline long long maxi(lo...
#include <bits/stdc++.h> using namespace std; int main() { long long n, i, j, k, m, t, x, y, sum; cin >> t; while (t > 0) { t = t - 1; cin >> n >> k; long long a[n], c[k]; for (i = 0; i < n; i++) { cin >> a[i]; } for (i = 0; i < k; i++) { cin >> c[i]; ...
#include <bits/stdc++.h> using namespace std; double eps = 1e-9; const int INF = 1e9 + 7; const int MAXN = int(2e5 + 7); int n, a[3], sum, g[10][10], d[10], ans = INF * 2; string second[7] = { Anka , Chapay , Cleo , Troll , Dracul , Snowy , Hexadecimal }; int get(strin...
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; const unsigned long long inf = 1e18; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; vector<unsigned long long> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } unsi...
#include <bits/stdc++.h> using namespace std; const int inf = 1e9; const int MOD = 1e9 + 7; const int N = 2e6 + 10; int n, m, x, a[N], fi[N]; long long pos[N]; void prepare() { scanf( %d%d , &n, &m); for (auto i = 0; i < n; i++) scanf( %d , a + i), a[n + i] = a[i]; for (auto i = 1; i <= m; i++...
#include <bits/stdc++.h> using namespace std; int n, m, d; int a[(1 << 20) + 5]; int sum[(1 << 20) + 5]; int b[22][100005]; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> m >> d; for (int i = 0; i < m; i++) { int x, y; cin >> x; for (int ...
#include <bits/stdc++.h> using namespace std; template <class T> inline void read(T &x) { x = 0; long long f = 0; char ch = getchar(); while (!isdigit(ch)) f = ch == - , ch = getchar(); while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar(); x = f ? -x : x; } const lo...
#include <bits/stdc++.h> using namespace std; const int maxn = 100; long long n, k; int a[15]; long long rc[15], p[15], ans; void solve() { scanf( %d%d , &n, &k); k++; scanf( %d , &a[1]); rc[1] = 1; long long now = 1, tmp; int ss = 0; for (int i = 2; i <= n; i++) { scanf( %...
#include <bits/stdc++.h> using namespace std; const int mxN = 1e5; int n; string ans; int kmp(string s) { vector<int> pf(s.size()); for (int j = 1; j < s.size(); ++j) { int k = pf[j - 1]; while (s[k] != s[j]) { if (!k) { k = -1; break; } k = pf[k...
#include <bits/stdc++.h> using namespace std; const long long int mod = 1e9 + 7; const long long int MOD = 1e18 + 7; long long int modPow(long long int a, long long int b) { long long int res = 1; a %= mod; for (; b; b >>= 1) { if (b & 1) res = res * a % mod; a = a * a % mod; } r...
#include <bits/stdc++.h> using namespace std; template <typename tp> inline void read(tp& x) { x = 0; char tmp; bool key = 0; for (tmp = getchar(); !isdigit(tmp); tmp = getchar()) key = (tmp == - ); for (; isdigit(tmp); tmp = getchar()) x = (x << 3) + (x << 1) + (tmp ^ 0 ); if (key) x = ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); int a, b, c, d, i, j, n, flag = 0; cin >> a >> b >> c >> d; n = max(max(a, b), max(c, d)); flag = 1; for (i = 0; i <= n; i++) { for (j = 0; j <= n; j++) { ...
#include <bits/stdc++.h> using namespace std; int main() { string a, b; cin >> a >> b; int m = 0, n = 0, c = 0; m = a.length(); n = b.length(); int x = n - 1; if (m != n) { cout << NO ; return 0; } for (int i = 0; i < m; i++) { if (a[i] == b[x]) { c++; ...
#include <bits/stdc++.h> const long long int mod = 1e9 + 7; using namespace std; bool prime(long long int n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; for (long long int i = 5; i * i <= n; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) r...
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; cin.get(); vector<string> v(n); for (int i = 0; i < n; i++) getline(cin, v[i]); vector<int> p(k); for (int i = 0; i < k; i++) p[i] = i; int minDiff = INT_MAX; do { int minNum, maxNum; ...
#include <bits/stdc++.h> using namespace std; const int maxN = 200009; vector<int> a; vector<int> b; vector<int> bb; int main() { long long s, x; cin >> s >> x; int s1 = s, x1 = x; int ans = 0; for (int i = 0; i < 45; i++) { if ((s & ((long long)1 << i)) && (x & ((long long)1 << i)...
#include <bits/stdc++.h> using namespace std; int n, p, q, d[110]; void nhap() { memset(d, 0, sizeof(d)); int x; cin >> n >> p; for (int i = 1; i <= p; i++) { cin >> x; d[x] = 1; } cin >> q; for (int i = 1; i <= q; i++) { cin >> x; d[x] = 1; } } void cbi...
#include <bits/stdc++.h> using namespace std; const int MAXN = 600010; struct wl { int k, l, pos; }; wl w[MAXN]; wl temp[MAXN]; int n; int p[MAXN]; int cnt, tcnt; int *t; int x[MAXN], y[MAXN]; int find(int p) { int l = 0, r = tcnt; while (l < r) { int mid = (l + r) / 2; i...
#include <bits/stdc++.h> using namespace std; vector<long long int> g[200001], rg[200001]; bool vis[200001]; long long int par[200001]; long long int sz[200001], dnom[200001]; long long int ans = 0, no = 0; long long int n, m, S; deque<long long int> top; void dfs(long long int x) { vis[x] = 1; ...
#include <bits/stdc++.h> using namespace std; int main() { int n, w[26][26]; int money, cost, temp; char a[100002], b[100002], x, y; char result[100002]; for (int i = 0; i < 26; ++i) { for (int j = 0; j < 26; ++j) { w[i][j] = 1073741823; } w[i][i] = 0; } cin >> ...
#include <bits/stdc++.h> using namespace std; const long long N = 1e4 + 7; const long long M = 1e3 + 7; const long long INF = 1e18; long long n, m, k, a[N], g, r, ans; bool h[N][M], ok; queue<pair<long long, long long> > q; vector<long long> v; int32_t main() { ios_base::sync_with_stdio(false); ...
#include <bits/stdc++.h> using namespace std; int tobin(string s) { int ans = 0; for (int i = 0; i < s.size(); i++) { ans |= 1 << (s[i] - a ); } return ans; } int main() { int n, mask, save = 0; cin >> n; mask = (1 << 26) - 1; while (n--) { char c, c2; string s...
#include <bits/stdc++.h> using namespace std; const long long max_n = 1000006; inline long long read() { long long x = 0; bool w = 0; char c = getchar(); while (c < 0 || c > 9 ) w |= c == - , c = getchar(); while (c >= 0 && c <= 9 ) x = (x << 1) + (x << 3) + (c ^ 48), c = getchar(...
#include <bits/stdc++.h> using namespace std; int main() { vector<int> v; bool g; int n, m[5001] = {0}, x; cin >> n; if (n % 2 == 1) { v.push_back(1); m[1] = 1; } else { v.push_back(2); m[2] = 1; } while (true) { g = false; for (int i = 1; i <= n; ...
#include <bits/stdc++.h> using namespace std; int dp_pos[1000010], dp_neg[1000010]; int mark_pos[1000010], mark_neg[1000010]; int pos[1000010], neg[1000010], cnt_pos = 0, cnt_neg = 0; int max_pos, max_neg; int a[1000010]; void calc(int* dp, int* mark) { int cnt = 0, i, j; for (i = 0; i <= max_pos ...
#include <bits/stdc++.h> using namespace std; int main() { int n, check = 0; string x; cin >> n >> x; sort(x.begin(), x.end()); if (n == 1) cout << YES ; else { for (int i = 0; i < x.size() - 1; i++) { if (x[i] == x[i + 1]) { check = 1; break; ...
#include <bits/stdc++.h> const int N = 1e5 + 10; using namespace std; map<int, int> mp; struct a { int x, y, z; }; vector<a> res; int main() { int n; cin >> n; for (int i = 1; i <= n; ++i) { int t; cin >> t; mp[t]++; } priority_queue<pair<int, int>> pq; for (a...
#include <bits/stdc++.h> using namespace std; template <class T> void _R(T &x) { cin >> x; } void _R(int &x) { scanf( %d , &x); } void _R(int64_t &x) { scanf( %lld , &x); } void _R(double &x) { scanf( %lf , &x); } void _R(char &x) { scanf( %c , &x); } void _R(char *x) { scanf( %s , x); } void R...
#include <bits/stdc++.h> using namespace std; long long a[10000], b[10000]; long long res[10000]; int val[10000]; map<long long, int> mp; int main() { int n; long long ans = 0; int len = 0; cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; mp[a[i]]++; if (mp[a[i]] =...
#include <bits/stdc++.h> using namespace std; template <class T> void deba(T *a, int n) { for (int i = 0; i < n; i++) cout << a[i] << ; cout << n ; } const int N = 5e5 + 10, M = 5e5 + 10; long long n, m, c[N], t[N], num, ans[N]; vector<pair<long long, long long> > e3[N]; vector<long long> e...
#include <bits/stdc++.h> using namespace std; int n, m1, m2; long long C[4005][4005], f[4005], ret; long long MOD = 1000000009; int main() { for (int i = 0; i <= 4000; i++) { C[i][0] = C[i][i] = 1; for (int j = 1; j <= i; j++) C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % MOD; } ...
#include <bits/stdc++.h> using namespace std; const int maxn = 3e5 + 5; const int maxm = 305; long long a[maxn]; long long c[11][maxn]; long long num[maxn]; long long n, m, v, k; int main() { cin >> n >> m >> k; for (int i = 0; i < n; i++) { cin >> a[i]; } sort(a, a + n); long ...
#include <bits/stdc++.h> using namespace std; long long int n, m, i, j, k, l, T, u, v, q, t = 0, t1 = 0, te, c = 0; long long int a[1010], b[1010]; long long int gcd(long long int p, long long int q) { if (q == 0) return p; else return gcd(q, p % q); } int main() { std::ios::sync_wit...
#include <bits/stdc++.h> using namespace std; int main() { long long n, isum = 0; cin >> n; if (n % 2 == 0) cout << ((n + 1) * (n + 1) - 1) / 4; else cout << ((n + 1) * (n + 1)) / 4; }
#include <bits/stdc++.h> using namespace std; long long n; long long head[1100000], a[1100000]; struct node { long long v, nex; } bian[2100000]; long long cnt; void add(long long x, long long y) { bian[++cnt].v = y; bian[cnt].nex = head[x]; head[x] = cnt; } long long tot[1100000], d[11...
#include <bits/stdc++.h> using namespace std; long long N, K, L, R; long long G, A; long long ans; void run(int use, long long ntot) { if (N <= 500000) { for (int nplus = 0; nplus <= N - 1; nplus++) { long long rr = (N + nplus + use); long long rv = G + (1 + use); long long n...
#include <bits/stdc++.h> using namespace std; template <typename T> inline T abs(T t) { return t < 0 ? -t : t; } const long long modn = 1000000007; inline long long mod(long long x) { return x % modn; } const int MAXN = 312345; int n, m; vector<long long> s[4]; struct pd { long long x; i...
#include <bits/stdc++.h> using namespace std; const int N = 2005, MOD = 1e9 + 7; int d, n, a[N], dp[N], rt; vector<int> g[N]; void dfs(int v, int pr = -1) { dp[v] = 1; for (int to : g[v]) { if (to == pr) { continue; } if (a[to] < a[rt] || a[to] > a[rt] + d) { continue...
#include <bits/stdc++.h> using namespace std; int main() { int k, d, i, j; cin >> k >> d; if (d != 0) { for (i = 1; i <= k; i++) { if (i == 1) cout << d; else cout << 0; } } if (d == 0) { if (k == 1) cout << 0; else cout...
#include<bits/stdc++.h> #define ll long long using namespace std; const int N = 2e5 + 10; struct Seg_Tree { struct { int l, r, num; ll sum, sL, sR; } t[N << 3]; #define update(p) { t[p].sum = ...
#include <bits/stdc++.h> using namespace std; long long tot, n, w, b, x; deque<pair<long long, long long> > maxq; void add(long long val, long long pos) { while (maxq.size() > 0 && maxq.back().first <= val) maxq.pop_back(); maxq.push_back({val, pos}); } long long query() { return maxq.front().first;...
#include <bits/stdc++.h> using namespace std; void solve() { string s; cin >> s; long long int n = s.size(); map<char, long long int> r; for (long long int i = 0; i < n; i++) { r[s[i]]++; } long long int k = 0, cnt = 0; for (auto it = r.begin(); it != r.end(); it++) { if ...
#include <bits/stdc++.h> using namespace std; bool isVowel(char c) { return (c == a || c == e || c == i || c == o || c == u ); } int main() { vector<string> v; int cnt[] = {5, 7, 5}; for (int i = 0; i < 3; i++) { string s; char c; cin >> c; getline(cin, s); ...
#include <bits/stdc++.h> using namespace std; ifstream fin( Sisend.txt ); long long t, n, m, arv; string s[105]; vector<int> v; void pane(int i1, int j1, int i2, int j2, int i3, int j3) { v.emplace_back(i1 + 1), v.emplace_back(j1 + 1), v.emplace_back(i2 + 1), v.emplace_back(j2 + 1), v.emplace_ba...
#include <bits/stdc++.h> using namespace std; const int N = 100000; int n, k, p[N], gk[256], gl[256]; int main() { cin >> n >> k; memset(gk, -1, sizeof(gk)); for (int i = 0; i < n; i++) { cin >> p[i]; } for (int i = 0; i < n; i++) { int cc = p[i]; if (gk[cc] == -1) { ...
#include <bits/stdc++.h> using namespace std; mt19937 rnd(228); const int M = 1791791791; const int B = 239; int main() { ios::sync_with_stdio(0); cin.tie(0); int n, m; cin >> n >> m; vector<string> a(n), b(m); for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 1e1; long long n; long long r, avg; long long must, ans = 0, sum = 0; pair<long long, long long> d[MAXN]; int main() { cin >> n >> r >> avg; long long x, y; for (long long i = 1; i <= n; i++) { scanf( %I64d%I64d , &x, &...
#include <bits/stdc++.h> using namespace std; int a[100001]; stack<int> st; int main() { ios::sync_with_stdio(0); int n; cin >> n; long long int sum = 0; for (int i = 0; i < n; i++) cin >> a[i]; sum += a[0]; for (int i = 1; i < n; i++) sum += max(a[i] - a[i - 1], 0); cout << sum ...
#include <bits/stdc++.h> using namespace std; int main() { long long xx, yy, n, m, i, g, j, k, x, y; std::vector<long long> v; vector<pair<long long, long long>> vp; cin >> n >> m; map<pair<long long, long long>, long long> mp; for (i = 0; i < m; i++) { cin >> x >> y; vp.push_bac...
#include <bits/stdc++.h> using namespace std; long long sum = 0, n, m; const long long mod = 1e9 + 7; long long f[25]; long long qpow(long long a, long long b) { long long ans = 1; while (b) { if (b & 1) ans = (ans * a) % mod; a = (a * a) % mod; b >>= 1; } return ans; } l...
#include <bits/stdc++.h> const int inf = 1e5 + 10; const long long mod = 998244353; const int LARGEST = 0x3f3f3f3f; int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } int dx[] = {0, 1, 1, 1, 0, -1, -1, -1}; int dy[] = {1, 1, 0, -1, -1, -1, 0, 1}; int bx[] = {0, 1, 0, -1}; int by[] = {-1, 0, 1, 0}; ...
#include <bits/stdc++.h> const double PI = acos(-1.0); using namespace std; const int MAXN = 200117, MAXM = 1200117, C = 5, MAXX = 1000000120; int n, k, a[MAXN], b, c, m, p[MAXM]; long long ans, s[C]; priority_queue<long long> q[C]; inline void add(int x) { int rx = ((x % C) + C) % C; for (int i =...
#include <bits/stdc++.h> using namespace std; long long int po(long long int x, long long int y, long long int p) { long long int res = 1; x = x % p; while (y > 0) { if (y & 1) res = (res * x) % p; y >>= 1; x = (x * x) % p; } return res % p; } long long int modInverse(long ...
#include <bits/stdc++.h> using namespace std; struct listNode { long long int n; listNode *next; listNode(long long int n = 0LL) : n(n), next(NULL) {} }; long long int num; listNode *edge[100100], *tail[100100]; long long int color[100100]; void insertEdge(long long int a, long long int b) { ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { (i + j) % 2 ? cout << B : cout << W ; } cout << endl; } }
#include <bits/stdc++.h> using namespace std; int main() { string s1; int tc; cin >> tc; getchar(); while (tc--) { cin >> s1; for (int i = 0; i < s1.length(); i += 2) { cout << s1[i]; } cout << s1[s1.size() - 1] << endl; } }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; long long row1[n], row2[n]; for (int i = 0; i < n; i++) cin >> row1[i]; for (int i = 0; i < n; i++) cin >> row2[i]; long long first, second, pref = 0, pres = 0; for (int i = 0; i < n; i++) { first = max(pre...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; int a[n], i, j, ans = 1; int c[201][n + 1]; vector<int> v[201]; memset(c, 0, sizeof(c)); for (i = 0; i < n; i++) { cin >> a[i]; v[a[i]].pus...
#include <bits/stdc++.h> const int maxn = 100010; char s[maxn]; int main() { int a = 0, b = 0, c = 0, i; scanf( %s , s); int len = strlen(s); if (s[0] == ) || s[len - 1] == ( || s[0] == # ) { printf( -1 n ); return 0; } for (i = len - 1; i >= 0; i--) { if (s[i] == (...
#include <bits/stdc++.h> using namespace std; int min(int a, int b) { if (a > b) return b; else return a; } int main() { int tc; cin >> tc; while (tc--) { long long int n; cin >> n; vector<int> a(n + 1, 0); vector<int> ans(n + 1, 0); for (int i = 1; ...
#include <bits/stdc++.h> using namespace std; int n, m; vector<vector<int> > D; int main(int argc, char **argv) { cin >> n >> m; for (int i = 0; i < n; i++) { string t; cin >> t; D.push_back(vector<int>()); for (int j = 0; j < m; j++) { D[D.size() - 1].push_back(t[j] == ...
#include <bits/stdc++.h> using namespace std; const int N = 111; const int INF = (int)1e9; const int mod = (int)1e9 + 7; int n, m; vector<int> v[N]; int get(int i, int j) { if (i > j) swap(i, j); int s = j - i; s = min(s, m - s); return s; } int get_res(int x, int y) { auto left = ...
#include <bits/stdc++.h> int read() { register int x = 0; register char f = 1, ch = getchar(); for (; !isdigit(ch); ch = getchar()) if (ch == - ) f = !f; for (; isdigit(ch); ch = getchar()) x = (x << 1) + (x << 3) + (ch ^ 0 ); return f ? x : -x; } int n, fac[200005], dp[200005], sz[200...
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 4; int n, k, a[N]; bool used[N], inStack[N]; set<int> s; set<int> q; void add(int& it) { if (s.size() && *s.begin() < a[it]) { cout << -1; exit(0); } inStack[a[it]] = 1; used[a[it]] = 1; s.insert(a[it]); ...
#include <bits/stdc++.h> using namespace std; using ll = long long; const int MAXN = 100; int cnt[MAXN]; int pre[MAXN]; ll fact[MAXN]; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); fact[0] = 1; for (int i = 1; i < MAXN; i++) { fact[i] = fact[i - 1] * i; }...
#include <bits/stdc++.h> using namespace std; int n, m; int d[5001]; int t[5001]; int l[5001]; int r[5001]; int x[5001]; vector<int> cl, cr, num, cx; int eksi[5001]; int ek[5001][5001]; int main() { ios_base::sync_with_stdio(false); cin >> n >> m; for (int i = 1; i <= n; i++) d[i] = 10...
#include <bits/stdc++.h> using namespace std; inline long long read() { long long x = 0, f = 1; char ch = getchar(); while (ch < 0 || ch > 9 ) { if (ch == - ) f = -1; ch = getchar(); } while (ch >= 0 && ch <= 9 ) { x = x * 10 + ch - 0 ; ch = getchar(); } r...
#include <bits/stdc++.h> using namespace std; char g[8][8]; int calc(int x, int y, int a, int d) { int res = 0; while (x != d) { x += a; ++res; if (g[x][y] != . ) return 2e9; } return res; } int main() { for (int i = 0; i < 8; ++i) scanf( %s , g[i]); int a = 2e9, b =...
#include <bits/stdc++.h> using namespace std; int main() { cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false); long long n, d; cin >> n >> d; long long a[105] = {0}; long long pref[105] = {0}; for (long long i = 1; i <= n; i++) { cin >> a[i]; if (a[i] % 2 != 0) pre...
#include<bits/stdc++.h> #define ll long long int #define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); using namespace std; int main(){ ll t; cin>>t; while(t--){ ll n,k1,k2,w,b; cin>>n>>k1>>k2; ...
#include <bits/stdc++.h> using namespace std; template <typename T, typename U> inline void smin(T &a, U b) { if (a > b) a = b; } template <typename T, typename U> inline void smax(T &a, U b) { if (a < b) a = b; } template <typename T> inline void gn(T &first) { char c, sg = 0; while (...
#include <bits/stdc++.h> using namespace std; long long dp[3005][3005]; string s, t; int n, m; inline long long solve(int l, int r) { int id = r - l + 1; if (r >= n) return 0ll; if (l == 0) { for (int i = r + 1; i < m; i++) { if (t[i] != s[id]) return 0ll; id++; } ...
#include <bits/stdc++.h> using namespace std; long long read() { long long sign = 1, x = 0; char s = getchar(); while (s > 9 || s < 0 ) { if (s == - ) sign = -1; s = getchar(); } while (s >= 0 && s <= 9 ) { x = (x << 3) + (x << 1) + s - 0 ; s = getchar(); } ...
#include <bits/stdc++.h> using namespace std; int a[200000]; int s[200000]; int n, p, k; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int tc; cin >> tc; while (tc--) { cin >> n >> p >> k; for (int i = 0; i < n; ++i) cin >> a[i]; sort(a, a + n); int ...
#include <bits/stdc++.h> using namespace std; int n, a[101], nxt, l, h; int main(int argc, const char* argv[]) { scanf( %d , &n); for (int i = 0; i < n; i++) { scanf( %d , &a[i]); } int mn = 10001; for (int i = 0; i < n; i++) { nxt = i + 1; nxt %= n; if (mn > abs(a[i] -...
#include <bits/stdc++.h> using namespace std; int main() { int n, ans = 0; cin >> n; ans = (n * (n + 1)) / 2; if (ans & 1) cout << 1 << endl; else cout << 0 << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int n, t; int main() { cin >> n >> t; if (n == 8 && t == 10) { cout << 11111110; return 0; } if (n == 18 & t == 10) { cout << 111111111111111110; return 0; } if (n == 1 && t == 10) { cout << -1; return 0; ...
#include <bits/stdc++.h> using namespace std; struct Node { int l, r; Node(int l, int r) : l(l), r(r) {} bool operator<(const Node &o) const { return r - l == o.r - o.l ? r > o.r : r - l > o.r - o.l; } }; vector<int> event; int arr[200000]; map<int, int> matching; map<int, int> cloak...
#include <bits/stdc++.h> using namespace std; int main() { int k, n, s, p, b, c; cin >> k >> n >> s >> p; float a = (n * 1.0) / s; b = ceil(a); c = b * k; float d = (c * 1.0) / p; int t = ceil(d); cout << t; }
#include <bits/stdc++.h> using namespace std; long long n, k, cur_div; vector<long long> cnt; bool check(long long x) { long long tot = 0; for (long long i = 0; i < 26; i++) { tot += cnt[i] / x; if (tot >= cur_div) { return true; } } return false; } void solve() { ...
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize( Ofast ) #pragma GCC target( avx,avx2,fma ) #pragma GCC optimization( unroll-loops ) mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); void __print(int x) { cout << x; } void __print(long x) { cout << x; } void __print...
#include <bits/stdc++.h> using namespace std; int main() { string s; char b, c; int n, m; int l, r; cin >> n >> m; cin >> s; for (int j = 1; j <= m; j++) { cin >> l >> r >> b >> c; for (int i = l - 1; i < r; i++) { if (s[i] == b) { s[i] = c; } ...
#include <bits/stdc++.h> using namespace std; int main() { long long r; vector<long long> a; cin >> r; for (int i = 0; i < r; i++) { long long aux; cin >> aux; a.push_back(aux); } a.push_back(a[0]); long long n = 0, m = 1; long long min = abs(a[0] - a[1]); for (...
#include <bits/stdc++.h> using namespace std; uint64_t l, r, s; set<uint64_t> S; void f(uint64_t x) { S.insert(x); if (x < r) f(x * 10 + 4), f(x * 10 + 7); } int main() { cin >> l >> r; for (f(0); l <= r;) { auto it = S.lower_bound(l); s += (min(r, *it) - l + 1) * *it; l = ...
#include <bits/stdc++.h> using namespace std; long long ab(long long x) { return x > 0LL ? x : -x; } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long n, k, sum = 0, x; cin >> n >> k; vector<long long> v; for (long long i = 0; i < n; i++) { cin >> x; ...
#include <bits/stdc++.h> using namespace std; char a[10010]; char b[10010], c[1010], d[1010]; int main() { while (scanf( %s%s , a, b) != EOF) { int len = strlen(a); sort(a, a + len); int flag = 0; for (int i = 0; i < len; i++) { if (a[i] != 0 ) { flag = i; ...
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; const long long INF = LLONG_MAX; void solve() { long long k; cin >> k; string s; cin >> s; long long test[10] = {0}; long long sum = 0; for (long long i = 0; i < s.size(); i++) { int digit = s[i] - 0 ...
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; vector<int> adj[N], nodesAtDepth[N]; int degree[N], Dist[N]; bool isDiam[N]; int n; int bfs(int start) { queue<pair<int, int>> q; q.push({start, start}); Dist[start] = 0; int mxDist = -1; int mxNode = -1; while (!...
#include <bits/stdc++.h> using namespace std; int h[4] = {0, 0, 1, -1}; int v[4] = {1, -1, 0, 0}; vector<vector<int> > adj; bool *visited; int num[501][501]; bool done = false; int sourceR, sourceC, destR, destC; void DFS(int vertix) { if (!done) { visited[vertix] = true; for (int i = ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> v; int max = 0; int mi = 0; for (int i = 0; i < n; ++i) { int temp; cin >> temp; v.push_back(temp); if (temp > max) { max = temp; mi = i; } } for (int...
#include <bits/stdc++.h> const double PI = 3.1415926; const int KL = 1e6; using namespace std; long long q, x, y, z, n, m, p[KL], mn = 1e9, mx = -1e9, ans; string t; vector<int> vec[KL]; set<int> s; map<int, int> M; int pr[KL], sz[KL]; int prfind(int node) { if (pr[node] == node) return no...
#include <bits/stdc++.h> using namespace std; int main() { int n, tmp; cin >> n; multiset<int> a; for (int i = 0; i < n; i++) { cin >> tmp; a.insert(tmp); } int ans = 0; while (!a.empty()) { int h = 0; while (a.lower_bound(h) != a.end()) { a.erase(a.lower_...
#include <bits/stdc++.h> using namespace std; bool sortbysec(const pair<int, int> a, const pair<int, int> b) { return a.second < b.second; } int main() { string s1; cin >> s1; string s2; cin >> s2; bool flag = false; string ans = 0 ; for (int i = 0; i < s1.length(); i++) { ...