func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; bool check(int a, int b) { bool dig[10] = {0}; while (a > 0) { dig[a % 10] = true; a /= 10; } while (b > 0) { if (dig[b % 10]) { return true; } b /= 10; } return false; } int main() { int a; cin >...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); int t; t = 1; while (t--) { int c = 0; std::vector<int> v; string s[3]; getline(cin, s[0]); getline(cin, s[1]); getline(cin, s[2]); for (int i = 0; i <= 2; i+...
#include <bits/stdc++.h> using namespace std; int main() { string a, b; cin >> a >> b; string s = ; sort(b.rbegin(), b.rend()); if (a.size() > b.size()) s = b.substr(0, a.size()); else s = b; for (int i = 0; i < a.size(); i++) { if (a[i] == 9 ) continue; ...
#include <bits/stdc++.h> using namespace std; int main() { string s, ans = ; cin >> s; int i = 0, j = s.size() - 1; while (i < j) { if (s[i] == s[j]) { i++; j--; continue; } else { s.insert(s.begin() + j + 1, s[i]); i++; } } cout <<...
#include <bits/stdc++.h> using namespace std; int main() { int n, flag; cin >> n; int a[n]; for (int i = 0; i < n; i++) cin >> a[i]; if (n == 2) cout << a[0] + 2 * (a[1] - a[0]); else { for (int i = 0; i < n - 2; i++) { if ((a[i + 2] - a[i + 1]) != (a[1 + i] - a[i])) { ...
#include <bits/stdc++.h> using namespace std; void Read(int &p) { p = 0; char c = getchar(); for (; c < 0 || c > 9 ; c = getchar()) ; for (; c >= 0 && c <= 9 ; c = getchar()) p = p * 10 + c - 0 ; } struct ma { int x, y; ma(int _x = 0, int _y = 0) : x(_x), y(_y) {} }; boo...
#include <bits/stdc++.h> using namespace std; long long expo(long long base, long long exponent, long long mod) { long long ans = 1; while (exponent != 0) { if (exponent & 1) ans = (1LL * ans * base) % mod; base = (1LL * base * base) % mod; exponent >>= 1; } return ans % mod; } ...
#include <bits/stdc++.h> using namespace std; int main() { int n, c = 0; cin >> n; int arr[n]; set<int> s; for (int i = 0; i < n; i++) cin >> arr[i]; sort(arr, arr + n); for (int i = 1; i < n; i++) { if (arr[i] == arr[i - 1]) { c++; arr[i]++; } else if (arr[i]...
#include <bits/stdc++.h> using namespace std; int main() { long long int a, b, s = 0; cin >> a >> b; while (b > 1) { if (b > a) swap(a, b); s += a / b; a -= (b * (a / b)); if (a < 1) break; } s += a; cout << s << endl; return 0; }
#include <bits/stdc++.h> using namespace std; long long int mod_Expo(long long int x, long long int n, long long int M) { if (x == 0) return 0; if (n == 0) return 1; else if (n % 2 == 0) return mod_Expo((x * x) % M, n / 2, M); else return (x * mod_Expo((x * x) % M, (n - 1) / 2, M))...
#include <bits/stdc++.h> using namespace std; int main() { int n, sum = 0; cin >> n; int a[n][2], maxi = -100; for (int i = 0; i < n; i++) { for (int j = 0; j < 2; j++) { cin >> a[i][j]; } } for (int i = 0; i < n; i++) { for (int j = 0; j <= 0; j++) { sum = ...
#include <bits/stdc++.h> using namespace std; const long long int maxN = 2e5 + 100; const long long int maxM = 1e3 + 100; const long long int mod = 1e9 + 7; const long long int hmod = 1e16 + 7; const long double PI = 3.141592653; const long double eps = 1e-8; const long long int D = 1379; const long l...
#include <bits/stdc++.h> using namespace std; string s; long long heavy; long long ukupno; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cerr.tie(0); cin >> s; heavy = 0; ukupno = 0; for (int i = 4; i < s.size(); i++) { if (s[i] == l && s[i - 1...
#include <bits/stdc++.h> using namespace std; int main() { int n, a[93], b[93]; scanf( %d , &n); int ans = 0; a[0] = 0; for (int i = 1; i <= n; i++) { scanf( %d , &a[i]); b[i - 1] = a[i] - a[i - 1]; } b[n] = 90 - a[n]; for (int i = 0; i <= n; i++) { if (b[i] > 15) {...
#include <bits/stdc++.h> using namespace std; const long long INF = 0x1fffffffffffffff; const double INFD = 1e20; const double EPS = 1e-9; const double PI = atan(1) * 4; const long long M = 998244353; long long mod(long long x) { return ((x % M) + M) % M; } long long add(long long a, long long b) { retu...
#include <bits/stdc++.h> using namespace std; vector<long long> adj[200005]; long long siz = 0; long long cc = 0; long long t, n; long long a[200005]; long long vis[200005]; long long size_dict[200005]; void dfs(long long u) { vis[u] = cc; siz += 1; for (long long i = 0; i < adj[u].size();...
#include <bits/stdc++.h> using namespace std; int main() { int n, a, b, x1, y1, x2, y2, left, right; cin >> a >> b >> x1 >> y1 >> x2 >> y2; int r1 = (x2 - y2) / (2 * b); int r2 = (x1 - y1) / (2 * b); int r3 = (x2 + y2) / (2 * a); int r4 = (x1 + y1) / (2 * a); left = ((x2 - y2) / (2 * b) ...
#include <bits/stdc++.h> using namespace std; int n_keys, n_chests; int odd_keys, even_keys, odd_chests, even_chests; int main() { cin >> n_keys >> n_chests; for (int i = 0; i < n_keys; i++) { int x; cin >> x; if (x % 2 == 0) even_keys++; else odd_keys++; } ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; if (n % 2) { cout << contest n ; } else { cout << home n ; } }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; cin >> n; vector<int> v; for (int i = 0; i < n; i++) { int x; cin >> x; v.push_back(x); } sort(v.begin(), v.end()); if (v[0] == v[n /...
#include <bits/stdc++.h> int main() { int n, a[102], sum1 = 0, sum2 = 0; int s, t; scanf( %d , &n); for (int i = 0; i < n; i++) scanf( %d , &a[i]); scanf( %d %d , &s, &t); if (s == t) { printf( 0 n ); } else { int i; if (s > t) { s ^= t; t ^= s; s ...
#include <bits/stdc++.h> using namespace std; const int Maxn = 3e6 + 10, Maxk = 1e6 + 10; int a[Maxn], l[Maxn], r[Maxn], s[Maxn], n, k; vector<int> v[Maxk]; long long ans; int ask(int k, int l, int r) { int x = upper_bound(v[k].begin(), v[k].end(), r) - v[k].begin() - 1, y = lower_bound(v[k].beg...
#include <bits/stdc++.h> using namespace std; int main() { int T; scanf( %d , &T); while (T--) { int n, ans = 0; scanf( %d , &n); map<string, int> book; vector<string> aa, temp; for (int i = 1; i <= n; i++) { string s; cin >> s; book[s] = 1; ...
#include <bits/stdc++.h> using namespace std; int main() { int t = 1; while (t--) { long long l, r, i, sum = 0; deque<long long> a; a.push_back(4); a.push_back(7); cin >> l >> r; for (i = l; i <= r;) { if (i <= a.front()) { sum += a.front(); i+...
#include <bits/stdc++.h> const double PI = 3.1415926535897932384626433; const int KL = 1e6; using namespace std; const long long MOD = 998244353; int mul(int x, int y) { return x * 1LL * y % MOD; } int add(int x, int y) { x += y; if (x >= MOD) x -= MOD; return x; } int sub(int x, int y) { ...
#include <bits/stdc++.h> using namespace std; int typetest; inline void fastIOfileinput() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); typetest = 1; } const int N = 1e2 + 2; long long n; void Enter() { cin >> n; } long long cnt() { return (long long)((long long)sqrt((long...
#include <bits/stdc++.h> int main() { float a, b, x, y, v, g, k = 10000.000; int i, n; scanf( %f %f %d , &a, &b, &n); for (i = 0; i < n; i++) { scanf( %f %f %f , &x, &y, &v); g = (x - a) * (x - a) + (y - b) * (y - b); g = sqrt(g); g = g / v; if (g < k) { k = g; ...
#include <bits/stdc++.h> using namespace std; template <typename T> inline string toString(T a) { ostringstream os( ); os << a; return os.str(); } template <typename T> inline long long toLong(T a) { long long res; istringstream os(a); os >> res; return res; } template <type...
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize( Ofast ) #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma ) #pragma GCC optimize( unroll-loops ) const long long int mod = 1e9 + 7; const long long int mod1 = 998244353; const long long int inf = 1e18; const long ...
#include <bits/stdc++.h> using namespace std; void Solve() { int n; string a, b; cin >> n >> a >> b; a = - + a + - ; b = - + b + - ; int val = 0; for (int i = 1; i <= n; i++) { if (a[i] != b[i]) val += 2; else if (a[i] == 0 ) { val++; if (a[i - ...
#include <bits/stdc++.h> using namespace std; inline long long read() { long long x = 0; bool f = 1; char s = getchar(); while ((s < 0 || s > 9 ) && s > 0) { if (s == - ) f ^= 1; s = getchar(); } while (s >= 0 && s <= 9 ) x = (x << 1) + (x << 3) + s - 0 , s = getchar(); ...
#include <bits/stdc++.h> using namespace std; int Read() { char c; while (c = getchar(), (c != - ) && (c < 0 || c > 9 )) ; bool neg = (c == - ); int ret = (neg ? 0 : c - 48); while (c = getchar(), c >= 0 && c <= 9 ) ret = ret * 10 + c - 48; return neg ? -ret : ret; } const ...
#include <bits/stdc++.h> using namespace std; template <class T> struct rge { T b, e; }; template <class T> rge<T> range(T i, T j) { return rge<T>{i, j}; }; template <class A, class B> ostream &operator<<(ostream &os, pair<A, B> p) { return os << ( << p.first << , << p.second << ) ; ...
#include <bits/stdc++.h> using namespace std; std::vector<int> v[100005]; int dist[100005]; void dfs(int s, int par) { if (par != -1) dist[s] = dist[par] + 1; for (int i = 0; i < v[s].size(); i++) { if (par != v[s][i]) dfs(v[s][i], s); } } int main() { ios_base::sync_with_stdio(0); ...
#include <bits/stdc++.h> using namespace std; template <typename F, typename S> ostream &operator<<(ostream &os, const pair<F, S> &p) { return os << ( << p.first << , << p.second << ) ; } template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { os << { ; for (auto it =...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 5; int n, a[maxn], b[maxn], t[maxn]; bool check(int num, int pos) { t[pos] = num; if (pos == n) return true; for (int i = 0; i <= 3; i++) { if ((num | i) == a[pos] && (num & i) == b[pos]) return check(i, pos + 1); } r...
#include <bits/stdc++.h> using namespace std; const int N = 200000 + 10; const int M = 5 * N; const int OO = 1000000000; int ans = 0; int anum = 0; int i; int n; int result; int sum[N]; int tree[M]; string s; int lowbit(int x) { return x & (-x); } int min(int a, int b) { return a < b ? a : b...
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; const int MAX_N = 1e5 + 50; int w[MAX_N]; void solve() { int n, m; cin >> n >> m; long long ret = ((long long)w[n] + (long long)w[m] - 1LL) * 2LL; cout << ret % MOD << n ; } void precal() { w[0] = 0; w[1] = 1;...
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e6 + 2e5; int p[MAXN + 10], rub[MAXN + 10]; bool mark[MAXN + 10]; bool palin(int x) { stringstream sst; sst << x; string s; sst >> s; for (int i = 0; i < s.length(); i++) if (s[i] != s[s.length() - i - 1]) return false; ...
#include <bits/stdc++.h> using namespace std; const int SZ = 200005; vector<int> graph[SZ]; int par[SZ]; int dst[SZ]; int tot; void dfs(int x, int crt) { par[x] = crt; tot++; for (int nxt : graph[x]) { if (par[nxt]) continue; dfs(nxt, crt); } } int main(void) { ios_base...
#include <bits/stdc++.h> using namespace std; const int inf = 1e9 + 7; const int maxn = 1e6 + 100; const double EPS = 1e-12; struct point { double x, y; }; string a[11] = { zero , one , two , three , four , five , six , seven , eight , nine , ten }; string b[11] = {...
#include <bits/stdc++.h> using namespace std; int64_t read() { bool b = 0; int64_t n = 0; char c = getchar(); for (; !(( 0 ) <= (c) && (c) <= ( 9 )); c = getchar()) b = (c == - ); for (; (( 0 ) <= (c) && (c) <= ( 9 )); c = getchar()) n = 10 * n + (c - 0 ); if (b) n = -n; return n; } ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; char board[n][n]; bool even = true; for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) cin >> board[i][j]; for (int i = 0; i < n; i++) { int c = 0; for (int j = 0; j < n; j++) { if (i -...
#include <bits/stdc++.h> using namespace std; const long long int MAX = 1e7 + 7; const long long int MOD = 1000000007; void fast() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); } int main() { fast(); long long int TEST_CASES = 1; while (TEST_CASES--) { ...
#include <bits/stdc++.h> using namespace std; typedef struct { int freq; char l; } db; int comp(const void *a, const void *b) { db *x = (db *)a; db *y = (db *)b; return x->freq - y->freq; } int main() { db aa[30]; db e; string str; int let[30], sz, i, cnt, k, d, j; wh...
#include <bits/stdc++.h> char c[10005]; int main() { int i, j, k, n, m; int x0 = 0, x = 0, y0 = 0, y = 0; scanf( %d%s , &n, c + 1); for (i = 1; i <= n; i++) { if (!x0 && c[i] == R ) x0 = i; if (c[i] == R ) x = i; if (!y0 && c[i] == L ) y0 = i; if (c[i] == L ) y = i; }...
#include <bits/stdc++.h> using namespace std; int blk_size; struct node { int l, r, id; long long int ans = 0; }; bool compare(node a, node b) { if (a.l / blk_size != b.l / blk_size) return (a.l) / blk_size < (b.l) / blk_size; return a.r < b.r; } bool compare2(node a, node b) { retur...
#include <bits/stdc++.h> const long long MOD = 1000000007; int N, K; long long a[5002], FUL[5001]; long long inv[5001]; long long O; long long POWER(long long a, long long b) { long long r = 1; for (; b; b >>= 1) { if (b & 1) r = r * a % MOD; a = a * a % MOD; } return r; } in...
#include <bits/stdc++.h> using namespace std; using ld = long double; template <class T> inline T gcd(T a, T b) { return !a ? b : gcd(b % a, a); } template <class T> inline T lcm(T a, T b) { return (a * b) / gcd(a, b); } mt19937 rnd(time(0)); const int INF = 1e9; const long long LLINF = 1e...
#include <bits/stdc++.h> using namespace std; const long long int mod = 1e9 + 7; void __print(int x) { cerr << x; } void __print(long x) { cerr << x; } void __print(long long x) { cerr << x; } void __print(unsigned x) { cerr << x; } void __print(unsigned long x) { cerr << x; } void __print(unsigned long...
#include <bits/stdc++.h> using namespace std; long long int ans, sum, pro; string s, str; long long int solve(int st, int end, string z) { long long int sum2 = 0, pro2 = 1; for (int i = st; i <= end; i++) { if (z[i] == + ) { sum2 += pro2; pro2 = 1; } else if (i % 2 == 0) ...
#include <bits/stdc++.h> using namespace std; bool bad[105]; string A[105]; bool check(string a, string b) { if ((int)a.size() != (int)b.size()) return false; for (int i = 0; i < (int)a.size(); i++) if (tolower(a[i]) != tolower(b[i])) return false; return true; } int main() { int n, i,...
#include <bits/stdc++.h> using std ::vector; template <typename T> T max(T x, T y) { return (x > y) ? x : y; } template <typename T> T min(T x, T y) { return (x < y) ? x : y; } template <typename T> bool chkmax(T &x, T y) { return (x >= y) ? 0 : (x = y, 1); } template <typename T> bo...
#include <bits/stdc++.h> using namespace std; int ans, n, a[10005], cnt, f, i, j, vis[10005]; int main() { scanf( %d , &n); for (i = 0; i < n; i++) { scanf( %d , &a[i]); } ans = 0; f = 0; cnt = 0; memset(vis, 0, sizeof vis); for (i = 0; i < n; i++) { if (!f) { f...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a[n], ans = 0, maxi = 0; for (int i = 0; i < 7; i++) { cin >> a[i]; maxi += a[i]; } int t; if (maxi >= n) t = 1; else if (n % maxi == 0) { t = n / maxi; } else { t = n / ...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:100000000 ) using namespace std; int b[500][100005], c[500]; int main() { srand(time(0)); int n, m, i, j, k; scanf( %d %d , &n, &m); map<int, vector<int> > a; for (i = 0; i < n; i++) { scanf( %d , &k); if (k <= n) a[k].push...
#include <bits/stdc++.h> using namespace std; template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; } int num[26]; int main() { int T; scanf( %d , &T); while (T--) { int n; string s, t; cin >> n >> s >> t; int rev = 0, flg = 0; memset(num, 0, sizeof...
#include <bits/stdc++.h> using namespace std; long long dr[] = {-1, 1, 0, 0, -1, 1, -1, 1}; long long dc[] = {0, 0, -1, 1, -1, -1, 1, 1}; int main() { long long T; cin >> T; while (T--) { string a, b; cin >> a >> b; if (a < b) { cout << a << n ; continue; } ...
#include <bits/stdc++.h> using namespace std; inline long long LAKLSNCJKQ() { char c = getchar(); if (32281 > 23346) { long long SJQTNVYTHY; SJQTNVYTHY = 890; long long VLABDWDNOG; double QHJMZGOBOX; bool SJAZLHXFNS; } long long x = 0; double IBTBRLYCXT; IBTBRLY...
#include <bits/stdc++.h> using namespace std; pair<long long, long long> p1[1005]; pair<long long, long long> p2[1005]; vector<long long> v; int main() { long long i, j, n, x, y, a, b; cin >> n; for (i = 0; i < n; i++) cin >> p1[i].first >> p1[i].second; for (i = 0; i < n; i++) cin >> p2[i].fi...
#include <bits/stdc++.h> using namespace std; long long inf = 2147483647; const long long ll = 9223372036854775807, ninf = 1000000000; const double eps = 1e-6; const long long nll = 1000000000000000000; vector<int> node[200005]; vector<int> num; int deg[200005] = {}; void dfs(int x) { for (int i =...
#include <bits/stdc++.h> using namespace std; const int maxn = 1005; int fa[2][maxn << 1]; int cost[2][maxn][maxn]; int dd[2][maxn]; int n; int sz[2]; int dp[maxn]; void init(int t) { cin >> sz[t]; for (int i = (2); i <= (sz[t]); ++i) cin >> fa[t][i]; for (int i = (1); i <= (n); ++i) cin >...
#include <bits/stdc++.h> using namespace std; template <class T> inline T SQR(T x) { return x * x; } template <class T> inline string TOSTR(const T &x) { stringstream ss; ss << x; return ss.str(); } template <class T> void UPDATE_MIN(T &x, T y) { if (y < x) { x = y; } }...
#include <bits/stdc++.h> using namespace std; map<char, long long int> cou; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); ; long long int n; cin >> n; while (n--) { string s; cin >> s; cou[s[0]]++; } long long int ans = 0; for (ma...
#include <bits/stdc++.h> using namespace std; int mark[1 << 22]; int is[1 << 22]; int a[1 << 22]; int n, m; int tot; void dfs(int x) { if (mark[x]) return; mark[x] = 1; if (is[x]) dfs(tot ^ x); for (int j = 0; j < n; j++) { if (x >> j & 1) { dfs(x ^ (1 << j)); } } ...
#include <bits/stdc++.h> using namespace std; const long long N = 5e5 + 7; const long long INF = 1e17 + 7; long long h[N], t[N], f[N][2], pos[N], w[N]; long long n, num = 0; struct edge { long long v, next; } e[N * 2]; struct pir { long long a, b; } p[N]; bool cmp(pir x, pir y) { return (x.b...
#include <bits/stdc++.h> using namespace std; int main() { int i = 0; ios_base::sync_with_stdio(false); cin.tie(NULL); vector<int> ans; int n; int m; cin >> n >> m; int a[110]; int b[20]; memset(a, 0, sizeof a); memset(b, 0, sizeof b); for (int i = 0; i < n; i++) { ...
#include <bits/stdc++.h> using namespace std; string t(int a) { int i, tmp = 1; for (i = 1; i <= a; i *= 3) { } string s; for (; i >= 1; i /= 3) { if (a / i == 2) s += 2 , a %= i; else if (a / i == 1) s += 1 , a %= i; else s += 0 ; } return s;...
#include <bits/stdc++.h> using namespace std; long long n, m, vet[202020], cap[202020]; set<long long> s; int main() { scanf( %lld , &n); for (long long i = 1; i <= n; i++) scanf( %lld , &cap[i]), s.insert(i); scanf( %lld , &m); long long op, x, p, k; while (m--) { scanf( %lld , &op); ...
#include <bits/stdc++.h> using namespace std; const int maxn = 15, maxx = 10; long long a[maxn], b[maxn], c[maxn]; void Init() { for (int i = 1; i <= maxx; i++) { long long x = i, l = 1, r = 0; while (x--) l *= 10, r = r * 10 + 9; l /= 10; a[i] = (r - l + 1) * i; b[i] = b[i - 1...
#include <bits/stdc++.h> using namespace std; bool flag; int n, a[1010], vis[2010], T; pair<int, int> ans[5]; void read(int &x) { char ch = getchar(); int mark = 1; for (; ch != - && (ch < 0 || ch > 9 ); ch = getchar()) ; if (ch == - ) mark = -1, ch = getchar(); for (x = 0; ch ...
#include <bits/stdc++.h> using namespace std; bool test(long long k, long long x, long long n, long long m, long long p1, long long l1, long long r1, long long p2, long long l2, long long r2) { if (p1 * 2 + l1 + r1 > n) return false; if (p2 * 2 + l2 + r2 > m) return false; for (l...
#include <bits/stdc++.h> #pragma GCC optimize 2 using namespace std; const int N = 2e4 + 9; struct stree { int l, r, lazy, sum; } t[N << 2]; int dp[20005]; inline void pushdown(int now) { int lazy = t[now].lazy; if (!lazy) return; if (t[now].l != t[now].r) t[now * 2].lazy += lazy, t[...
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const double eps = 1e-6; template <class T> T gcd(T a, T b) { if (!b) return a; return gcd(b, a % b); } const int maxn = 1e6 + 10; int n, m; int phi[maxn]; int a[maxn]; int get(int x) { int res = x; for (long...
#include <bits/stdc++.h> using namespace std; long long M = 1000000007; long long bigMod(long long n, long long power, long long mod = M) { if (power == 0) return 1; if (power == 1) return n % mod; else if (power % 2 == 0) { long long v = bigMod(n, power / 2, mod); return ((v % mod) ...
#include <bits/stdc++.h> using namespace std; const int N = 3005; int n, a[N]; int main() { scanf( %d , &n); for (int i = 0; i < n; ++i) { scanf( %d , a + i); } int ans = 0; for (int i = 0; i < n; ++i) { for (int j = 0; j < i; ++j) { if (a[j] > a[i]) { ++ans; ...
#include <bits/stdc++.h> using namespace std; int n, K; int pover[64000]; int ipover[64000]; int dt[503][503]; int lsum[2][503][503]; const int mod = 1000000007; int main() { scanf( %d%d , &n, &K); int maxval = 0; pover[0] = 1; for (int i = 1; i < 64000; i++) { pover[i] = (pover[i ...
#include <bits/stdc++.h> using namespace std; int d[1005], s[1005], sufmax[1005], mxpos[1005], pred[1005]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, k; cin >> n >> k; ++n; for (int i = 1; i < n; ++i) cin >> d[i]; for (int i = 1; i < n; ++i) cin >> s[i]; for (int...
#include <bits/stdc++.h> using namespace std; const int N = 5e5 + 10, B = 1e6 + 3; int n, m, p1[N][2], p2[N][2], x, y; long long ans = 1; int main() { scanf( %d%d n , &n, &m); char a[n + 3][m + 3]; for (int i = 0; i < n; ++i) gets(a[i]); for (int i = 0; i < n; ++i) { for (int j = 0; j < ...
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize( O3 ) #pragma GCC target( avx,avx2,sse,sse2,sse3,sse4,popcnt,fma ) #pragma GCC optimize( unroll-loops ) const long long int MAXN = 2e5 + 5; const long long int mod = 1000000007; const long long int N = 200005; void solve() { map<pair...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n, c0, c1, h; cin >> n >> c0 >> c1 >> h; string s; cin >> s; int o = 0, z = 0; for (int i = 0; i < n; i++) { if (s[i] == 1 ) o++; else z+...
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) #pragma GCC optimize( O3 ) #pragma GCC optimize( O2 ) #pragma GCC optimize( inline ) #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native ) #pragma GCC optimize( unroll-loops ) using namespace std; const int INF = 1e9 + 7; i...
#include <bits/stdc++.h> using namespace std; const int maxn = 500010; int m, k, n, s, a[maxn], b[maxn], c[maxn], maxx, tong[maxn], ansl, ansr, vis[maxn]; bool check(int l, int r) { memcpy(c, tong, sizeof(c)); for (int i = l; i <= r; i++) c[a[i]]--; for (int i = 1; i <= maxx; i++) if (c[...
#include <bits/stdc++.h> using namespace std; const int N = 2005; bool can = 1; char arr[N][N]; int n, m, vis[N][N], dp[N][N]; bool valid(pair<int, int> a) { return min(a.first, a.second) > -1 && a.first < n && a.second < m && arr[a.first][a.second] != # ; } pair<int, int> get_next(pair<...
#include <bits/stdc++.h> using namespace std; const int inf = 1.01e9; const double eps = 1e-9; const int N = 1e5 + 10; int t[N]; int mem[N]; int main() { int n; scanf( %d , &n); for (int i = 0; (i) < (n); ++i) scanf( %d , &t[i]); int s = 0; for (int i = 0; (i) < (n); ++i) { int v...
#include <bits/stdc++.h> using namespace std; int main() { int x, y; scanf( %d %d , &x, &y); long long ans = 0; for (int val = 1; val <= x; ++val) { ans += (int)floor((y - (5 - (val % 5))) / 5.0) + 1; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const long double PI = 3.14159265359; const long long MOD = (long long)1e9 + 7; const long long MAXN = (long long)1e5 + 10; const long long INF = (long long)9223372036854775; const long double EPS = (long double)1e-8; long long par[MAXN], sz[MAXN], ln[MAXN], p...
#include <bits/stdc++.h> using namespace std; int main() { int n, l = 0; char a; cin >> n; for (int i = 0; i < n; i++) { cin >> a; if (a - 0 == 1) l++; else l--; } cout << abs(l); return 0; }
#include <bits/stdc++.h> using namespace std; long long offset[1000]; vector<pair<long long, int> > x[1000]; long long v[500005]; int bucketsize = 700; inline int bucket(int x) { return x / bucketsize; } int buckets, n; inline int bstart(int x) { if (x == buckets + 1) { return n + 1; } ...
#include <bits/stdc++.h> using namespace std; int main() { int T; cin >> T; while (T--) { int a, b, n; cin >> a >> b >> n; if (n % 3 == 0) cout << a << endl; else if (n % 3 == 1) cout << b << endl; else cout << (a ^ b) << endl; } }
#include <bits/stdc++.h> using namespace std; int n, m, a; int tab[105]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> m; for (int i = 1; i <= m; i++) { cin >> a; tab[a]--; } sort(tab + 1, tab + 1 + 100); {} for (int wynik = 1; wynik <= 101; wynik...
#include <bits/stdc++.h> namespace myland { using namespace std; namespace _abbr { const double EPS(1e-8); const double PI(acos(-1.0)); const int INF(0x3f3f3f3f); const long long INFL(0x3f3f3f3f3f3f3f3fll); const int MOD(1e9 + 7); } // namespace _abbr using namespace _abbr; namespace _solve {} ...
#include <bits/stdc++.h> using namespace std; int main() { int n = 0, a[100001]; long long sum = 0, x = 0, ans = 0; cin >> n; for (int i = 0; i < n; i++) cin >> a[i], sum += a[i]; sum = sum / n; for (int i = 0; i < n; i++) x += a[i] - sum, ans += abs(x); cout << ans; return 0; }
#include <bits/stdc++.h> using namespace std; int n; char a[440000], b[440000]; int cnta = 0, cntb = 0; int df[440000] = {0}; int czl[440000], czr[440000]; int zz1 = 0, zz2 = 0; int ab[440000] = {0}, ba[440000] = {0}; int ans = 0; int main() { cin >> n; cin >> a >> b; for (int i = 0; i <...
#include <bits/stdc++.h> using namespace std; const int N = 1010; int vis[N]; vector<int> a[N], tmp; int main() { int n; scanf( %d , &n); int x = 1; for (int i = 2; i <= n; i++) { if (n - (n + i - 1) / i - i + 1 > n - (n + x - 1) / x - x + 1) x = i; } int ans = n - (n + x - 1) / ...
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; bool a[m + 1]; memset(a, 0, sizeof(a)); for (int i = 1; i <= n; i++) { int l, r; cin >> l >> r; for (int j = l; j <= r; j++) a[j] = 1; } vector<int> v; int res = 0; for (int i = ...
#include <bits/stdc++.h> using namespace std; struct a1 { int value, freq; } arr[101]; bool compare(a1 lhs, a1 rhs) { return lhs.freq > rhs.freq; } int main() { int temp = 0, j, n, num = 0, m, i, a[101], ans = 0; scanf( %d %d , &n, &m); int b[n], c[n]; memset(a, 0, sizeof(a)); for (i =...
#include <bits/stdc++.h> using namespace std; template <class A> void pr(A a) { cout << a; cout << n ; } template <class A, class B> void pr(A a, B b) { cout << a << ; pr(b); } template <class A, class B, class C> void pr(A a, B b, C c) { cout << a << ; pr(b, c); } ...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; struct Node { int a, px, ori, c; } node[N]; int n, l, r; bool cmp_px(Node &a, Node &b) { return a.px < b.px; } bool cmp_ori(Node &a, Node &b) { return a.ori < b.ori; } int main() { cin >> n >> l >> r; int t; for (int i ...
#include <bits/stdc++.h> using namespace std; int main() { int sb, eb; vector<int> box; cin >> sb; for (int a = 0; a < sb; a++) { cin >> eb; box.push_back(eb); } sort(box.begin(), box.end()); for (int a = 0; a < sb; a++) { cout << box[a] << ; } }