solution
stringlengths
53
181k
difficulty
int64
0
13
#include <bits/stdc++.h> using namespace std; int main() { int a, b, sum = 0; cin >> a >> b; int c = (a < b) ? a : b; sum += c; cout << sum << " "; sum = 0; a -= c, b -= c; c = (a > b) ? a / 2 : b / 2; sum += c; cout << sum << endl; }
0
#include <bits/stdc++.h> using namespace std; const int INF = (int)1e9; const long long INF64 = (long long)1e18; const long double eps = 1e-9; const long double pi = 3.14159265358979323846; long long gcd(long long a, long long b) { if (a == 0) return b; return gcd(b % a, a); } long long lcm(long long a, long long b...
3
#include <bits/stdc++.h> using namespace std; int a[100005]; int d[100005]; int b[100005]; int e[100005]; int chk[100005]; vector<pair<int, int> > v; int main() { int n, m; cin >> n >> m; int i; for (i = 1; i <= n; i++) { cin >> d[i]; } for (i = 1; i <= m; i++) { cin >> a[i]; } a[0] = 0; int n...
4
#include <bits/stdc++.h> int main() { long long int n, i, k, a; scanf("%lld", &n); k = n; for (i = 0; i < 10; i++) { a = k % 10; k = k / 10; if (k == 0 && a == 1) { printf("YES\n"); break; } else if (k == 0 && a != 1) { printf("NO\n"); break; } if (a == 1) { ...
0
#include <bits/stdc++.h> using namespace std; int solve(vector<int> v) { vector<int> s; int res = v[0] ^ v[1], n = v.size(); for (int i = 0; i < n; i++) { while (!s.empty() && s.back() < v[i]) s.pop_back(); s.push_back(v[i]); if (s.size() >= 2) res = max(res, s[s.size() - 1] ^ s[s.size() - 2]); } ...
5
#include <bits/stdc++.h> using namespace std; int s0, s1, mn, z; char a[5009]; char b[5009]; int main() { scanf("%s", a); scanf("%s", b); s0 = strlen(a); s1 = strlen(b); mn = s1; for (int i = 0 - s1; i < s0; i++) { z = 0; for (int j = 0; j < s1; j++) { if (j < 0 || a[i + j] != b[j] || j + i >=...
4
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c; int k, q, f = 0; double p; scanf("%d", &a), scanf("%d", &b); if (b + a > 0) { c = b + a; q = c / (2 * (b)); if (q >= 1) { f = 1; p = (double)c / (double)(2 * q); } } if (b - a <= 0) { c = a - b; q =...
4
#include <bits/stdc++.h> using namespace std; const long long N = 1e7 + 7; const int bigN = 1e9 + 5; int mod = 1e9 + 7; int arr[N], temp[N], arr2[N]; int arr1[N]; int matrix1[100][100], matrix2[100][100], matrix3[100][100]; bool boolArr[N]; void init() { cin.tie(0); cin.sync_with_stdio(0); } long long gcd(long long...
2
#include <bits/stdc++.h> using namespace std; int n, m; bool viz[100003]; int main() { int i, sol, mindr, maxst, x, y, st, dr; cin >> n >> m; mindr = 200000; maxst = 0; for (i = 1; i <= m; ++i) { cin >> x >> y; viz[x] = viz[y] = true; st = min(x, y); dr = max(x, y); if ((st >= mindr) || (d...
2
#include <bits/stdc++.h> using namespace std; const char nl = '\n'; inline int _min(const register int& x, const register int& y) { return x < y ? x : y; } inline int _max(const register int& x, const register int& y) { return x > y ? x : y; } void solve() { ios_base::sync_with_stdio(false); cin.tie(NULL); ; ...
3
#include <bits/stdc++.h> using namespace std; void solve() { int n, m, d; cin >> n >> m >> d; vector<int> adj1; vector<pair<int, int>> ps; int c = 0; for (int i = 1; i <= m; i++) { int a, b; cin >> a >> b; ps.push_back({a, b}); if (min(a, b) == 1) c++, adj1.push_back(max(a, b)); } if (c ...
4
#include <bits/stdc++.h> using namespace std; vector<int> ar; int main() { std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n, tmp; cin >> n; ar.resize(n); for (int i = 0; i < n; i++) { cin >> ar[i]; } sort(ar.rbegin(), ar.rend()); long long int ans = 0; long long int sum =...
3
#include <bits/stdc++.h> int main() { int d, h, v, e; double r; while (scanf("%d %d %d %d", &d, &h, &v, &e) != EOF) { r = d * 1.0 / 2; double de = r * r * acos(-1.0) * e; if ((v - de) >= 0) { printf("YES\n"); printf("%.10lf\n", (r * r * h * acos(-1.0) * 1.0) / (v - de)); } else p...
1
#include <bits/stdc++.h> using namespace std; int id[110]; int n, m, k, x, y; map<int, int> mp; int fun(int &x, int &y) { int ans = 1; for (int i = x + 1; i <= y; i++) { if (mp[i] < mp[i - 1]) ans++; } return ans; } void h(int x, int y) { int nx = id[x]; int ny = id[y]; mp[nx] = y; mp[ny] = x; swa...
4
#include <bits/stdc++.h> using namespace std; const int SZ = 17, N = 1 << SZ; int Rev(int x) { int i, r = 0; for (i = 0; i < SZ; i++) { r = r << 1 | (x & 1); x >>= 1; } return r; } void FFT(long long *a, bool f) { int i, j, k; long long z; for (i = 0; i < N; i++) { j = Rev(i); if (i < j) {...
9
#include <bits/stdc++.h> using namespace std; int main() { long long int n, m, ans, p = 0, sum = -1; ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> m; long long int arr[n]; for (int i = 0; i < n; i++) { cin >> arr[i]; if (i < m) p += arr[i]; else if (i >= m) { if (p ...
1
#include <bits/stdc++.h> using namespace std; int main() { int n, m; scanf("%d%d", &n, &m); for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { if (i % 2 == 0) printf("#"); else if (j == 0 && (i + 1) % 4 == 0) printf("#"); else if (j == m - 1 && (i + 1) % 4 == 2) ...
0
#include <bits/stdc++.h> int Set(int N, int pos) { return N = N | (1 << pos); } int reset(int N, int pos) { return N = N & ~(1 << pos); } bool check(int N, int pos) { return (bool)(N & (1 << pos)); } using namespace std; const int maxx = 3e5 + 10; vector<long long> adj[maxx + 5], par(maxx + 5), dp(maxx + 5); long long ...
4
#include <bits/stdc++.h> using namespace std; template <class T> inline void read(T &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; } template <class T> T gcd(T a,...
13
#include <bits/stdc++.h> using namespace std; int cmp1(pair<int, int> a, pair<int, int> b) { return a.first < b.first; } int cmp2(pair<int, int> a, pair<int, int> b) { return a.second < b.second; } int main() { vector<pair<int, int> > v; int n, a, b; cin >> n; for (int i = 0; i < n; i++) { cin >> a >> b; ...
2
#include <bits/stdc++.h> using namespace std; int a1, a2; int fz(int x) { int t = 0; while (x) { t *= 10; t += x % 10; x /= 10; } return t; } int main() { cin >> a1 >> a2; cout << a1 + fz(a2); return 0; }
3
#include <bits/stdc++.h> using namespace std; int n; void printans() { printf("2 * 1 = 2\n"); printf("2 * 3 = 6\n"); printf("6 * 4 = 24\n"); } int main() { int i, j, fl, test; scanf("%d", &n); if (n <= 3) printf("NO\n"); else { printf("YES\n"); if (n == 4) { printans(); return 0; ...
3
#include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <fstream> #include <iostream> #include <list> #include <map> #include <unordered_map> #include <set> #include <string> #include <vector> #include <queue> #define ll long long #define dd long double #define ff first #...
0
#include <bits/stdc++.h> using namespace std; const long long l1 = 1LL; const int Len = 200000; vector<int> ans; stack<int> S[Len + 5], modS[3]; int am[3], A[Len + 5], nA[Len + 5]; int n; void Init() { ans.clear(); for (int i = 0; i < n; ++i) { while (!S[i].empty()) S[i].pop(); } memset(am, -1, sizeof(am));...
5
#include <bits/stdc++.h> using namespace std; int a[109]; int b[109]; vector<int> v; int main() { int t; cin >> t; while (t--) { v.clear(); int n; cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i < n; i++) { cin >> b[i]; if (!b[i]) v.push_back(a[i]...
2
#include <bits/stdc++.h> using namespace std; vector<long long> adj[300006]; int col[300007]; string s; long long MD = 998244353; long long res0 = 1, res1 = 1, res; bool fl = 0; void dfs(int u) { for (int i = 0; i < adj[u].size(); i++) { int v = adj[u][i]; if (col[v] == -1) { col[v] = 1 - col[u]; ...
4
#include <bits/stdc++.h> using namespace std; int a, b, c; int main() { cin >> a >> b >> c; c++; if (c > a - b) cout << a - b; else cout << c; }
1
#include <bits/stdc++.h> using namespace std; long long n, m, z, u, l, s, h, k, y, x, t, a[976869], b[987654], d[987654], e[685868], c[2001][2001]; long long i, j; map<long long, long long> f; string r, p, q, w[7675]; int main() { cin >> n; for (i = 0; i < n; i++) { for (j = 0; j < 4; j++) { cin >> p[...
2
#include <bits/stdc++.h> using namespace std; const int MaxSize = 200010; int n, m; vector<pair<int, int> > V[MaxSize]; int main() { int K, a, x, y, P, t, i, j, c, ans = 0; scanf("%d", &n); for (i = 1; i <= n; ++i) { scanf("%d%d%d%d%d", &K, &a, &x, &y, &P); if (c = 0, m < MaxSize) V[0].push_back(pair<int,...
6
#include <bits/stdc++.h> using namespace std; const int MAXN = 5001; double x[MAXN], y[MAXN], z[MAXN]; double dis[MAXN]; inline double calc(double x1, double y1, double z1, double x2, double y2, double z2) { return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2) + (z1 - z2) * (z1 -...
5
#include <bits/stdc++.h> using namespace std; const int N = 100002, md = 1000000007, INF = 10000001; using namespace std; int n, l, x, y, m, q, A1, fe, P[N], D[21]; vector<vector<int> > g; vector<int> tin, tout, pa, X[N], ans, ans1, mn[N][20]; int timer; vector<vector<int> > up; void dfs(int v, int p = 0) { tin[v] = ...
7
#include <bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<int, int>; using pll = pair<ll, ll>; template <class T> using vv = vector<vector<T>>; template <class T> inline bool MX(T &l, const T &r) { return l < r ? l = r, 1 : 0; } template <class T> inline bool MN(T &l, const T &r) { return...
4
#include <bits/stdc++.h> bool comp(const int& a, const int& b) { return a < b ? false : true; } using namespace std; long long int a[100009]; long long int b[100009]; queue<int> q; int z[100009]; multimap<long long int, int> asd; int main() { int n, i, j; cin >> n; for (i = 0; i < n; i++) { q.push(i); } f...
4
#include <bits/stdc++.h> using namespace std; signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t; cin >> t; while (t--) { int n, m, a, b; cin >> n >> m; vector<int> graph[n + 1]; for (int i = 0; i < m; i++) { cin >> a >> b; graph[a].push_back(b); g...
4
#include <bits/stdc++.h> using namespace std; vector<vector<int>> g; const int maxn = 100005; vector<bool> mark(maxn); vector<bool> tree(4 * maxn); int N; void query(int pos, int i, int j, int l, int r) { int esq = 2 * pos; int dir = 2 * pos + 1; int mid = (i + j) / 2; int dl = 0; int u; if (i > r || j < l)...
5
#include <bits/stdc++.h> using namespace std; int main() { long long int a, b, x; cin >> a >> b >> x; long long int i; if (x == 1) { for (i = 0; i < a; i++) cout << "0"; for (i = 0; i < b; i++) cout << "1"; return 0; } if (x % 2 == 1) { long long int hl = x / 2; for (i = 0; i < hl; i++) ...
2
#include <bits/stdc++.h> using namespace std; string s; int get(int x) { if (((int)(s[x - 1] - '0') * 10 + (int)(s[x] - '0')) % 4 == 0) return 1; return 0; } int main() { ios_base::sync_with_stdio(0); cin >> s; long long ans = 0; for (int i = 0; i < s.size(); i++) if ((int)(s[i] - '0') % 4 == 0) ans++; ...
2
#include <bits/stdc++.h> using namespace std; std::vector<int> visited1(100005), visited2(100005); string s1, s2; int n, k; int dfs(int i, int p, int q) { if (i + k >= n) return 1; int x = 0, y = 0, z = 0; if (p == 0) { if (i + k >= q + 1 && s2[i + k] == '-' && visited2[i + k] == 0) { visited2[i + k] = ...
3
#include <bits/stdc++.h> using namespace std; void solve() { long long n, s; cin >> n >> s; long long val = s / n; long long rem = s % n; long long val1 = val; long long val2 = val + rem; if (val > 1) { cout << "YES\n"; for (long long i = 0; i < n; i++) { if (i == n - 1) cout << val2...
3
#include <bits/stdc++.h> using namespace std; const long long MAX_N = 5e5 + 20; vector<long long> v[MAX_N], d, adj[MAX_N]; long long ans[MAX_N], h[MAX_N], f[MAX_N], q[MAX_N], n; string s; void DFS(long long r) { long long rs = adj[r].size(); q[r] = d.size(); for (int e = 0; e < rs; e++) { int i = adj[r][e]; ...
7
#include <bits/stdc++.h> using namespace std; int main() { vector<int64_t> A(8, 8); vector<int64_t> A_high(8, 0); vector<int64_t> B(8, 8); vector<int64_t> B_high(8, 8); int64_t amax = 8; int64_t bmax = 8; char k; for (int64_t i = 0; i < 8; i++) { for (int64_t j = 0; j < 8; j++) { cin >> k; ...
2
#include <bits/stdc++.h> using namespace std; int main() { int x, y; vector<vector<int> > v(5, vector<int>(5)); for (int i = 0; i < 5; ++i) { for (int j = 0; j < 5; ++j) { cin >> v[i][j]; } } for (int i = 0; i < 5; ++i) { for (int j = 0; j < 5; ++j) { if (v[i][j] == 1) { x = i ...
0
#include <bits/stdc++.h> using namespace std; struct toado { int u; int v; }; int main() { int m, n, x, y, z; vector<int> a; vector<int> b; vector<toado> c; cin >> n >> m >> x >> y; for (int i = 0; i < n; i++) { cin >> z; a.push_back(z); } for (int i = 0; i < m; i++) { cin >> z; b.pu...
2
#include<bits/stdc++.h> #define si(a) scanf("%d",&a) #define sl(a) scanf("%lld",&a) #define sd(a) scanf("%lf",&a) #define sc(a) scanf("%c",&a) #define ss(a) scanf("%s",a) #define pi(a) printf("%d\n",a) #define pl(a) printf("%lld\n",a) #define pc(a) putchar(a) #define ms(a) memset(a,0,sizeof(a)) #define repi(i, a, b) f...
7
#include <bits/stdc++.h> using namespace std; template <class T> ostream &operator<<(ostream &os, const vector<T> &p) { os << "["; for (auto &it : p) os << it << " "; return os << "]"; } template <class S, class T> ostream &operator<<(ostream &os, const pair<S, T> &p) { return os << "(" << p.first << "," << p.s...
0
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 10; int a[N]; int32_t main() { ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); int t; cin >> t; while (t--) { int n; cin >> n; for (int i = 0; i < (2 * n); ++i) cin >> a[i]; sort(a, a + (2 * n)); cout << a[n] - a[n - 1] ...
1
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; const long long mxn = 1e9 + 7; const long long inf = 1e18; vector<long long> vec; void fun(long long n, long long four, long long seven) { if (n > mxn) { return; } long long tem1 = (10 * n) + 4; if ((four + 1) == seven) { vec.p...
5
#include <bits/stdc++.h> using namespace std; int n, a[4444], cnt[4444]; map<int, int> id; vector<int> pos[4444]; int dp[4444]; int vis[4444]; int prev1(int el, int idx) { vector<int>::iterator it = lower_bound(pos[el].begin(), pos[el].end(), idx); if (it == pos[el].begin()) return -1; else { it--; re...
3
#include <bits/stdc++.h> using namespace std; pair<int, int> p[55]; int calc(int T, int n) { static pair<int, int> a[105], b[205]; int tot = 0; for (int i = 1; i <= n; i++) { a[++tot] = pair<int, int>(p[i].first - T, i); a[++tot] = pair<int, int>(p[i].first + T + 1, -i); } sort(a + 1, a + tot + 1); ...
13
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, m; cin >> n >> m; int x = 1; int y = 1; int levely = 1; int levelx = 1; vector<pair<int, int> > ans; int left = n * m; for (int i = 1; i <= m / 2; i++) { for (int j = 1; j <= n; j++) { ...
5
#include <bits/stdc++.h> using namespace std; char str[5111]; bool dp[5111][5111]; vector<int> bits[5111]; vector<pair<int, int> > cur; vector<char> ans; int main() { scanf("%s", str); int n = strlen(str); int cnt = 0; while ((1 << cnt) < n) cnt++; cnt--; int finalsz = n, cursz = 1; while (finalsz > cursz...
9
#include <bits/stdc++.h> using namespace std; void output_strings(int ind[], string s[]) { for (int i = 0; i < 6; i++) { cout << s[ind[i]] << " "; } cout << endl; return; } bool check(int ind[], string s[]) { int l[6]; char b[6], e[6]; for (int i = 0; i < 6; i++) { l[i] = s[ind[i]].length(); b...
6
#include <bits/stdc++.h> int main() { int m, n, ma = 11, mb = 11; int ans = 110; scanf("%d%d", &m, &n); int fl[11], sl[11]; for (int a = 0; a < m; a++) { scanf("%d", &fl[a]); if (fl[a] < ma) ma = fl[a]; } for (int a = 0; a < n; a++) { scanf("%d", &sl[a]); if (sl[a] < mb) mb = sl[a]; } ...
0
#include <bits/stdc++.h> using namespace std; int n, j = 0; int a[1000 + 10]; int main() { cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; } sort(a, a + n); if (n % 2 == 0) { cout << a[(n - 1) / 2] << endl; } else cout << a[n / 2] << endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; long long n, ans; void go(long long x) { if (x == 0) return; long long f = 1; while (f <= x) { f *= 2; } x -= f / 2; ans++; go(x); } int main() { cin >> n; go(n); cout << ans; return 0; }
1
#include <bits/stdc++.h> using namespace std; int main() { char arr[4][4]; for (int i = 0; i < 3; i++) for (int j = 0; j < 3; j++) cin >> arr[i][j]; if (arr[0][0] != arr[2][2] || arr[0][1] != arr[2][1] || arr[0][2] != arr[2][0] || arr[1][0] != arr[1][2]) cout << "NO" << endl; else cout << "YES...
0
#include <bits/stdc++.h> using namespace std; int n, m; const int N = 2e5 + 5, inf = 1e9; int dp[N][2], a[N]; bool bad[N][2]; int P[N][2]; int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> n; vector<int> ans(n + 1); dp[0][0] = inf; dp[0][1] = -1; for (int i = 1, val; i <= n; i++) { cin >> val; ...
8
#include <bits/stdc++.h> using namespace std; int dfs(int u, vector<int> adj[], vector<bool> &vist, int p) { int i; vist[u] = true; for (i = 0; i < adj[u].size(); i++) { if (vist[adj[u][i]] == true && adj[u][i] != p) return 1; if (vist[adj[u][i]] == false && adj[u][i] != p) { if (dfs(adj[u][i], adj,...
4
#include <bits/stdc++.h> using namespace std; long long get_ans(vector<long long> arr, long long bit) { vector<long long> left_ans, right_ans; for (auto& x : arr) { if (x & (1 << bit)) { right_ans.push_back(x ^ (1 << bit)); } else { left_ans.push_back(x); } } if (!bit) { return left_...
6
#include <bits/stdc++.h> using namespace std; using ll = long long; void solve() { int n; cin >> n; vector<int> last_pos(n, -1); vector<int> max_dist(n); for (int i = 0; i < n; ++i) { int t; cin >> t; --t; max_dist[t] = max(max_dist[t], i - last_pos[t]); last_pos[t] = i; } for (int i =...
3
#include <bits/stdc++.h> using namespace std; int main() { int t, n; cin >> t; while (t--) { cin >> n; int x; vector<int> even, odd; for (int i = 1; i <= n; i++) { cin >> x; if (x % 2 == 0) { even.push_back(i); } else { odd.push_back(i); } } if (even...
0
#include <bits/stdc++.h> using namespace std; int main() { char str[100010]; int A[200]; memset(A, 0, sizeof A); scanf("%s", str); int len = strlen(str); int ans = 1; char temp; for (int i = 0; i < len; i++) { if (i == 0 && str[i] == '?') ans *= 9; else if (str[i] == '?' && i != 0) a...
1
#include <bits/stdc++.h> struct max { int num, much; } max; int a[55], b[55]; int main() { int i, an, bn; max.num = -1, max.much = 0; scanf("%d", &an); for (i = 0; i < an; i++) { scanf("%d", &a[i]); } scanf("%d", &bn); for (i = 0; i < bn; i++) { scanf("%d", &b[i]); } for (i = 0; i < an; i++)...
0
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t-- > 0) { int n, m; cin >> n; int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } int i = 0, t = 0, f = 0; while (i < n - 1) { if (a[0] != 1) { f = 1; cout << "First\n"; ...
1
#include <bits/stdc++.h> using namespace std; int main() { int n, m; vector<int> nums; scanf("%d%d", &n, &m); for (int i = 0; i < m; i++) { int y; scanf("%*d%d", &y); nums.push_back(y); } sort(nums.begin(), nums.end()); int i; for (i = 1;; i++) { int vv; if (i % 2 == 1) vv = (i * i -...
6
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1.0); int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long int n; cin >> n; vector<long long int> arr(n); long long int sum = 0, cnt = 0; for (long long int i = 0; i < n; i++) { long long int temp; cin >> temp...
1
#include <bits/stdc++.h> using namespace std; int main() { int t; scanf("%d", &t); while (t--) { int a, b, c; scanf("%d%d%d", &a, &b, &c); long long sum = 0; sum = a + 2 * b + 3 * c; if (sum % 2 == 0) cout << 0 << endl; else cout << 1 << endl; } }
0
#include <bits/stdc++.h> using namespace std; bool isprime(long long int n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; for (int i = 5; i * i <= n; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } vector<long long int> prime; ...
5
#include <bits/stdc++.h> using namespace std; void bmin(long long &a, long long b) { a = (a < b) ? a : b; } int read() { int x = 0, w = 1; char ch = getchar(); while (ch > '9' || ch < '0') { if (ch == '-') w = -1; ch = getchar(); } while (ch <= '9' && ch >= '0') x = x * 10 + ch - '0', ch = getchar(); ...
11
#include <bits/stdc++.h> using namespace std; int main() { long long i, j, k, n, m, t, tc; string str = "aabb"; scanf("%lld", &n); if (n % 2) m = n / 2; else m = n / 2 - 1; printf("%lld", m); return 0; }
1
#include <bits/stdc++.h> using namespace std; int _, n, m, s[30]; int gcd(int x, int y) { return y ? gcd(y, x % y) : x; } int main() { int i, x, y; for (scanf("%d", &_); _; _--) { scanf("%d%d\n", &n, &m); memset(s, 0, sizeof(s)); for (i = 1; i <= n; i++) s[getchar() - 96]++; while (1) { x = gc...
5
#include <bits/stdc++.h> using namespace std; int n, s1, s2, s3, a[5005], i, s; int main() { cin >> n; cout << "? " << 1 << " " << 2 << "\n"; cout.flush(); cin >> s1; cout << "? " << 1 << " " << 3 << "\n"; cout.flush(); cin >> s2; cout << "? " << 2 << " " << 3 << "\n"; cout.flush(); cin >> s3; a[1...
3
#include <bits/stdc++.h> using namespace std; int t; int n, k, l; int d; int ta[300010]; vector<int> kk; vector<int> zz; int main() { cin.tie(0); ios_base::sync_with_stdio(0); cin >> t; for (int i = 0; i < t; i++) { cin >> n >> k >> l; bool czy = true; zz.clear(); kk.clear(); kk.push_back(0)...
5
#include <bits/stdc++.h> using namespace std; long long merge(string &s, long long lo, long long mid, long long hi) { long long inversion_count = 0; string x = s.substr(lo, hi - lo + 1); long long start1 = lo, start2 = mid + 1; long long k = start1; while (start1 <= mid && start2 <= hi) { if (x[start1 - l...
6
#include <bits/stdc++.h> using namespace std; int main() { int n, m; double x; cin >> n >> m; vector<int> v; for (int i = 0; i < n; i++) { cin >> m >> x; int ind = upper_bound(v.begin(), v.end(), m) - v.begin(); if (ind == v.size()) v.push_back(m); else v[ind] = m; } cout << n ...
4
#include <bits/stdc++.h> using namespace std; int read() { int x = 0; bool flg = false; char ch = getchar(); for (; !isdigit(ch); ch = getchar()) if (ch == '-') flg = true; for (; isdigit(ch); ch = getchar()) x = (x << 3) + (x << 1) + (ch ^ 48); return flg ? -x : x; } int n; int c[200010]; vector<int> e...
8
#include <bits/stdc++.h> using namespace std; int R, C, res, total; int cnt[155]; int mn[155], mx[155]; char ar[155][155]; void F(int r, int c) { if (ar[r][c] == 'W') { cnt[r]--; total--; } if (total == 0) return; res++; if (r % 2 == 0) { if (cnt[r] == 0 && c >= mx[r + 1]) F(r + 1, c); e...
3
#include <bits/stdc++.h> #pragma GCC optimize "-O3" using namespace std; const int MX = 1e6 + 1; const int D = 1000; const int INF = 1e9; map<vector<int>, int> mm; vector<vector<int>> gg; int tmp[D]; int tmp2[D]; int ds[300][D]; int aa[300][300]; int bb[MX]; vector<int> pr; int ggg[MX]; int cnt = 0; int get(vector<int>...
10
#include <bits/stdc++.h> int main() { int i, j, a, b, n, k; scanf("%d", &n); scanf("%d", &a); int x[a]; for (k = 0; k < a; k++) { scanf("%d", &x[k]); } scanf("%d", &b); int y[b], z[a + b]; for (k = 0; k < b; k++) { scanf("%d", &y[k]); } for (i = 0; i < a; i++) { z[i] = x[i]; } for ...
0
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int a, b, c, d, k; cin >> a >> b >> c >> d >> k; int x = a / c; if (a % c != 0) x++; int y = b / d; if (b % d != 0) y++; if (x + y > k) cout << -1; else cout << x << " " << y; ...
0
#include <bits/stdc++.h> using namespace std; template <class T> ostream &operator<<(ostream &os, const vector<T> &vec) { os << '{'; for (int i = (0), __i = (((int)(vec).size())); i < __i; i++) { os << vec[i]; if (i + 1 != ((int)(vec).size())) os << ','; } os << '}'; return os; } template <class T1, c...
3
#include <bits/stdc++.h> using namespace std; int n, q, a[300005], bit[300005]; vector<vector<int>> queries; bool cmp(vector<int>& a, vector<int>& b) { return a[1] < b[1]; } int query(int x) { int sm = 0; while (x) { sm += bit[x]; x -= x & -x; } return sm; } void update(int x, int val) { while (x < 30...
7
#include <bits/stdc++.h> using namespace std; void solve() { int a, b, c, m; cin >> a >> b >> c >> m; int maxl = max(a - 1, 0) + max(b - 1, 0) + max(c - 1, 0); int maxv = max(a, max(b, c)); int rest = a + b + c - maxv; int minl = max(0, maxv - rest - 1); if (maxl >= m and m >= minl) { cout << "YES" <<...
1
#include <bits/stdc++.h> using namespace std; const int INF = 2034567891; const long long int INF64 = 4234567890123456789ll; long long nc3(long long v) { return (v * (v - 1ll) * (v - 2ll)) / 6ll; } long long nc2(long long v) { return (v * (v - 1ll)) / 2ll; } long long int gcd(long long int a, long long int b) { retur...
0
#include <bits/stdc++.h> using namespace std; template <class T> void in(T &x) { x = 0; bool f = 0; char c = getchar(); while (c < '0' || c > '9') { if (c == '-') f = 1; c = getchar(); } while ('0' <= c && c <= '9') { x = (x << 3) + (x << 1) + (c ^ 48); c = getchar(); } if (f) x = -x; } ...
8
#include <bits/stdc++.h> using namespace std; int caseno = 0; void yesno(bool okk) { cout << (okk ? "YES" : "NO") << '\n'; } const int primemod = 1000000007; const long long maxsize = 1 * 1000000 + 9; const double eps = 1e-10; const int N = 210; int freq[maxsize]; bool sortbysec(pair<string, int> a, pair<string, int> b...
5
#include <bits/stdc++.h> using namespace std; template <typename T> void rd(T &x) { x = 0; bool f = 0; char c = getchar(); while (!isdigit(c)) { if (c == '-') f = 1; c = getchar(); } while (isdigit(c)) x = (x << 1) + (x << 3) + (c ^ 48), c = getchar(); if (f) x = -x; } const long long N = 5e5 + 5;...
8
#include <bits/stdc++.h> using namespace std; template <typename Arg1> void __f(const char* name, Arg1&& arg1) { std::cerr << name << " : " << arg1 << '\n'; } template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args) { const char* comma = strchr(names + 1, ','); std::cerr...
1
#include <bits/stdc++.h> using namespace std; const int MAXN = 150; int n, m, k, ar[MAXN][MAXN], sum[MAXN][MAXN], ans1, ans2, tmpans1, tmpans2; int main() { scanf("%d%d%d", &n, &m, &k); for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { scanf("%d", &ar[i][j]); } } for (int i = 1; i <= m...
4
#include <bits/stdc++.h> using namespace std; template <class TAT> void read(TAT &a) { static char cc; static bool fff; while (((cc = getchar()) < '0' || cc > '9') && cc != '-') ; if (cc == '-') fff = 1, a = 0; else fff = 0, a = cc - 48; while ((cc = getchar()) >= '0' && cc <= '9') a = a * 10 + ...
7
#include <bits/stdc++.h> using namespace std; double EPS = 1e-9; int INF = 2000000; long long INFF = 8000000000000000000LL; double PI = acos(-1); inline string IntToString(int a) { char x[100]; sprintf(x, "%d", a); string s = x; return s; } inline int StringToInt(string a) { char x[100]; int res; strcpy(x...
5
#include <bits/stdc++.h> using namespace std; long long ans[100005]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long n, i, j, cnt = 1; cin >> n; for (i = 2; i <= n; i++) { if (ans[i] == 0) { for (j = i; j <= n; j += i) ans[j] = cnt; cnt++; } } for (i...
2
#include <bits/stdc++.h> using namespace std; template <typename TH> void _dbg(const char *sdbg, TH h) { cerr << sdbg << "=" << h << "\n"; } template <typename TH, typename... TA> void _dbg(const char *sdbg, TH h, TA... t) { while (*sdbg != ',') { cerr << *sdbg++; } cerr << "=" << h << ","; _dbg(sdbg + 1,...
4
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; long long n, m; long long pow_log(long long k) { if (k == 0) { return 1; } long long b = pow_log(k / 2); b = (b * b) % MOD; if (k % 2) { b = (b * 2) % MOD; } return b; } int main() { cin >> n; m = pow_log(n - 1); if...
2
#include <bits/stdc++.h> using namespace std; const int inf = 1e9; int n, S, T, dis[6010], ans, path[6010], a[3010]; bool used[6010]; int cnt = 1, head[6010], to[50010], nxt[50010], v[50010], w[50010]; void add(int x, int y, int z, int f) { cnt++; to[cnt] = y; nxt[cnt] = head[x]; head[x] = cnt; v[cnt] = f; ...
9
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int arr[n]; for (int i = 0; i < n; i++) { cin >> arr[i]; } sort(arr, arr + n); long long int ans = 0; for (int i = 1; i <= n; i++) { ans += abs(arr[i - 1] - i); } cout << ans; return 0; }
2
#include <bits/stdc++.h> using namespace std; long long int bigMod(long long int x, long long int y, long long int MOD = 10000007) { if (y == 0) return 1 % MOD; long long int haha = bigMod(x, y / 2, MOD); haha = (haha * haha) % MOD; if (y & 1) return (haha * x) % MOD; return haha; } long ...
1
#include <bits/stdc++.h> using namespace std; int n, c4, c5, c3, s; int I, J, K; int main() { scanf("%d %d", &n, &s); for (int i = 0; i < n; ++i) { int x; scanf("%d", &x); c3 += x == 3; c4 += x == 4; c5 += x == 5; } int ans = 1e9 + 10; for (int i = s / n; i >= 0; --i) { for (int j = (s...
8
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:16777216") using namespace std; double pi = acos((double)-1); const int MOD = 1000000007; const int INF = 2147483647; vector<int> s; vector<int> mulres; vector<int> move_perm; vector<int> sort_perm; void multiply_perm(vector<int>& perm, vector<int>& by, int n) { ...
9
#include <bits/stdc++.h> using namespace std; const int N = 100; int t, n, k; struct ab { int l, r; int ll, rr; } aa[N + 5]; int cc[N * 2 + 5]; int main() { scanf("%d", &t); while (t--) { scanf("%d%d", &n, &k); set<int> q; for (int i = 1; i <= n; ++i) { q.insert(i); q.insert(i + n); ...
5