solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> using namespace std; int a[4], x, y, z; int main() { cin >> a[1] >> a[2] >> a[3]; sort(a + 1, a + 4); x = a[1], y = a[2], z = a[3]; if (x + y > z) cout << 0; else cout << z - x - y + 1; return 0; }
0
#include <bits/stdc++.h> using namespace std; string s; int f = 0; int t = 0; int x; int main() { cin >> s; x = s.length(); for (int i = 0; i < x; i++) { if (s[i] == 'a') { t++; } else { f++; } } if (t > f) { cout << x; } else { cout << (t + (t - 1)); } return 0; }
0
#include <bits/stdc++.h> using namespace std; int main() { char s[100][100]; int n, m; cin >> n >> m; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) cin >> s[i][j]; } for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { int flag1 = 1, flag2 = 1; for (int k = 0; k < m; k...
3
#include <bits/stdc++.h> using namespace std; const int MAXN = 200000; int n, m; vector<pair<int, int> > eds[MAXN]; vector<tuple<int, int, int> > ed; vector<int> v[2]; int was[MAXN]; int fl; void dfs(int v, int cl) { was[v] = cl; ::v[cl - 1].push_back(v); for (pair<int, int> x : eds[v]) { int u = x.first; ...
14
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int r, c; cin >> r >> c; for (int i = 1; i <= r; i++) { for (int j = 1; j <= c; j++) { bool hasHead = false; if (i % 2 == 1) hasHead = true; else { if (i % 4 == 2) hasHead ...
0
#include <bits/stdc++.h> using namespace std; int a[200010], b[200010], c[200010], second[200010], n; bool vis[200010]; multiset<int> st; void deal() { for (int i = 1; i <= 2 * n; i++) second[i] = second[i - 1] + a[i] - b[i]; st.clear(); for (int i = 1; i < n; i++) st.insert(second[i]); st.insert(0); for (int...
12
#include <bits/stdc++.h> using namespace std; long long pw(long long base, long long expo, long long c) { if (expo == 0) return 1; long long f = pw(base, expo / 2, c); if (expo & 1) return (((f * f) % c) * base) % c; return (f * f) % c; } long long n, a, b, c, d; int check(long long val) { if (val >= 1 && val...
6
#include <bits/stdc++.h> using namespace std; const long double pi = 3.1415926535897932384626433832795l; template <typename T> inline auto sqr(T x) -> decltype(x * x) { return x * x; } template <typename T1, typename T2> inline bool umx(T1& a, T2 b) { if (a < b) { a = b; return 1; } return 0; } template...
14
#include <bits/stdc++.h> using namespace std; int const N = 1000000; int const B = 20; int n, m; bool valid; int ans[N]; int cnt; int maxc[N + 1], maxl[N + 1]; int minr[N + 1]; int st[B][N + 1]; int query(int l, int r) { int sz = r - l + 1; int b = 0; while ((1 << (b + 1)) < sz) { ++b; } return maxc[st[b]...
16
#include <bits/stdc++.h> using namespace std; const long long M = 998244353; const long long N = 1e6 + 10; long long a[N], p2[N]; void solve() { long long n; cin >> n; for (long long i = 0; i < n; i++) cin >> a[i]; if (n == 1) { cout << a[0]; return; } p2[0] = 1; for (long long i = 1; i <= n; i++)...
12
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); string a; cin >> a; string b = a; reverse(b.begin(), b.end()); cout << a << b << endl; }
0
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; string str; cin >> n >> str; string Min; for (int i = 0; i < 10; ++i) { for (int j = 0; j < n; ++j) { str[j] = (str[j] - '0' + 1) % 10 + '0'; } if (i == 0) Min = str; els...
7
#include <bits/stdc++.h> using namespace std; template <typename T> T pow(T a, T b, long long int m) { T ans = 1; while (b > 0) { if (b % 2 == 1) ans = (ans * a) % m; b /= 2; a = (a * a) % m; } return ans % m; } template <typename T> T InverseMod(T a, long long int m) { return pow(a, m - 2, m); } ...
9
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; if (n <= 2) { cout << "No"; return 0; } cout << "Yes" << "\n"; int k = (n % 2 == 0) ? n / 2 : (n + 1) / 2; cout << 1 << " " << k << "\n"; cout << n - 1 << " "; for (int i...
3
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ; long long n; cin >> n; long long x; map<long long, long long> mp; for (long long i = 0; i < n; i++) { cin >> x; mp.insert(make_pair(x, i + 1)); } for (long long i =...
4
#include <bits/stdc++.h> using namespace std; int main() { long long n, k; cin >> n >> k; long long res = 1; long long mod = (1e+9) + 7; for (int i = (1); i <= (k - 1); i++) res *= k; res %= mod; long long m = n - k; for (int i = (1); i <= (m); i++) res = (res * m) % mod; cout << res; return 0; }
7
#include <bits/stdc++.h> const int Max = 1e5 + 10; using namespace std; struct edge { int to; int next; }; multiset<int> point[Max << 1]; vector<int> e[Max], g[Max << 1]; int tree[Max << 3], val[Max << 1]; int dfn[Max << 1], rDfn[Max << 1], low[Max << 1], son[Max << 1], hTop[Max << 1], size[Max << 1], fa[Max <<...
24
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin >> n; if (n % 2 != 0) cout << 0; else { long long dp[n + 1]; dp[1] = 0; dp[2] = 2; for (long long i = 3; i < n + 1; i++) dp[i] = 2 * dp[i - 2]; cout << dp[n]; } }
2
#include <bits/stdc++.h> using namespace std; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long n, cnt = 0; string str[505]; string s; cin >> n; for (long long i = 0; i < n; i++) { cin >> s; str[i] = ""; str[i] += s; } for (long long i = 1; i <= n - 2;...
0
#include <bits/stdc++.h> using namespace std; bool primes[1000007]; void fnc() { for (int i = 4; i <= 1000000; i += 2) primes[i] = 1; primes[1] = 1; int limit = sqrt(1000000) + 1; for (long long i = 3; i <= 1000000; i += 2) { if (!primes[i]) { if (i <= limit) { for (long long j = i * i; j <= 1...
5
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f; const int MAX_N = 1000 + 5; const double EPS = 1e-6; int a[MAX_N]; int main(void) { int t, i; cin >> t; while (t--) { int n, m; cin >> n >> m; for (i = 0; i < n; i++) scanf("%d", &a[i]); int sum = 0; for (i = 1; i < n; i++...
0
#include <bits/stdc++.h> using namespace std; const int mx = 1000000001; int main() { int n; cin >> n; int kx, ky; cin >> kx >> ky; vector<pair<int, char> > smx, smy, smdg, smdg1; for (int i = 0; i < n; i++) { char ch; int x, y; cin >> ch >> x >> y; if (x == kx) smx.push_back(make_pair(y, ch...
9
#include <bits/stdc++.h> using namespace std; const int MAXN = 2e3 + 10; int n, a[MAXN], cnt1[MAXN], cnt2[MAXN]; int get(int i, int j, int cnt[MAXN]) { return cnt[j] - cnt[i]; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> n; for (int i = 0; i < int(n); i++) cin >> a[i]; cnt1[0] = cnt2[0]...
10
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; const int maxn = 1e6 + 10; int a[100], b[100]; vector<int> x[40010]; vector<int> y[40010]; bool xx[100]; bool yy[100]; int main() { ios_base::sync_with_stdio(0); int n, m; set<int> s; cin >> n >> m; for (int i = 0; i < n; i++) cin >> a[i];...
13
#include <bits/stdc++.h> using namespace std; int n, k, p[1005]; set<int> y; void sieve() { memset(p, 1, sizeof(p)); for (int i = 2; i <= 32; i++) { if (p[i]) { for (int j = i * i; j <= 1000; j += i) p[j] = 0; } } } int main() { sieve(); cin >> n; for (int i = 2; i <= n; i++) { if (p[i]) {...
7
#include <bits/stdc++.h> using namespace std; int n, h; const int MAXN = 1005; int a[MAXN]; vector<int> curr; int main() { ios::sync_with_stdio(0); cin >> n >> h; for (int i = 0; i < n; i++) cin >> a[i]; bool done = false; for (int i = 0; i < n; i++) { curr.push_back(a[i]); sort(curr.rbegin(), curr.re...
5
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; const int N = 1e6 + 7; void my_dbg() { cout << endl; } template <typename Arg, typename... Args> void my_dbg(Arg A, Args... B) { cout << ' ' << A; my_dbg(B...); } int main() { long long n; scanf("%lld", &n); long long a = n / 2520; ...
3
#include <bits/stdc++.h> using namespace std; int el[200005]; int n; long long sum = 0; vector<int> prop; int main() { scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d", &el[i]); sum += el[i]; } for (int i = 0; i < n; i++) { long long d = sum - (long long)el[i]; if (!(d % (long long)(n -...
4
#include <bits/stdc++.h> using namespace std; int pre[100005][20], suf[100005][20], mn[100005][20]; int a[100005], lg[100005], n, ans; int getmn(int x, int y) { if (x > y) return 1e9; int k = lg[y - x + 1]; return min(mn[x][k], mn[y - (1 << k) + 1][k]); } int getmn1(int x, int y) { if (x > y) return 1e9; int ...
21
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 5; const long long mod = 1e9 + 7; const int alphabet = 26; const int inf = INT_MAX; const long long linf = 1e18 + 9; inline long long cnm(char ch) { return (ch - '0'); } inline long long cap(char ch) { return (ch - 'a'); } inline void instr(string& s,...
5
#include <bits/stdc++.h> using namespace std; template <typename T> void chmax(T &a, T b) { a = max(a, b); } template <typename T> void chmin(T &a, T b) { a = min(a, b); } template <typename T> void chadd(T &a, T b) { a = a + b; } long long int dx[] = {0, 0, 1, -1}; long long int dy[] = {1, -1, 0, 0}; const long ...
17
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; char s1[N], s2[N]; int cnt[N][26]; int cnt2[N][26]; int tmp[26], tmp2[26]; bool dfs(int l, int r, int t, int p) { bool flag = true; for (int i = l, j = t; i <= r; i++, j++) { if (s1[i] != s2[j]) { flag = false; break; } } i...
9
#include <bits/stdc++.h> using namespace std; const int maxN = 2e5 + 5; long long fac[maxN], iv[maxN], pwK[maxN], pwK2[maxN]; long long powmod(long long x, long long y) { long long ans = 1; x %= 998244353; while (y > 0) { if (y & 1) ans = (ans * x) % 998244353; y >>= 1; x = (x * x) % 998244353; } ...
14
#include <bits/stdc++.h> using namespace std; void file() { freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); } void zuka() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); } bool primes[2750135]; long long spf[2750135]; map<long long, long long> p; void pre() { p[0] = 0; int k = 1;...
10
#include <bits/stdc++.h> using namespace std; const int N = (int)(1e5) + 100; long long n, m, k; const long long mod = (int)(1e9) + 7; long long bp(long long a, long long b) { if (b == 0) return 1ll; if (b == 1) return a; long long x = bp(a, b / 2) % mod; long long y = bp(a, b % 2) % mod; return (((x * x) % m...
8
#include <bits/stdc++.h> using namespace std; long long n, q; struct EDGE { int v, inx; long long w; }; vector<EDGE> edges[100010]; long long son[100010]; double tot; long long cnt[100010], wet[100010]; void dfs(int u, int par) { son[u] = 1; for (int i = 0; i < edges[u].size(); ++i) { EDGE edge = edges[u][i...
11
#include <bits/stdc++.h> using namespace std; int cnt, j, n, m, k, i, cnt1, sum, fr, re; int ss[2000010], ff[2000010], pred[2000010]; int last[1000010], x[1000010], was[1000010]; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> m >> k; for (i = 1; i <= m; i++) { cin >> ss[i] ...
14
#include <bits/stdc++.h> using namespace std; const int N = 1000100; const int INF = int(2e9); long long n, k, a[N], ans = 0, mini = (1e16); int main() { ios_base ::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> k; for (int i = 1; i <= n; i++) { cin >> a[i]; if (a[i] < mini) mini = a[i]; }...
1
#include <bits/stdc++.h> using namespace std; int main() { long long n, i, q, j = 0, k = 0, ans = 0, m = 0, y, x = 0; cin >> q; while (q--) { cin >> n; ans = 0, m = 0; vector<pair<long long, long long> > v(n, make_pair(0, 0)); for (i = 0; i < n; i++) { cin >> x >> y; x--; v[x].fi...
6
#include <bits/stdc++.h> using namespace std; long long int prime[2001]; vector<long long int> factor[2001]; void seive(long long int n) { memset(prime, 0, sizeof(prime)); prime[0] = 0; prime[1] = 1; for (int i = 2; i <= n; i++) { if (prime[i] == 0) { prime[i] = i; for (int j = 2 * i; j <= n; j ...
6
#include <bits/stdc++.h> using namespace std; long long s[200050]; long long t[200050]; int n; int ansi = 1, ansl = 0; double ans = -1; double now1, now2, nowans; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%I64d", &t[i]); } sort(t + 1, t + n + 1); s[0] = 0; for (int i = 1; i <= ...
16
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const double PI = acos(-1.0); int a, b, f, k; int main(void) { ios_base::sync_with_stdio(false); cin >> a >> b >> f >> k; int tank = b; bool at = 0; int res = 0; while (k--) { int dist; if (at == 0) dist = f; else ...
7
#include <bits/stdc++.h> using namespace std; priority_queue<pair<int, int>, vector<pair<int, int> >, greater<pair<int, int> > > pq; int a[600005], ans; int n, k, pre[600005], nxt[600005]; int main() { scanf("%d%d", &k, &n); for (int i = 1; i <= n; ++i) scanf("%d", &a[i]); sort(a + 1, a + n + 1...
14
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int *x = new int[n]; for (int i = 0; i < n; i++) cin >> x[i]; int max = 1, counter = 1, k = n; for (int i = 0; i < n; i++) for (int j = i + 1; j < n; j++) if (x[i] > x[j]) swap(x[i], x[j]); for (int i = 0; i < n - 1; i++...
2
#include <bits/stdc++.h> #pragma - GCC - optimize("-Ofast"); const int Max = 1000000 + 100; 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 * 1...
8
#include <bits/stdc++.h> using namespace std; inline long long quick_pow(long long a, long long n, long long MOD) { long long res = 1; a = (a % MOD + MOD) % MOD; while (n) { if (n & 1) res = res * a % MOD; a = a * a % MOD; n >>= 1; } return res; } inline long long rev(long long a, long long p) { ...
18
#include <bits/stdc++.h> using namespace std; int n, m, ans; string s[100]; string str[100]; string str2[100]; int main() { scanf("%d%d", &n, &m); for (int i = 0; i < n; i++) cin >> s[i]; for (int j = 0; j < m; j++) { for (int i = 0; i < n; i++) { str2[i] = str[i]; str2[i] += s[i][j]; } bo...
7
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 7; const int MX = 1e9 + 7; const long long int INF = 1e18 + 9LL; int n; int p[N]; long long int out[N]; long long int t, in[N]; int main() { scanf("%d %lld", &n, &t); for (int i = 1; i <= n; ++i) { scanf("%lld", &in[i]); out[i] = in[i] + t; ...
15
#include <bits/stdc++.h> using namespace std; vector<string> lesha, lesha1; map<string, int> ma; vector<vector<string> > tc; int n, m, k; int inv(vector<string> a) { int r = 0; for (int i = 0; i < a.size() - 1; i++) { for (int j = i + 1; j < a.size(); j++) { if (ma[a[i]] > ma[a[j]]) { r++; }...
9
#include <bits/stdc++.h> using namespace std; void file() { freopen("capitals.in", "r", stdin); freopen("capitals.out", "w", stdout); } void boos() { ios_base ::sync_with_stdio(0); cin.tie(0); cout.tie(0); } const long long INF = (long long)1e9 + 7ll; const long long INF1 = 998244353; const long long INF2 = (...
24
#include <bits/stdc++.h> using namespace std; double c(double a, double b) { double r = 1; for (int i = 0; i < b; i++) { r *= a - i; r /= i + 1; } return r; } int main() { int n, m, h; cin >> n >> m >> h; h--; int other = 0, same = 0; for (int i = 0; i < m; i++) { int a; cin >> a; ...
8
#include <bits/stdc++.h> using namespace std; template <class T1> void deb(T1 e1) { cout << e1 << endl; } template <class T1, class T2> void deb(T1 e1, T2 e2) { cout << e1 << " " << e2 << endl; } template <class T1, class T2, class T3> void deb(T1 e1, T2 e2, T3 e3) { cout << e1 << " " << e2 << " " << e3 << endl; ...
5
#include <bits/stdc++.h> using namespace std; int f[100005], ff[100005], g[100005], h[100005]; int read() { int x = 0; char ch = getchar(); while (ch > '9' || ch < '0') { ch = getchar(); } while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); } return x; } int main() { int ...
9
#include <bits/stdc++.h> using namespace std; void fast_IO() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); } const long long INF = 1e18; const long long DEBUG = 1; long long n; string s; vector<long long> a; void init() { cin >> s; n = s.size(); a.clear(); long long cnt = 0; for (long lon...
0
#include <bits/stdc++.h> using namespace std; const int maxn = 18, maxm = 100, maxl = 1 << 18; const long long powten[maxn + 5] = {1, 10, 100, 1000, 10000, ...
12
#include <bits/stdc++.h> using namespace std; stack<int> st; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); string com; int n, res = 0, del = 1; cin >> n; n <<= 1; for (int i = 0, num; i < n; ++i) { cin >> com; if (com == "add") { cin >> num; st.push(num); } else { ...
7
#include <bits/stdc++.h> using namespace std; int n, ok, ans; vector<int> q; struct point { int x[10]; } a[10010], b, c; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; for (int i = 1; i <= n; i++) { for (int j = 1; j <= 5; j++) { cin >> a[i].x[j]; } } for (in...
9
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; vector<int> a(N), b(N); for (auto &i : a) cin >> i; for (auto &i : b) cin >> i; int ans = 0; int tmp_a, tmp_b; for (int i = 0; i < N; i++) { for (int j = i; j < N; j++) { tmp_a = tmp_b = 0; for (int x = i; x <= j...
1
#include <bits/stdc++.h> #pragma comment(linker, "/stack:200000000") using pii = std::pair<long long, long long>; using namespace std; long long n, k, a, cnt[1005] = {0}; class ADrinksChoosing { public: void solve(std::istream& in, std::ostream& out) { in >> n >> k; for (long long i = (0); i < (n); i++) { ...
2
#include <bits/stdc++.h> using namespace std; int sum[100500], gr[100500]; int was[500]; inline int get(int left, int right) { if (left == 0) return sum[right]; return sum[right] ^ sum[left - 1]; } int main() { int n; cin >> n; gr[0] = gr[1] = sum[0] = sum[1] = 0; for (int i = 2; i <= n; i++) { for (int...
12
#include <bits/stdc++.h> using namespace std; int n, m, v[260]; int main() { cin >> n >> m; memset(v, -1, sizeof(v)); v[0] = 0; for (int i = 1; i <= n; i++) { int x; cin >> x; if (v[x] == -1) { for (int i = x - m + 1; i <= x; i++) { if (v[i] == -1 || v[i] == i) { for (int j =...
9
#include <bits/stdc++.h> using namespace std; vector<int> addv(vector<int> a, vector<int> b) { for (int i = 0; i < 26; ++i) { a[i] += b[i]; } return a; } int main(int argc, char const *argv[]) { int t; cin >> t; while (t--) { int n, m; cin >> n >> m; string s; cin >> s; vector<int> a...
5
#include <bits/stdc++.h> using namespace std; template <typename T> void answer(T ans) { cout << ans; exit(0); } bool beat[8][8]; void addbeat(int r, int c) { if (r < 0 || r > 7 || c < 0 || c > 7) return; beat[r][c] = true; } int tr, tc, cr, cc; bool beats(int r, int c) { if (r < 0 || r > 7 || c < 0 || c > 7)...
4
#include <bits/stdc++.h> int main() { long long a, b, c, x, y, z; scanf("%lld%lld%lld", &a, &b, &c); if ((a + b + c) % 2 == 0) { x = (a + b - c) / 2; y = (b + c - a) / 2; z = (c + a - b) / 2; if (x >= 0 && y >= 0 && z >= 0) printf("%lld %lld %lld\n", x, y, z); else printf("Impossib...
4
#include <bits/stdc++.h> template <class T> int gmax(T &a, T b) { if (b > a) { a = b; return 1; } return 0; } template <class T> int gmin(T &a, T b) { if (b < a) { a = b; return 1; } return 0; } using namespace std; const int INF = 0x3f3f3f3f; string to_string(string s) { return '"' + s + '"...
4
#include <bits/stdc++.h> using namespace std; const long long infi = 1000000000000000009; int subset_fav[201009 + 10]; int dp[201009 + 10]; int puppy[201009 + 10]; int main() { int a, b, k, t, i, j; scanf("%d%d%d%d", &a, &b, &k, &t); for (i = -k; i <= k; i++) { subset_fav[i + 100309] = 1; } for (i = 2; i ...
14
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1); using namespace std; inline long long read() { long long x = 0, f = 1; char ch = getchar(); while (ch > '9' || ch < '0') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ...
1
#include <bits/stdc++.h> using namespace std; int n, h, x[2005], r[2005], l[2005]; double p, dp[2005][2005][2][2]; int main() { scanf("%d %d %lf", &n, &h, &p); for (int i = 1; i <= n; i++) { scanf("%d", &x[i]); } sort(x + 1, x + 1 + n); x[0] = -1e9, x[n + 1] = 1e9; for (int i = 1; i <= n; i++) { int...
15
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 5; long long a[maxn] = {0}; int jl[maxn] = {0}; int bj[maxn] = {0}; int main() { int n, cnt = 0; memset(bj, 999999, sizeof(bj)); scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); if (a[i] == 0) bj[++cnt] = i; } in...
4
#include <bits/stdc++.h> using namespace std; const long long N = 5e5 + 7; const long long mod = 1e7 + 7; void solve() { string s, ans; cin >> s; long long n = s.size(); ans += s[0]; ans += s[1]; for (long long i = 3; i < n; i += 2) { ans += s[i]; } cout << ans << '\n'; } int32_t main() { ios_base...
0
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; int a = k / n; if (a > 2) cout << 0 << endl; else cout << max(0, n - k % n) << endl; return 0; }
1
#include <bits/stdc++.h> using namespace std; int findMax(int price[], int diff, int l) { int minp = price[0]; int maxp = price[0]; for (int i = 0; i < l; i++) { minp = min(minp, price[i]); } for (int i = 0; i < l; i++) { maxp = max(maxp, price[i]); } int mintest = minp + diff; int maxtest = max...
1
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c, d; cin >> a >> b >> c; if (c == 0) { cout << a; return 0; } if (c == 1) { cout << b; return 0; } for (int i = 1; i < c; i++) { d = a + b; a = b; b = d; } cout << d; return 0; }
8
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 10; int ch[N][26], f[N], g[N], lst, len[N], n, cnt = 1; pair<int, int> r[N], dp[N]; char s[N], t[N]; int main() { scanf("%s%s", s + 1, t + 1); n = strlen(s + 1); s[0] = -1; len[0] = 0; len[1] = -1; f[0] = 1; for (int i = (n); i >= (1); --i)...
25
#include <bits/stdc++.h> using namespace std; int n, s, e; long long a[5001], b[5001], c[5001], d[5001], p[5001]; int nxt[5001]; long long ans; long long to(int x, int y) { if (x > y) return abs(p[x] - p[y]) + c[x] + b[y]; else return abs(p[x] - p[y]) + d[x] + a[y]; } int main() { scanf("%d%d%d", &n, &s, ...
17
#include <bits/stdc++.h> int n, a, b, c, f[2][4], cur; int main() { scanf("%d%d%d%d", &n, &a, &b, &c); memset(f[cur], 63, sizeof(f[cur])); f[cur][1] = 0; for (int i = 2; i <= n; i++) { cur ^= 1; memset(f[cur], 63, sizeof(f[cur])); f[cur][1] = std::min(f[cur ^ 1][2] + a, f[cur ^ 1][3] + b); f[cur...
1
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; int main() { long long n, m, i, j, k, x, y, t; cin >> n; vector<long long> a(n), b(n); for (i = 0; i < n; i++) cin >> a[i]; for (i = 0; i < n; i++) cin >> b[i]; for (i = 0, j = 0; i < n && j < n; i++) { if (b[i] == a[j]) j++; } c...
7
#include <bits/stdc++.h> using namespace std; int read() { int x = 0, flag = 1; char c = getchar(); while ((c > '9' || c < '0') && c != '-') c = getchar(); if (c == '-') flag = 0, c = getchar(); while (c <= '9' && c >= '0') { x = (x << 3) + (x << 1) + c - '0'; c = getchar(); } return flag ? x : -x...
22
#include <bits/stdc++.h> using namespace std; template <class T, class U> void maximize(T &x, U y) { if (x < y) x = y; } template <class T, class U> void minimize(T &x, U y) { if (x > y) x = y; } template <class T> T Abs(T x) { return (x < 0 ? -x : x); } template <class T> T safe_sqrt(T x) { return sqrt(max(x, ...
15
#include <bits/stdc++.h> using namespace std; complex<long long> ln[3][2]; long long inner(complex<long long> a, complex<long long> b) { return a.imag() * b.imag() + a.real() * b.real(); } long long outer(complex<long long> a, complex<long long> b) { return a.real() * b.imag() - a.imag() * b.real(); } int solve() {...
12
#include <bits/stdc++.h> using namespace std; int n; int t; vector<pair<int, int> > v; long long pre[60][60][60][3]; long long dp[2][2505][60]; long long dp2[2][2505][60][60]; long long ans; void preprocess() { pre[1][0][0][0] = 1; pre[0][1][0][1] = 1; pre[0][0][1][2] = 1; for (int i = 0; i <= 50; i++) for ...
13
#include <bits/stdc++.h> using namespace std; int main() { string a, b; cin >> a >> b; for (int i = 0; i < a.size(); i++) a[i] = toupper(a[i]); for (int i = 0; i < b.size(); i++) b[i] = toupper(b[i]); int r = a.compare(b); cout << r << endl; }
0
#include <bits/stdc++.h> using namespace std; long long mod = 1e9 + 7; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t; t = 1; while (t--) { long long n, i, j, k = 0, m, ans = 0; cin >> n >> m; long long a[m][n], h[m][n + 1]; memset(h, 0, sizeof(h)); for (i ...
9
#include <bits/stdc++.h> using namespace std; inline void read(int &x) { char ch; bool flag = false; for (ch = getchar(); !isdigit(ch); ch = getchar()) if (ch == '-') flag = true; for (x = 0; isdigit(ch); x = x * 10 + ch - '0', ch = getchar()) ; x = flag ? -x : x; } const int MAXN = 1e5 + 100; int a[M...
12
#include <bits/stdc++.h> using namespace std; using ll = long long; using ull = unsigned long long; using ld = long double; bool chk(vector<int> a, int k, int m) { if (a[0] + k >= m) a[0] = 0; for (int i = 1; i < a.size(); i++) { if (a[i] + k < a[i - 1]) return false; else if (a[i] < a[i - 1]) a...
9
#include <bits/stdc++.h> using namespace std; vector<long long> v; set<long long> v1; int main() { long long a, b, i, d; cin >> a >> b; d = b; long long s = a; long long e = 1; int count = 0; for (int i = 1; i <= a; i++) { if (count % 2 == 0) { v.push_back(s); s--; } else { v.pus...
4
#include <bits/stdc++.h> using namespace std; int main() { int a, b; cin >> a >> b; cout << min(a, b) << " " << abs((a - b) / 2); return 0; }
0
#include <bits/stdc++.h> #pragma GCC target("avx2") #pragma GCC optimization("O3") #pragma GCC optimization("unroll-loops") using namespace std; int mod = 1e9 + 7; int inf = 2e9; long long int linf = 1000000ll * 10000 * 10000; const int maxn = 5e5 + 20; int A[maxn]; long long int res, psum[maxn]; long long int C3(long ...
16
#include <bits/stdc++.h> using namespace std; const long double EPS = 1e-9; struct SegmTree { vector<pair<int, int> > t; int sz; SegmTree(int n = 0) { sz = 1; while (sz < n) sz *= 2; t.assign(sz * 2, make_pair(-1, 0)); } void put(int pos, int val) { int v = sz + pos; t[v] = make_pair(val, ...
17
#include <bits/stdc++.h> using namespace std; const long double EPS = 0.000001; const int MAXN = 605; const int MAXK = 16; const long long int INF = 1000000000000000LL; const int DX = 2; const int DY = 1; int h, w, k, ph, img[MAXN][MAXN]; long long int graph[MAXN][MAXN]; int parent[MAXK][1 << MAXK]; long long int dp[MA...
18
#include <bits/stdc++.h> using namespace std; const int maxint = -1u >> 2; const double eps = 1e-6; const int MAX = 200 + 1; int N; int cnt[MAX]; int mark[MAX]; int pre[MAX][MAX]; int C[MAX]; int solve(int com) { int left[MAX]; int ans = 0; memset(mark, 0, sizeof mark); for (int i = 0; i < N; ++i) { left[i]...
9
#include <bits/stdc++.h> using namespace std; long long int power(long long int a, long long int n) { long long int p = 1; while (n > 0) { if (n & 1) { p = ((p % 1000003) * (a % 1000003)) % 1000003; } n >>= 1; a = ((a % 1000003) * (a % 1000003)) % 1000003; } return p % 1000003; } const lon...
11
#include <bits/stdc++.h> using namespace std; const int UPPER_LIM = 3000000; int p, q; double A; int prime[UPPER_LIM] = {}; int num_primes[UPPER_LIM] = {}; int num_palindromes[UPPER_LIM] = {}; int digits[100]; int len; void get_digits(int x) { len = 0; while (x > 0) { digits[len] = x % 10; x /= 10; ++le...
8
#include <iostream> using namespace std; int main(){ int t; cin >> t; int n,m,i,k=0,j,P[101],l; for(i=0;i<t;i++){ for(j=0;j<101;j++){ P[j]=0; } k=0; cin >> n >> m; for(j=0;j<n;j++){ cin >> l; P[l]++; } for(j=0;j<m;j++){ cin >> l; P[l]++; } for(j=1;j<=100;j++){ if(P[j]>1){ k++...
0
#include <bits/stdc++.h> using namespace std; bool vis[501]; vector<int> adj[501]; int dfs(int i) { vis[i] = 1; int xam = 1; int val = 0; for (int j = 0; j < adj[i].size(); j++) { if (!vis[adj[i][j]]) { val = max(val, dfs(adj[i][j])); } } return max(xam, 1 + val); } bool cmp(pair<int, int> a, ...
10
#include <bits/stdc++.h> const int mx = 1e6 + 5; const int inf = 0x3f3f3f3f; using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); int n, p; scanf("%d", &n); vector<int> a, b, ca, cb; for (int i = 0; i < n; ++i) { int x; scanf("%d", &x); if (x != 0) a.push_back(x); } for (in...
5
#include <bits/stdc++.h> using namespace std; const long long _ = 35003; long long N, arr[_], l[_], r[_]; long long work(long long x) { priority_queue<long long> L; priority_queue<long long, vector<long long>, greater<long long> > R; long long val = abs(x), movel = 0, mover = 0; for (long long i = 1; i <= N + 3...
27
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1.0); int convert(string s) { reverse(s.begin(), s.end()); int r = 0; for (int i = 0; i < (int)s.size(); i++) { r += (s[i] - 48) * pow(2, i); } return r; } int main() { int n; scanf("%d", &n); int mi = 1; int r = 1; int cn = 1...
2
#include <bits/stdc++.h> using namespace std; int c; int par[200005]; int root(int u) { if (par[u] == u) return u; return par[u] = root(par[u]); } void merge(int u, int v) { int ru = root(u), rv = root(v); if (ru == rv) return; c--; if (rand() & 1) swap(ru, rv); par[ru] = rv; } int main() { ios_base::sy...
13
#include <bits/stdc++.h> int main() { int a, b, i; char ss[110]; int xx[110], yy[110], sx, sy; scanf("%d%d", &a, &b); scanf("%s", ss); xx[0] = 0; yy[0] = 0; if (a == 0 && b == 0) { printf("Yes\n"); return 0; } for (i = 0; i < strlen(ss); i++) { if (ss[i] == 'U') { xx[i + 1] = xx[i]...
9