func_code_string
stringlengths
59
71.4k
#include <bits/stdc++.h> using namespace std; int fun(string s, int i) { int k = 0; while (s[i] == 0 & i >= 0) { k++; i--; } return k; } int main(int argc, char const *argv[]) { string s; int a, k = 0, count = 1; cin >> a; cin >> s; string ans = ; int i = ...
#include <bits/stdc++.h> using namespace std; const int MAX_N = 55; int n, m, dp[MAX_N][MAX_N][MAX_N][MAX_N]; char a[MAX_N][MAX_N]; int dfs(int x1, int y1, int x2, int y2) { if (dp[x1][y1][x2][y2] >= 0) { return dp[x1][y1][x2][y2]; } if (x1 == x2 && y1 == y2) { return dp[x1][y1][x2][y2...
#include <bits/stdc++.h> using namespace std; const long long int delta = 1e9 + 5; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ; int x; int d; cin >> x >> d; vector<long long int> ans; long long int cur = 1; for (int i = 31; i >= 0; i--) { long long int ...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); string str; cin >> str; int n = str.length(); map<char, int> mp; for (int i = 0; i < n; i++) { mp[str[i]]++; } if (mp.size() % 2 == 1) cout << IGNORE HIM!...
#include <bits/stdc++.h> using namespace std; const long long MOD = 998244353LL, INV2 = (MOD + 1) / 2; const int MAXN = 500; long long DP[MAXN + 1][MAXN + 1]; int main() { ios::sync_with_stdio(0); cin.tie(0); int N, K; cin >> N >> K; for (int k = 1; k <= min(N, K); ++k) { DP[k][0] = ...
#include <bits/stdc++.h> using namespace std; long long cubes[100001], x; long long my_pow(long long x) { return x * x * x; } pair<long long, long long> best; void rec(long long m, long long steps, long long subtracted) { if (m == 0) { best = max(best, make_pair(steps, subtracted)); return; ...
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) using namespace std; const long long infl = 0x3f3f3f3f3f3f3f3fLL; const long long infi = 0x3f3f3f3f; mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count()); const long long mod = 1e9 + 7; const long long N = 1e6 + 5; void solve() { ...
#include <bits/stdc++.h> using namespace std; int ABS(int a) { if (a < 0) return (-a); return a; } void input() {} int n, table; int a[55]; double dp[55][55][55][55]; int aim; double f(int idx, int sum, int k, int cnt) { if (idx == n) { if (sum != aim || cnt == 0) return 0; ret...
#include <bits/stdc++.h> using namespace std; const int MAXN = 100010; const int MAXK = 20; int times[MAXN]; int dp[MAXN][MAXK]; int subtree[MAXN]; int marc[MAXN]; int prof[MAXN]; vector<int> graph[MAXN]; vector<pair<int, int>> arcs; void init_dfs(int u) { marc[u] = 1; for (int v : graph[u...
#include <bits/stdc++.h> using namespace std; vector<pair<double, double>> v[4]; double x[3], y[3], r[3]; void add_point(int p, double x, double y) { for (int t = 0; t < v[p].size(); t++) if (fabs(x - v[p][t].first) < 1e-7 && fabs(y - v[p][t].second) < 1e-7) return; v[p].push_back(make_pai...
#include <bits/stdc++.h> using namespace std; const long long Mod = 1000000007; long long fp(long long a, long long k) { long long res = 1; while (k) { if (k & 1) res = res * a % Mod; a = a * a % Mod; k >>= 1; } return res; } int main() { long long n, m; scanf( %I64d%...
#include <bits/stdc++.h> using namespace std; const long long inf = 1e9 + 7; void solve() { long long n, m; cin >> n >> m; if (m == 1) { long long a = n * (n - 1) / 2; cout << a << << a << endl; } else { long long aux = n - (m - 1); long long maxi = aux * (aux - 1) / 2;...
#include <bits/stdc++.h> using namespace std; const int N = 25; long long n, ans[N]; pair<int, int> arr[N]; int main() { ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); cin >> n; for (int i = 0; i < n; i++) cin >> arr[i].first, arr[i].second = i; sort(arr, arr + n); for (int i = 0; i < n...
#include <bits/stdc++.h> using namespace std; long long int gcd(long long int a, long long int b) { return b == 0 ? a : gcd(b, a % b); } inline long long int lbt(long long int x) { return x & -x; } inline void fail() { cout << -1 << endl; exit(0); } int main() { long long int a, b, c, d,...
#include <bits/stdc++.h> using namespace std; long long n, l, r; long long gerar(long long n) { if (n == 0) { return 0; } return 2 * gerar(n / 2) + 1; } long long solve(long long esq, long long dir, long long l, long long r, long long valor) { long long mid = (esq + dir...
#include <bits/stdc++.h> using namespace std; long long add(long long a, long long b) { a += b; if (a >= 998244353) { a -= 998244353; } return a; } long long sub(long long a, long long b) { a -= b; if (a < 0) { a += 998244353; } return a; } long long mul(long long...
#include <bits/stdc++.h> using namespace std; int num[500005]; int maps[500005]; int to[500005]; int main() { ios::sync_with_stdio(0); int n, m; int l, r; scanf( %d%d , &n, &m); for (int i = 1; i <= n; i++) { scanf( %d , &num[i]); to[num[i]] = i; } for (int i = 1; i <= ...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { long long n, k; cin >> n >> k; long long i = 1, cnt = 0; while (i < k && i < n) { cnt++; i = i * 2; } if (i < n) { cnt += (n - i) / k; if ((n - i)...
#include <bits/stdc++.h> using namespace std; using UL = unsigned int; using ULL = unsigned long long; using LL = long long; int N; int CB[300000]; int CN[300000]; int Bbuf = 0, Nbuf = 0; int F(int cn, int cb) { int ans = 0; for (int i = 0; i < (N); i++) { ans = max(ans, abs(cn - CN[i]))...
#include <bits/stdc++.h> using namespace std; set<int> S; int n, a[500005], b[500005], q[500005], r; int main() { scanf( %d , &n); n *= 2; int tot = 0; for (int i = 1; i <= n; i++) { char c = getchar(); while (c != + && c != - ) c = getchar(); if (c == + ) q[++r] = ...
#include <bits/stdc++.h> using namespace std; int main() { int t; scanf( %d , &t); while (t--) { int n; scanf( %d , &n); int a[n], b[n]; for (int i = 0; i < n; i++) scanf( %d%d , &a[i], &b[i]); if (a[0] < b[0]) printf( NO n ); else { int f = 1; ...
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1.0); const int inf = (int)1e9; struct vert { int to, z, num; }; struct ans { int x, y, z; }; const int N = (int)(1e5) + 5; int n, m; vector<vert> g[N]; vector<int> d(N, inf); vector<int> dp(N, inf); vector<int> pr(N...
#include <bits/stdc++.h> using namespace std; int mod = (int)1e9 + 7; struct matrix { int A[2][2] = {0}; matrix operator*(matrix B) { matrix C; for (int i = 0; i < 2; i++) for (int j = 0; j < 2; j++) for (int k = 0; k < 2; k++) C[i][j] = (C[i][j] + 1ll * A[i][k] *...
#include <bits/stdc++.h> using namespace std; int a[110], b[110]; int main() { int n; cin >> n; for (int i = 1; i <= n; ++i) cin >> a[i]; sort(a + 1, a + 1 + n); int aa = a[n]; cin >> n; for (int i = 1; i <= n; ++i) cin >> b[i]; sort(b + 1, b + 1 + n); int bb = b[n]; cout <...
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const long long LINF = 0x3f3f3f3f3f3f3f3f; int v[1010]; bool compare(pair<int, int> a, pair<int, int> b) { if (a.second != b.second) return a.second > b.second; if (v[a.first] != v[b.first]) return v[a.first] < v[b.first]; r...
#include <bits/stdc++.h> using namespace std; void fast() { ios_base::sync_with_stdio(0); cin.tie(NULL), cout.tie(NULL); } int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); } int lcm(int a, int b) { return a * (b / gcd(a, b)); } char maze[1001][1001]; int main() { fast(); int num,...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); const int maxN = 2 * 1e5; int answers[maxN]; int n, m, x, neg = 0, pos = 0; cin >> n >> m; for (int i = 0; i < n; i++) { cin >> x; if (x == -1) neg++; else po...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 * 4; inline int get() { int x; cin >> x; return x; } inline long long getlong() { long long x; cin >> x; return x; } inline string getString() { string s; cin >> s; return s; } template <typename T> ...
#include <bits/stdc++.h> using namespace std; void split(string &s, vector<string> &v, string &sep) { int current, previous = 0; current = s.find_first_of(sep); while (current != string::npos) { v.push_back(s.substr(previous, current - previous)); previous = current + 1; current = s.fi...
#include <bits/stdc++.h> using namespace std; int has[205][205]; int vis[205][205]; vector<pair<int, int> > q; int gcd(int x, int y) { if (x < y) swap(x, y); while (y) { int t = x % y; x = y; y = t; } return x; } int main() { int n; scanf( %d , &n); for (int i...
#include <bits/stdc++.h> using namespace std; int main() { long long N; scanf( %I64d , &N); int l = 1, r = 20000000, ans = 0; while (l <= r) { int mid = (l + r) >> 1; if ((long long)mid * (mid + 1) < N * 2) ans = mid, l = mid + 1; else r = mid - 1; } printf(...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:96777216 ) using namespace std; const double NOT_FOUND = -1000000000; const double EPS = 0.00000001; const double PI = acos(-1.0); struct point { double x, y; }; point make_point(double a, double b) { point c; c.x = a; c.y = b; ...
#include <bits/stdc++.h> using namespace std; int prim[10] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29}; int n; long long ans; void DFS(int a, int b, long long temp) { if (temp < ans && a == n) ans = temp; if (a >= n) return; for (int i = 1; i <= 64; i++) { if (ans / prim[b] < temp) break; t...
#include <bits/stdc++.h> using namespace std; int ABS(int a) { if (a < 0) return (-a); return a; } void input() {} int a[100005]; int seg[100005]; int nxt[100005]; int hop[100005]; void readInt(int &n) { n = 0; char ch = getchar(); while (!isdigit(ch)) ch = getchar(); while (is...
#include <bits/stdc++.h> using namespace std; const int mx = 200100; struct node { int x, y, z; } a[mx]; struct nod { int id, x; } b[mx]; int fa[mx]; long long num[mx]; long long ans[mx]; int n, m; bool cmp(node x, node y) { return x.z < y.z; } bool cmp1(nod x, nod y) { return x.x < y.x;...
#include <bits/stdc++.h> using namespace std; long long int a[100005], ans[100005]; int main() { long long int n, i, j; cin >> n; for (i = 0; i < n; i++) { cin >> j; a[j] += 1 * j; } ans[1] = a[1]; ans[2] = a[2]; ans[3] = a[1] + a[3]; for (i = 4; i < 100005; i++) { ...
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { int T; cin >> T; while (T--) { int n; cin >> n; long double theta = 3.14159265358979323846 / (2 * n); long double answer = 1 / tan(theta); cout << setprecision(15) << answer << n ; } ...
#include <bits/stdc++.h> const int M = 1 << 20, L = 100020; char s[L]; int n, m, g[M], f[M], i, j, k, x, y, D; void init() { scanf( %d%d%s , &n, &m, s + 1); D = (1 << m) - 1; for (i = 1; i < n; i++) { x = s[i] - 97; y = s[i + 1] - 97; if (x != y) g[1 << x | 1 << y]++; } for...
#include <bits/stdc++.h> using namespace std; signed main() { ios_base::sync_with_stdio(false); cin.tie(); cout.tie(); long long t; cin >> t; while (t--) { long long n; cin >> n; string a; cin >> a; string last = a; for (long long i = 0; i <= n; ++i) { ...
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; int n = s.length(); vector<int> P(n, 0); int C = 0; int R = 0; for (int i = 1; i < n - 1; i++) { int mirror = 2 * C - i; if (R > i) { P[i] = min(R - i, P[mirror]); } else { P[...
#include <bits/stdc++.h> using namespace std; bool ck(int x) { int t[50], l = 0; while (x) t[l++] = x & 1, x >>= 1; if (l & 1) { int lim = l - 1 >> 1; for (int i = 0; i < lim; i++) if (t[i]) return 0; for (int i = lim; i < l; i++) if (!t[i]) return 0; } else r...
#include <bits/stdc++.h> const int N = 2010; std::set<std::pair<long long, int>> set; long long a[N][N], dis[N]; bool vis[N]; int n; int main() { scanf( %d , &n); memset(dis, 0x7f, sizeof(dis)); long long mine = LLONG_MAX; for (int i = 0; i < n; ++i) { for (int j = i + 1; j < n; ++j) {...
#include <bits/stdc++.h> #pragma GCC optimize( O3 ) #pragma GCC target( avx2 ) using namespace std; void solve() { int q; cin >> q; unordered_map<string, string> map; while (q--) { string a, b; cin >> a >> b; if (map.find(a) != map.end()) { string s = map[a]; ma...
#include <bits/stdc++.h> using namespace std; template <class Key, class Value> struct Heap { Value p[100100]; int pos[100100]; vector<Key> hp; void init() { hp.clear(); } void swapPos(int i, int a) { int temp; temp = pos[hp[a]]; pos[hp[a]] = pos[hp[i]]; pos[hp[i]] = te...
#include <bits/stdc++.h> using namespace std; const int inf = INT_MAX; const int mod = 1e9 + 7; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t; cin >> t; while (t--) { int n; cin >> n; int arr[2][n]; int sum[2][n]; for (int i = 0; i < 2; i++...
#include <bits/stdc++.h> #pragma comment(linker, /STACK:167772160 ) using namespace std; int main() { int n; cin >> n; pair<int, int> x[1111]; for (int i = 0; i < n; ++i) cin >> x[i].first >> x[i].second; long long p = 0, maxx = -1; int j = 0; for (int i = 0; i < x[n - 1].first; i++) ...
#include <bits/stdc++.h> using namespace std; long long int n, k, a, b; vector<long long int> arr; long long int rec(long long int l, long long int r) { long long int i = lower_bound(arr.begin(), arr.end(), l) - arr.begin(); long long int j = upper_bound(arr.begin(), arr.end(), r) - arr.begin(); lon...
#include <bits/stdc++.h> using namespace std; char s[10]; int main() { scanf( %s , s); int res = 1; for (int i = 1; i < 7; i++) { if (s[i] == 1 ) res += 10, i++; else res += s[i] - 0 ; } printf( %d n , res); }
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 10; char s[N]; int main() { vector<int> v1, v2; scanf( %s , s); int len = strlen(s); for (int i = 0; i < len; i++) { if (s[i] == l ) { v1.push_back(i + 1); } else v2.push_back(i + 1); } for (in...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 100; int n, p[4], bx[N], wx, by[N], wy, sum[N][4]; vector<int> wh[N]; struct node { int x, y, c; } sh[N]; bool cmp(node a, node b) { return a.x < b.x; } inline int read() { int f = 1, x = 0; char s = getchar(); while (s < ...
#include <bits/stdc++.h> static const int MAXN = 50004; static const int MAXE = 100004 * 2; static const int MAXL = 20; static const int MAXT = 1000005; int n, e; int head[MAXN], dest[MAXE], next[MAXE]; int l[MAXN], t[MAXN][MAXL]; int T = 0; int p[MAXN]; int conf[MAXN], team[MAXN]; int team_conf[M...
#include <bits/stdc++.h> using namespace std; int n, m; int ans = 654; vector<int> a, b, us(10); int main() { cin >> n >> m; a.resize(n); b.resize(m); for (int i = 0; i < n; ++i) { cin >> a[i]; us[a[i]] = 1; } for (int j = 0; j < m; ++j) { cin >> b[j]; if (us[b[...
#include <bits/stdc++.h> using namespace std; inline void read(int &x) { x = 0; char c = getchar(); int f = 1; while (!isdigit(c)) { if (c == - ) f = -1; c = getchar(); } while (isdigit(c)) { x = x * 10 + c - 0 ; c = getchar(); } x *= f; } const int N = ...
#include <bits/stdc++.h> using namespace std; const int MOD = 1000000007; int dp[1001][2010]; int digit[1002], k; void init() { memset(dp, -1, sizeof dp); } int dfs(int pos, int dist, bool doing) { if (pos == -1) return dist == 0; if (!doing && dp[pos][dist] != -1) return dp[pos][dist]; int ans ...
#include <bits/stdc++.h> using namespace std; vector<string> vec_splitter(string s) { s += , ; vector<string> res; while (!s.empty()) { res.push_back(s.substr(0, s.find( , ))); s = s.substr(s.find( , ) + 1); } return res; } void debug_out(vector<string> __attribute__((unused)) a...
#include <bits/stdc++.h> using namespace std; void Genawy() { std::ios_base::sync_with_stdio(0); cin.tie(NULL); } int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); } int n, cost[305]; int length[305]; map<pair<int, int>, int> dp; int solve(int ind, int gc) { if (ind == n) return gc ...
#include <bits/stdc++.h> int compare(const void *a, const void *b) { long long la = *(long long *)a; long long lb = *(long long *)b; return la == lb ? 0 : la < lb ? -1 : 1; } long long aa[8], aa_[8]; int bb[8], dp[8][1 << (8 - 1)]; char pp[8]; int n, ans = 0x3f3f3f3f; void solve(int i) { i...
#include <bits/stdc++.h> using namespace std; vector<string> v; int main() { string x, y; int cnt = 0; char temp; int n; cin >> n; n = n + n - 1; for (int i = 0; i < n; i++) { cin >> x; if (x == ** ) continue; cin >> y; x += y; sort(v.begin(), v.end()); ...
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; const int inf = 1 << 30; int n, qn, tot = 0, head[N], col[N], nowHead[N], deg[N], seq[N]; int dfsc = 0, id[N], siz[N], fa[N], son[N], dep[N], top[N]; bool vis[N]; struct Edge { int to, nxt; } e[N << 1]; inline void add(int from, ...
#include <bits/stdc++.h> using namespace std; const int inf = (int)1e9 + 7; int up(int n) { int r = 1; while (r < n) r <<= 1; return r; } class segtree { vector<int> arr; vector<bool> laz; void inv(int l, int r, int cl, int cr, int v) { if (r <= cl || cr <= l) return; push(...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string s; cin >> s; int p1 = 0, q1 = 0, r1 = 0, s1 = 0; int ans = 1; int a = 0, b = 0, c = 0, d = 0; vector<int> v; int sum = 0; for (int j = 0; j < s.length(); j++) { if (s[j] == R ) { ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t; cin >> t; while (t--) { int n; cin >> n; long long int a[n], sum = 0, fg = 0, cnt = 0, ind = 1, ans = 0; for (int i = 0; i < n; i++) cin >> a[i]; for (...
#include <bits/stdc++.h> using namespace std; long long s1[2100][2100], sum[2100][2100], cnt[2100][2100], cnt1[2100][2100]; int main() { int n, m, i, j; long long res; scanf( %d%d , &n, &m); for (i = 2; i <= m; i++) { for (j = 1; j <= n; j++) { cnt[i][j] = sum[i][j - 1] + 1; ...
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; s = * + s; int add = 0; int n = (s.length()) - 1; for (int i = 1; i + i <= n; i++) { if (s[i] != s[s.size() - i]) { add++; } } if (add <= 1 && (n & 1) || add == 1) cout << YES ...
#include <bits/stdc++.h> using namespace std; int main() { int n, a, i, j, arr[300] = {0}, p = 0, k = 0, c, d; cin >> n >> a; for (i = 1; i < n + 1; i++) { cin >> arr[i]; } arr[0] = 1, arr[n + 1] = 1; j = min(a, n - a + 1); for (i = j; i < n + 1; i++) { c = a + k; d = a...
#include <bits/stdc++.h> using namespace std; struct node { int x, y; } arr[104]; vector<int> graph[105]; int visited[105] = {0}; void dfs(int i) { visited[i] = 1; int j = 0; while (j < graph[i].size()) { if (visited[graph[i][j]] == 0) { dfs(graph[i][j]); } j++; ...
#include <bits/stdc++.h> using namespace std; const int MAXT = (1 << 18) + 5; int icT[MAXT], dcT[MAXT]; const int MAXN = 100010; int a[MAXN], idxofa[MAXN], b[MAXN]; int n; priority_queue<pair<int, int> > dc, ic; int main() { scanf( %d , &n); for (int i = 1; i <= (int)(n); i++) { scanf( %d ...
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 10; const long long inf = 0x3f3f3f3f3f3f3f3f; int n, k, b, c; int a[N], A[N], cost[N]; long long ans = inf; void solve(int x) { for (int i = 1; i <= n; ++i) { A[i] = a[i]; cost[i] = 0; while (A[i] % 5 != x) ++A[i], cos...
#include <bits/stdc++.h> const int N = 1e5 + 5; const int OO = 1e9 + 7; using namespace std; long long n, m, dishes[N], cost[N]; priority_queue<pair<long long, long long>, vector<pair<long long, long long>>, greater<pair<long long, long long>>> q; int main() { ios_base::sync_with_...
#include <bits/stdc++.h> using namespace std; void myswap(int& a, int& b) { int temp; temp = a; a = b; b = temp; } void fun(vector<int>& vec, int k, int l, int r) { if (k <= 1 || l >= r - 1) { return; } int mid = (l + r) / 2; if (k == 3) { myswap(vec[mid - 1], vec[mid...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n, k; cin >> n >> k; string s; cin >> s; int freq[26] = {0}; vector<int> v; for (int i = 0; i < s.length(); ++i) { freq[s[i] - a ]++; } for (int i ...
#include <bits/stdc++.h> int t; long long n, k, d1, d2, td1, td2, x1, x2, x3; bool solve() { if (n % 3) return false; for (int i = -1; i <= 1; ++i) for (int j = -1; j <= 1; ++j) { if (i == 0 || j == 0) continue; d1 = i * td1; d2 = j * td2; if ((d1 * 2 + d2 + k) % 3 ||...
#include <bits/stdc++.h> int n; char str[50]; int F[50], sz[50]; inline int find(int x) { return x == F[x] ? x : F[x] = find(F[x]); } inline void merge(int x, int y) { x = find(x); y = find(y); if (x == y) return; F[y] = x; sz[x] += sz[y]; } std::vector<int> G[55]; int id[66]; int ...
#include <bits/stdc++.h> int main() { int n; while (scanf( %d , &n) != EOF) { if (n % 2 == 1) { printf( -1 n ); continue; } printf( 2 1 ); for (int i = 3; i < n; i = i + 2) printf( %d %d , i + 1, i); printf( n ); } return 0; }
#include <bits/stdc++.h> using namespace std; map<int, int> Map; pair<int, int> a[250001]; vector<int> b[250001], t[250001]; char type; long long ans; int len[250001], n, m, i, q, l, r, d, mid, nom, nomN, zn, sum; bool pole[250001]; int get(int tl, int tr, int nom, int l, int r, int nomT) { if (tl...
#include <bits/stdc++.h> using namespace std; const long long int nax = 1e5 + 5; void solve() { long long int n; cin >> n; vector<long long int> a(n); for (auto &x : a) cin >> x; long long int sum = 0, mx = 0; for (long long int i = 0; i < n - 1; i++) { sum += max((long long int)0, a...
#include <bits/stdc++.h> using namespace std; inline int read() { int n = 0, f = 1, ch = getchar(); while (ch < 0 || ch > 9 ) { if (ch == - ) f = -1; ch = getchar(); } while (ch >= 0 && ch <= 9 ) { n = n * 10 + ch - 0 ; ch = getchar(); } return n * f; } ch...
#include <bits/stdc++.h> using namespace std; long double sq(long double a) { return a * a; } long double dist(pair<long double, long double> a, pair<long double, long double> b) { return sqrt((long double)(sq(a.second - b.second) + sq(a.first - b.first))); } long double mandist(pair<lo...
#include <bits/stdc++.h> using namespace std; int a[2005], b[2005]; int main() { int n, i, j, x, y, k; long long s; cin >> n; for (i = 0; i < n; i++) { cin >> x >> y; a[x + y]++; b[1001 + x - y]++; } s = 0; for (i = 0; i < 2003; i++) { k = a[i]; s += (k - ...
#include <bits/stdc++.h> using namespace std; void solve(); signed main() { ios::sync_with_stdio(false); cin.tie(0); cout << fixed; cout.precision(12); solve(); return 0; } template <typename T> void prv(vector<T> v) { for (int __ii = 0; __ii < ((int)v.size()); __ii++) { if...
#include <bits/stdc++.h> using namespace std; int main() { cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0); string s; cin >> s; string v = aeiou ; string c = bcdfghjklmnpqrstvwxyz ; map<char, int> cnt; map<char, int> mp; for (auto i : v) mp[i] = 1; for (auto i : c...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 5; string s[10005]; int vis[10005]; int main() { ios::sync_with_stdio(0); int n, sum(0); cin >> n; for (long long i = 0; i < n; ++i) cin >> s[i], sum += s[i].size(); char c; cin >> c; for (long long i = 0; i < n; ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; ++i) cin >> a[i]; map<int, int> used; int ans = 0; for (int i = n - 1; i >= 0; --i) { if (used[a[i]] == 0) { used[a[i]] = i; ans = a[i]; } ...
#include <bits/stdc++.h> using namespace std; const long double E = 1e-7; const int MOD = 1e9 + 7; const long long MAX = 1e6 + 1; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; int n, k; cin >> n >> k; int ar[n]; for (int i = 0; i < n; i++) cin >> ar[i]; ...
#include <bits/stdc++.h> using namespace std; int gcd(int x, int y) { if (x > y) return gcd(x - y, y); else if (x == y) return x; else return gcd(x, y - x); } int main() { int n, m, z; cin >> n >> m >> z; cout << (gcd(n, m) * z) / (n * m) << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, cnt, flag = 0; cin >> n; int a, b, c = 0; for (int i = 1; i <= n; i++) { cin >> a >> b; if (b - a >= 2) ++c; } cout << c << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int n, p = 0, ans = 0; string s, dvg, answ, r_dvg; cin >> n >> s; for (int i = 0; i < n - 1; i++) { dvg = s.substr(i, 2); for (int j = i; j < n - 1; j++) { r_dvg = s.substr(j, 2); if (dvg == r_dvg) { p++...
#include <bits/stdc++.h> using namespace std; struct Point { long long x, y; void read() { scanf( %lld%lld , &x, &y); } }; long long product(const Point &o, const Point &a, const Point &b) { return (a.x - o.x) * (b.y - o.y) - (b.x - o.x) * (a.y - o.y); } bool intersect(const Point &a, const Poin...
#include <bits/stdc++.h> using namespace std; const long long maxn = 305000; long long mod = 1e9 + 7; long long h, w, n; long long dp[maxn], f[maxn], inv[maxn]; struct stu { long long x, y; } a[maxn]; long long cmp(stu a, stu b) { if (a.x != b.x) return a.x < b.x; else return a.y...
#include <bits/stdc++.h> using namespace std; int v[3005], inv = 0, n; double sol; int main() { cin >> n; for (int i = 1; i <= n; i++) cin >> v[i]; for (int i = 1; i <= n; i++) for (int j = i + 1; j <= n; j++) if (v[i] > v[j]) inv++; sol = double(inv) - inv / 2 + (inv / 2) * 3.0; ...
#include <bits/stdc++.h> using namespace std; const int INF = 1000 * 1000 * 1000; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; cin >> n; pair<int, int> minp1(INF, INF), minp2(INF, INF); for (int i = 0; i < n; i++) { int x, y; cin >> x >> y;...
#include <bits/stdc++.h> using namespace std; int main() { int n; scanf( %d , &n); printf( %d n , (n & 1) ? (n - 1) + (n - 1) * ((n - 3) / 2) / 2 : (n - 2) * (n - 2) / 4 + (n - 2)); if (n & 1) { for (int i = 2; i <= n; i += 2) { printf( %d %d %d %d n , 3, 1, ...
#include <bits/stdc++.h> const int MAXN = 100100; struct Gao { int p[MAXN], q[MAXN]; bool r[MAXN]; void init(int n) { for (int i = 0; i < n; ++i) { q[i] = 1; r[i] = true; } } void next(int i) { if (!r[p[i]] && p[i] != i) { next(p[i]); q[i] += q[p...
#include <bits/stdc++.h> using namespace std; const int N = 4e4 + 5; int pr[N], ps = 0; bool np[N]; bool check(int n) { if (n == 1 || n == 0) return false; for (int i = 0; pr[i] * pr[i] <= n; ++i) if (n % pr[i] == 0) return false; return true; } int main() { for (int i = 2; i < N; ++...
#include <bits/stdc++.h> using namespace std; const long long mk = 100005; long long n; vector<long long> g[mk]; long long find(long long A) { if (A == 0) return 0; long long tmp = A & 3; long long R = (find(A / 4) << 2); if (tmp == 0) return R; if (tmp == 1) return (R | 2); if (tmp ==...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e4 + 5; pair<int, int> p[maxn]; set<pair<int, int> > s; void solve(int l, int r) { if (r - l < 2) return; int mid = (l + r) / 2; solve(l, mid), solve(mid, r); for (int i = l; i < r; i++) s.insert(make_pair(p[mid].first, p[i].secon...
#include <bits/stdc++.h> int main() { int n; long long int s; scanf( %d , &n); s = 6 * n * (n - 1) + 1; printf( %I64d , s); return 0; }
#include <bits/stdc++.h> template <class C, class E> inline bool contains(const C& container, const E& element) { return container.find(element) != container.end(); } template <class T> inline void checkmin(T& a, T b) { if (b < a) a = b; } template <class T> inline void checkmax(T& a, T b) { ...
#include <bits/stdc++.h> using namespace std; template <typename T> T sqr(T x) { return x * x; } template <typename T> T abs(T x) { return x < 0 ? -x : x; } template <typename T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; } template <typename T> bool chmin(T& x, const T& y) { ...
#include <bits/stdc++.h> using namespace std; int main() { double n, m, a, b; cin >> n >> m >> a >> b; double s = n / m; long long int s1 = floor(s) * m; long long int s2 = ceil(s) * m; long long int a1 = (n - s1) * b; long long int a2 = (s2 - n) * a; cout << (min(a1, a2)); }