solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> using namespace std; char ans[100][100]; int main() { ios::sync_with_stdio(false); int n, m; cin >> n >> m; if (n == 5) { cout << ">...v" << endl; cout << "v.<.." << endl; cout << "..^.." << endl; cout << ">...." << endl; cout << "..^.<" << endl; cout << "1 1" <<...
17
#include <bits/stdc++.h> using namespace std; long long a[200010]; map<long long, long long> freq; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, i; cin >> n; for ((i) = 0; (i) < (int)(n); (i)++) { cin >> a[i]; freq[i + 1 - a[i]] += a[i]; } long long res = 0; for (auto ele : freq) ...
6
#include <bits/stdc++.h> using namespace std; char s[8005]; int len, f[8005]; int dp[8005], cnt[8005][8005]; int WEI(int x) { int d = 0; while (x) d++, x /= 10; return d; } int main() { scanf("%s", s + 1); len = strlen(s + 1); for (int i = 1; i <= len; i++) { memset(f, 0, sizeof(f)); f[i] = f[i + 1]...
16
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c, d, e; cin >> a >> b >> c >> d >> e; if (a == 12) a = 0; a *= 10; if (b != 0 || c != 0) a += 1; b *= 2; if (c != 0) b += 1; c *= 2; if (d == 12) d = 0; d *= 10; if (e == 12) e = 0; e *= 10; if (d > e) { int tmp = d; ...
6
#include <bits/stdc++.h> using namespace std; long long x, y, px, py; int main() { cin >> x >> y >> px >> py; long long a = px - x + 1; long long b = py - y + 1; cout << (a - a / 2) * (b - b / 2) + (a / 2) * (b / 2); return 0; }
11
#include <bits/stdc++.h> using namespace std; const long long INF = 1000000000 + 7; const double esp = 1e-13; long long nhan(long long x, long long y, long long m) { long long ans = 0; while (y) { if (y % 2) ans = (ans + x) % m; x = x * 2 % m; y /= 2; } return ans; } long long power(long long a, lon...
13
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1.0); double fRand(double fMin, double fMax) { double f = (double)rand() / RAND_MAX; return fMin + f * (fMax - fMin); } template <class T> T min(T a, T b, T c) { return min(a, min(b, c)); } template <class T> T max(T a, T b, T c) { return max...
9
#include <bits/stdc++.h> using namespace std; long long m; long long mx(long long vote[]) { long long mm = vote[1], idx = 1; for (int i = 1; i < m; i++) { if (vote[i] > mm) { mm = max(mm, vote[i]); idx = i; } } return idx; } long long fmx(const string &s, long long vote[], pair<long long, lo...
9
#include <bits/stdc++.h> using namespace std; inline long long read() { long long sum = 0; char c = getchar(); while (!isdigit(c)) c = getchar(); while (isdigit(c)) { sum = (sum << 1) + (sum << 3) + (c ^ 48); c = getchar(); } return sum; } long long const maxn = 1e6 + 5; double const eps = 1e-6; lon...
21
#include <bits/stdc++.h> using namespace std; const int maxN = 1500 + 5; const int inf = 1000 * 1000 * 1000 * 100LL; char a[maxN][maxN]; bool mark[maxN][maxN]; pair<int, int> pos[maxN][maxN]; int dx[] = {-1, 1, 0, 0}; int dy[] = {0, 0, -1, 1}; int n, m; void dfs(int x, int y) { int xt = x % n; xt += n; xt %= n; ...
12
#include <bits/stdc++.h> using namespace std; istream &operator>>(istream &in, vector<int> &v) { for (auto &i : v) in >> i; return in; } ostream &operator<<(ostream &out, vector<int> &v) { for (auto i : v) out << i << " "; return out; } bool cmp(pair<long double, long double> a, pair<long double, long double> b...
15
#include <bits/stdc++.h> using namespace std; int n, k; int a2, a3, a4, a5; int main() { scanf("%d%d", &n, &k); int ans = 0x3f3f3f; for (int i = 0; i <= n; i++) { for (int j = 0; j <= n; j++) { for (int p = 0; p <= n; p++) { for (int q = 0; q <= n; q++) { if (i * 2 + j * 3 + p * 4 + q ...
1
#include <bits/stdc++.h> using namespace std; inline int input() { int ret = 0; bool isN = 0; char c = getchar(); while (c < '0' || c > '9') { if (c == '-') isN = 1; c = getchar(); } while (c >= '0' && c <= '9') { ret = ret * 10 + c - '0'; c = getchar(); } return isN ? -ret : ret; } inli...
9
#include <bits/stdc++.h> using namespace std; int dps[1010][1010]; int n, m, k; long long solve(int sz, int rem) { if ((sz - 1) / 2 < rem) return 0; if (rem == 0) return 1; if (dps[sz][rem] != -1) return dps[sz][rem]; long long ref = 0; for (int i = 1; i < sz - 1; i++) { long long t = sz - i - 1; t *=...
12
#include <bits/stdc++.h> using namespace std; const int maxn = 100005; int n, t, uv; int h[maxn], x[maxn], y[maxn], ans[maxn]; pair<int, pair<int, int> > st[maxn]; vector<pair<int, int> > f[maxn]; map<int, pair<int, int> > sh; map<int, pair<int, int> >::iterator sg, sg1; pair<int, int> pmc1, pmc2, t1, t2, cs; pair<int,...
18
#include <bits/stdc++.h> using namespace std; const int MAXn = 1005; int v[MAXn]; int main() { ios::sync_with_stdio(false); int n, m; cin >> n >> m; for (int i = 0; i < n; i++) cin >> v[i]; int sum = 0; for (int i = 0; i < m; i++) { int v1, v2; cin >> v1 >> v2; v1--; v2--; sum += min(v[v...
6
#include <bits/stdc++.h> using namespace std; template <int N> void gao() { union { struct { long long a[N][N]; }; struct { long long p[N * N]; }; } u; long long s = 0; for (int i = 0; i < N * N; ++i) { cin >> u.p[i]; s += u.p[i]; } sort(u.p, u.p + N * N); s /= N; do ...
11
#include <bits/stdc++.h> using namespace std; const int maxN = 1e3 + 5; const int maxS = 3; const int inf = 1e9 + 7; int dp[maxN][maxS]; char a[maxN][maxN]; int m, n, x, y; int compute() { int b, w; int sum_black[maxN], sum_white[maxN]; for (int i = 1; i <= n; ++i) { b = 0, w = 0; for (int j = 1; j <= m; ...
9
#include <bits/stdc++.h> using namespace std; int ans, n, a[20][1007], b[20][1007]; vector<int> x, y; void make_query(vector<int> l) { cout << (int)l.size() << endl; for (int i = 0; i < (int)l.size(); i++) { cout << l[i] << " "; } cout << endl; } int main() { ios_base::sync_with_stdio(0); cin >> n; in...
11
#include <bits/stdc++.h> using namespace std; int main() { int n; int num[5001] = {0}; cin >> n; for (int i = 0; i < n; i++) { int k; cin >> k; num[k] = 1; } int ans = 0; for (int i = 1; i <= n; i++) { if (!num[i]) ans++; } cout << ans << endl; return 0; }
2
#include <bits/stdc++.h> using namespace std; int a[100010]; int main() { int x, y, z; int x1, y1, z1; int a1, a2, a3, a4, a5, a6; scanf("%d%d%d", &x, &y, &z); scanf("%d%d%d", &x1, &y1, &z1); scanf("%d%d%d%d%d%d", &a1, &a2, &a3, &a4, &a5, &a6); int sum = 0; if (y < 0) sum += a1; if (y > y1) sum += a2;...
8
#include <bits/stdc++.h> using namespace std; char c[100005][20]; int main() { long long z, s1, s2, s, k, k1, k2, k3, n, i, j, a[100000], b[50], d[50]; map<long long, long long> f[32]; cin >> n >> k; for (i = 0; i < n; i++) { scanf("%s", c[i]); c[i][strlen(c[i])] = '.'; s1 = 0; s2 = 0; k3 = ...
8
#include <bits/stdc++.h> #pragma GCC optimization("unroll-loops") #pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,ssse3,sse4") using namespace std; const int BASE = 1000000, D = 10; int what[BASE + 2]; pair<int, int> nxt[BASE + 2][D]; pair<long long, int> to[D][D]; inline long long Calc(long long x) { ...
17
#include <bits/stdc++.h> using namespace std; template <typename T> string tos(T a) { stringstream ss; string ret; ss << a; ss >> ret; return ret; } void read(int &_a) { int temp = scanf("%d", &_a); } void read(int &_a, int &_b) { int temp = scanf("%d %d", &_a, &_b); } void read(int &_a, int &_b, int &_c) { ...
11
#include <bits/stdc++.h> using namespace std; template <class T> T sqr(T x) { return x * x; } long double pi = 3.1415926535897932384626433832795; long long mod = 1e9 + 7; const int N = 3e5 + 10; long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } long long bin_pow(long long n, long long p) { l...
5
#include <bits/stdc++.h> using namespace std; int n, m; char temp[11][36]; string arr[11]; int arrc[11]; int goback(string &str, int cnt, int indx = 0) { if (cnt < 0 || ((indx == n) && cnt)) return 0; if (indx == n) { for (int i = 1; i < m; i++) { int c = 0; for (int j = 0; j < n; j++) if (s...
14
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0); ; int t; cin >> t; while (t--) { long long a, b, c, d; cin >> a >> b >> c >> d; if (b >= a) { cout << b << "\n"; continue; } if (c <= d) { cout << ...
1
#include <bits/stdc++.h> using namespace std; const int N = 210; int n, m, q, t, a, b, c, g[N][N], row[N], col[N]; pair<int, pair<int, int> > grid[N][N]; pair<int, pair<int, int> > tmp[N]; int main() { scanf("%d%d%d", &n, &m, &q); for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { grid[i][j] = ...
6
#include <bits/stdc++.h> using namespace std; template <typename T> struct segtree { /* {{{ */ int N; vector<T> seg, lazy; segtree(int n = 1e5) : N(n) { seg.resize(4*N, 0); lazy.resize(4*N, 0); } T join(T x, T y) { return x + y; } void lazy_update(int x, int s, int e) { if (!lazy[x]) re...
18
#include <bits/stdc++.h> int n, m = 51, s, v; int main() { for (std::cin >> n; std::cin >> v;) v <= m ? v < m ? s = 2 : s += 2, m = v : v; std::cout << (s > n ? "Bob" : "Alice"); }
12
#include <bits/stdc++.h> const int MAXN = 200000; int S[MAXN + 5], a[MAXN + 5], p[MAXN + 5]; char s[MAXN + 5]; int main() { int n; scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); p[a[i]] = i; } scanf("%s", s); for (int i = 1; i < n; i++) S[i] = S[i - 1] + s[i - 1] - '0'; for (i...
6
#include <bits/stdc++.h> using namespace std; int calc(const vector<int>& a, int L, int R, int t0) { ; int t = t0; for (int i = L; i != R; ++i) { assert(i < R); if (t % a[i] == 0) { ++t; } ++t; }; return t - t0; } int main() { int n; scanf("%d", &n); vector<int> a(n); for (int i ...
16
#include <bits/stdc++.h> using namespace std; signed main() { long long n, m; cin >> n >> m; string str[n]; for (long long i = 0; i < n; i++) cin >> str[i]; long long r = 0, c = 0; for (long long i = 0; i < n; i++) { bool flag = true; for (long long j = 0; j < m; j++) { if (str[i][j] == 'S') {...
0
#include <bits/stdc++.h> using namespace std; const int INF = 0x3fffffff; const int SINF = 0x7fffffff; const long long LINF = 0x3fffffffffffffff; const long long SLINF = 0x7fffffffffffffff; const int MAXN = 607; const int MAXV = 2007; const int MAXE = 10007; struct eT { void setd(int _u, int _v, int _f, int _l) { ...
16
#include <bits/stdc++.h> using namespace std; const int N = 3 * 1e5 + 5; struct Edge { int u, v, id; }; vector<Edge> g[N]; int vis[N], used[N]; vector<int> matching; void solve(int u) { vis[u] = 1; for (int i = 0; i < g[u].size(); i++) { Edge e = g[u][i]; if (!used[u] && !used[e.v]) { matching.empla...
12
#include <bits/stdc++.h> using namespace std; int ToInt(string& s, int len) { int r = 0; for (int i = 0, max_ = (len); i < max_; ++i) { r *= 10; r += s[i] - '0'; } return r; } int GCD(int a, int b) { return b != 0 ? GCD(b, a % b) : a; } int LCM(int a, int b) { return a * (b / GCD(a, b)); } long long Pow...
4
#include <bits/stdc++.h> using namespace std; int n, k, a, t; int main() { cin >> k >> n; for (int i = 0; i < n; i++) { cin >> a; if (a % 2 == 0 || (k % 2 == 0 && i != n - 1)) t++; } if ((n - t) % 2 == 0) cout << "even"; else cout << "odd"; }
1
#include <bits/stdc++.h> using namespace std; const int maxn = 5e2 + 60; const double inf = 1e9; const double eps = 1e-12; char a[maxn][maxn]; int cc[maxn]; long long dp[maxn][maxn]; int main() { int n, m; long long mod; while (~scanf("%d%d%lld", &n, &m, &mod)) { memset(dp, 0, sizeof(dp)); memset(cc, 0, s...
13
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 10; int n, m, ans[maxn]; set<int> S[maxn]; vector<int> vec[maxn]; struct cmp { bool operator()(int x, int y) const { return S[x].size() == S[y].size() ? x < y : S[x].size() < S[y].size(); } }; int main() { cin >> n >> m; set<int, cmp> Q; ...
17
#include <bits/stdc++.h> using namespace std; int n, x, tot, maxn, a[101]; int main() { cin >> n >> x; for (int i = 1; i <= n; i++) { cin >> a[i]; maxn = max(maxn, a[i]); tot += a[i]; } tot += x; if (maxn * n > tot) { cout << "-1"; return 0; } for (int i = 1; i <= n; i++) printf("%.6lf...
3
#include <bits/stdc++.h> using namespace std; int N, M; int ch[400005][50], tp[50]; int add[400005]; int a[400005]; int ql, qr, q1; inline void update(int now) { int i; for (i = 0; i < 48; i++) ch[now][i] = (ch[now * 2][i] + ch[now * 2 + 1][i]) % 95542721; } inline void Make_tree(int now, int l, int r) { int ...
18
#include <bits/stdc++.h> using namespace std; int dp[250][100] = {0}; int main() { int n, m, k, d; scanf("%d%d%d", &n, &m, &k); string s; cin >> s; cin >> s; if (s == "head") d = -1; else d = 1; cin >> s; dp[0][m] = 1; for (int i = 0; i < s.size(); i++) { if (s[i] == '0') { for (in...
7
#include <bits/stdc++.h> using namespace std; using ull = unsigned long long; using ll = long long; int n, q; string s, t; bool solve() { int q = 0; for (int i = 0; i < n; ++i) { string nt = t.substr(0, i) + s[i]; for (int j = i; j < n; ++j) { if (t[j] == s[i]) { q += j - i; } else { ...
12
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; const int maxn = 1e6 + 100; long long a[10]; int main() { for (int i = 1; i <= 3; i++) { scanf("%I64d", a + i); } sort(a + 1, a + 4); long long ans = 0; if ((a[2] - a[1]) & 1) { ans = a[3]; } else { ans = a[2]; } cout << ...
13
#include <bits/stdc++.h> using namespace std; mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); mt19937 rnf(2106); const int N = 302, M = 1000000007; int c[N][N]; int f[N]; void pre() { for (int i = 0; i < N; ++i) { c[i][0] = 1; for (int j = 1; j <= i; ++j) c[i][j] = (c[i - 1][j] + c[i - 1]...
17
#include <bits/stdc++.h> using namespace std; long long n; int main() { cin >> n; int i = 0; long long a = 1, b = 1; while (b <= n) { long long tmp = a + b; a = b; b = tmp; i++; } cout << i - 1 << endl; return 0; }
8
#include <bits/stdc++.h> using namespace std; int p[100005] = {}; int n; int main() { cin >> n; if (n % 4 != 0 && n % 4 != 1) { cout << "-1" << endl; return 0; } for (int i = 1; i <= n / 2; i += 2) { p[i] = i + 1; p[i + 1] = n - i + 1; p[n - i + 1] = n - i; p[n - i] = i; } if (n % 2 ...
6
#include <bits/stdc++.h> using namespace std; pair<int, int> MP(int a, int b) { return make_pair(min(a, b), max(a, b)); } int n, m, counter; vector<int> adj[200013]; vector<vector<pair<int, int> > > bcc; vector<vector<int> > has; int num[200013]; int low[200013]; stack<pair<int, int> > s; void dfs(int x, int p, int sta...
23
#include <bits/stdc++.h> using namespace std; int main() { int t, n, p; cin >> t; while (t--) { cin >> n >> p; p += n * 2; for (int i = 1; i <= n; ++i) for (int j = i + 1; j <= n; ++j) { cout << i << " " << j << "\n"; p--; if (p == 0) goto here; } here:; } ret...
7
#include <bits/stdc++.h> using namespace std; bool cmp(string &a, string &b) { return a.length() < b.length(); } int main() { int n; scanf("%i", &n); vector<string> arr(n); for (auto &x : arr) cin >> x; sort(arr.begin(), arr.end(), cmp); for (int x = 1; x < n; x++) if (arr[x].find(arr[x - 1]) == string:...
3
#include <bits/stdc++.h> using namespace std; void solve() { int n, q; cin >> n >> q; vector<int> a(n); for (auto& x : a) cin >> x; vector<int> mx, mi; vector<int> occur(n, 2); set<int> absent; absent.insert(n + 1); vector<array<int, 4>> four(n); vector<array<int, 3>> three(n); vector<int> r4(n, n...
23
#include <bits/stdc++.h> using namespace std; int main() { int n, i, tmp; cin >> n; int a[n]; for (i = 0; i < n; i++) { cin >> a[i]; } multiset<int> b; for (i = 0; i < n; i++) { cin >> tmp; b.insert(tmp); } for (i = 0; i < n; i++) { auto it = b.lower_bound(n - a[i]); if (it == b.en...
9
#include <bits/stdc++.h> using namespace std; const int INF = 1 << 30; const int N = 1e5 + 10; char s[N]; int pre[N][26]; int main() { int m, n; scanf("%d%s", &m, s); n = strlen(s); for (int k = 0; k < 26; ++k) { int last = -1; for (int i = 0; i < n; ++i) { if (s[i] - 'a' == k) last = i; pre...
11
#include <bits/stdc++.h> using namespace std; const int N = 5e5 + 10; int n, k, a[N], b[N]; int solve(int st, int ed) { if (a[st] > a[ed]) return -1; int bk[N]; int sz = 0; for (int i = st + 1; i < ed; ++i) { if (a[i] < a[st] || a[i] > a[ed]) continue; int u = 0, v = sz; while (u != v) { int m...
14
#include <bits/stdc++.h> #pragma GCC optimize(2) using namespace std; const int mod = 1e9 + 7; const double eps = 1e-6; const int N = 2e3 + 7; unsigned long long h1[N], h2[N][N]; int n, m; char s[N][N], t[N][N]; void init() { for (int i = 1; i <= n; i++) { unsigned long long h = 0; for (int j = 1; j <= m; j++...
12
#include <bits/stdc++.h> using namespace std; int n; pair<int, int> p; vector<pair<int, int> > degres, pathes; int degree[70000], xors[70000]; vector<int> gs[70000]; bool v[70000]; priority_queue<pair<int, int>, vector<pair<int, int> >, greater<pair<int, int> > > qs; queue<int> q; void dfs(int x) { ...
7
#include <bits/stdc++.h> using namespace std; using ll = long long; char vo[] = {'a', 'e', 'i', 'o', 'u', 'y'}; inline bool invol(char x) { for (char i : vo) if (i == x) return true; return false; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n; string s; cin >>...
0
#include <bits/stdc++.h> using namespace std; const int N = 1000005; char S[N]; long long a[N], sum, now, g, w, x; int n; template <class I> inline I Min(I p, I q) { return p < q ? p : q; } int main() { scanf("%d", &n); register int i; for (i = 1; i <= n; ++i) scanf("%lld", &a[i]), a[i] <<= 1, sum += a[i]; sc...
18
#include <bits/stdc++.h> using namespace std; int dx[] = {0, 0, 1, -1, -1, -1, 1, 1}; int dy[] = {1, -1, 0, 0, -1, 1, 1, -1}; template <class T> inline T biton(T n, T pos) { return n | ((T)1 << pos); } template <class T> inline T bitoff(T n, T pos) { return n & ~((T)1 << pos); } template <class T> inline T ison(T n...
14
#include <bits/stdc++.h> using namespace std; long long exgcd(const long long &a, const long long &b, long long &x, long long &y) { if (b == 0) { x = 1; y = 0; return a; } else { long long r = exgcd(b, a % b, y, x); y -= a / b * x; return r; } } inline long long mul(long lo...
17
#include <bits/stdc++.h> using namespace std; void solve() { int n, m, k, fri = 0; cin >> n >> m >> k; vector<int> v; for (int i = 0; i < m + 1; i++) { int t; cin >> t; v.push_back(t); } for (int i = 0; i < m; i++) { int cnt = 0; for (int j = 0; j < 32; j++) { if ((v[i] & (1 << j))...
3
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 5; int p[44] = {1, 2, 1, 4, 3, 2, 1, 5, 6, 2, 1, 8, 7, 5, 9, 8, 7, 3, 4, 7, 4, 2, 1, 10, 9, 3, 6, 11, 12}; int n; int mark[N]; int main() { cin >> n; int ans = 1; int jvb = 0; if (n > N - 5) { jvb = n - N + 5; } for (int i ...
15
#include <bits/stdc++.h> using namespace std; template <class T> inline T bigmod(T p, T e, T M) { long long ret = 1; for (; e > 0; e >>= 1) { if (e & 1) ret = (ret * p) % M; p = (p * p) % M; } return (T)ret; } template <class T> inline T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); } ...
18
#include <bits/stdc++.h> using namespace std; const int MAXN = 1000000; string s; vector<string> res; int main() { cin >> s; res.push_back(""); for (int i = 0; i < s.length(); ++i) { if (s[i] == '.') res.push_back(""); else res.back() += s[i]; } if (!res[0].length() || res[0].length() > 8 ...
6
#include <bits/stdc++.h> using namespace std; long long ver(long long **a, long long size) { long long k = 0, sum = 0, m = (size - 1) / 2; for (long long x = 0; x < size; x++) { sum += a[k++][m]; } return sum; } long long hor(long long **a, long long size) { long long k = 0, sum = 0, m = (size - 1) / 2; ...
0
#include <bits/stdc++.h> using namespace std; const int MAXN = 500 + 10; const int INF = 0x3f3f3f3f; char pic[MAXN][MAXN]; vector<int> v[MAXN]; int t[MAXN][MAXN]; int dp[MAXN][MAXN]; int main() { int n, m, k; scanf("%d%d%d", &n, &m, &k); for (int i = 1; i <= n; ++i) { scanf("%s", pic[i]); } for (int i = 1...
10
#include <bits/stdc++.h> using namespace std; int main() { long long i, j, k; long long N, L, W; cin >> N >> L >> W; deque<long long> P1, P2; for (i = 0; i < N; i++) { long long a, b; cin >> a >> b; if (b == 1) { P1.push_back(a); } else { P2.push_back(a); } } sort(P1.begin(...
17
#include <bits/stdc++.h> using namespace std; struct item; string to_string(item a); const long long inf = 1e9 + 5; long double e = 0.000000001; struct item { long long mn = 0, delta = 0, l = 0, r = 0, end_speed = 0, start = 0; bool active = false, leaf = false; void init(pair<long long, long long>& pr) { l =...
20
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; long long dp[1001][2001]; long long get(int n, int k) { if (n <= 0) return 0; if (k <= 0) return 1; if (dp[n][k] == -1) { dp[n][k] = (get(n - 1, k) + get(n - 1, k - 1)) % MOD; } return dp[n][k]; } int main() { ios_base::sync_wi...
12
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin >> n; long long sum = 1; for (int i = 2; i <= n; ++i) { sum *= i; sum %= 1000000007; } long long minus = 1; for (int i = 1; i < n; ++i) { minus *= 2; minus %= 1000000007; } if (minus < sum) cout << ((sum - ...
7
#include <bits/stdc++.h> using namespace std; void program() { int n, temp; cin >> n; vector<int> a; for (int i = 0; i < n; i++) { cin >> temp; a.push_back(temp); } sort(a.begin(), a.end()); int dif1, flag, minimum = a[1] - a[0]; for (int i = 1; i < n - 1; i++) { dif1 = a[i + 1] - a[i]; ...
0
#include <bits/stdc++.h> using namespace std; int n, k, m; vector<int> a; int main() { cin >> n; for (int i = max(0, n - 100); i <= n; i++) { int y = i, s = 0; while (y > 0) { s += y % 10; y /= 10; } if (s + i == n) a.push_back(i); } cout << (int)a.size() << '\n'; for (auto i : a) ...
4
#include <bits/stdc++.h> using namespace std; int main() { string s, t; cin >> s >> t; int pos = 0; for (int i = 0; i < t.length(); ++i) if (s[pos] == t[i]) ++pos; cout << pos + 1; }
0
#include <bits/stdc++.h> using namespace std; string st; long long n, res, ar1[28], ar2[28][28]; int main() { cin >> st; n = st.size(); st = " " + st; for (long long i = 1; i <= n; ++i) { long long c = st[i] - 96; for (long long j = 1; j <= 26; ++j) { ar2[j][c] += ar1[j]; } ar1[c]++; } ...
7
#include <bits/stdc++.h> using namespace std; int main() { long long n, i, j, *a, *b, z, c, d, v, u; a = (long long*)malloc(sizeof(long long) * 1000000); b = (long long*)malloc(sizeof(long long) * 1000000); cin >> n; for (i = 0; i < n; i++) { cin >> a[i]; } for (i = 0; i < n; i++) { cin >> b[i]; ...
1
#include <bits/stdc++.h> using namespace std; const int N = 523456; const int inf = (int)1e9 + 7; const long double eps = 1e9; long double dist(long double x1, long double asjkdldkljkjs, long double x2, long double y2, long double x3, long double y3) { long double px = x2 - x1; long double py = y2 ...
10
#include <bits/stdc++.h> using namespace std; int main() { int n, p[100]; int sum, m = 0; cin >> n; for (int i = 0; i < n; i++) cin >> p[i]; sum = 0; for (int i = 0; i < n; i++) sum += p[i]; for (int j = 1; j <= 5; j++) if (((sum + j) % (n + 1)) != 1) m++; cout << m << endl; return 0; }
2
#include <bits/stdc++.h> using namespace std; int32_t mod = 1e9 + 7; void solveCase() { string s, t; cin >> s >> t; if (t.length() > s.length()) { cout << "NO\n"; return; } if (t.length() == s.length()) { cout << (t == s ? "YES" : "NO") << '\n'; return; } long long n = s.length(), m = t.le...
7
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; cin >> n; long long sum = 0; int maxv = 0; for (int i = 0; i < (int)(n); i++) { int x; cin >> x; sum += x; maxv = max(maxv, x); } sum -= maxv; cout << maxv - sum + 1 << endl; ...
3
#include <bits/stdc++.h> using namespace std; stack<char> k; int main() { ios_base::sync_with_stdio(0); cin.tie(0); string s; cin >> s; long long int cnt = 0; for (long long int i = 0; i < s.length(); i++) { if (k.empty() || s[i] == '(' || s[i] == '[' || s[i] == '<' || s[i] == '{') k.push(s[i]); ...
6
#include <bits/stdc++.h> using namespace std; const int maxn = 3000000; int q[maxn], used1[maxn], used2[maxn], n, m, first[maxn]; vector<int> g[maxn], gi[maxn]; void Bfs1() { int head = 0, tail = 0; for (int i = 1; i <= n; ++i) if (first[i] == 1) { q[tail++] = i; used1[i] = true; } while (head...
9
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; const double PI = acos(-1); const long long INF = 2e18 + 1; const int inf = 1e9 + 5; const double eps = 1e-10; const int maxn = 1e5 + 5; long long n, a, r, m, h[maxn]; long long getmid(long long need) { long long x = 0, y = 0, ans = 0; for...
13
#include <bits/stdc++.h> using namespace std; long long gcdExtended(long long a, long long b, long long *x, long long *y) { if (a == 0) { *x = 0; *y = 1; return b; } long long x1, y1; long long gcd = gcdExtended(b % a, a, &x1, &y1); *x = y1 - (b / a) * x1; *y = x1; return gcd; } void diophanti...
8
#include <bits/stdc++.h> using namespace std; int main() { set<char> s; string a; getline(cin, a); for (int i = 0; i < a.size(); i++) { if (a[i] >= 'a' && a[i] <= 'z') { s.insert(a[i]); } } cout << s.size() << endl; }
0
#include <bits/stdc++.h> #pragma GCC optimize("O3,Ofast,no-stack-protector,unroll-loops,fast-math") using namespace std; int n; int kek[200001]; pair<int, int> get(int l, int r) { cout << "? " << l << ' ' << r << endl; int x, f; cin >> x >> f; return {x, f}; } void put(int k) { pair<int, int> pr = get(k, k); ...
19
#include <bits/stdc++.h> using namespace std; long long n; char ar[200][200], ans[200][200]; bool ch[200][200]; bool check_o(long long x, long long y, long long dx, long long dy) { return (!((x + dx >= 0) && (x + dx < n) && (y + dy < n) && (y + dy >= 0)) || ((ar[x + dx][y + dy] == 'x') || (ar[x + dx][y + dy...
10
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int t; cin >> t; while (t--) { int n; cin >> n; string str1, str2; cin >> str1 >> str2; vector<int> ans; for (int i = n - 1; i >= 1; i--) { if (str1[i] == str2[i]) conti...
5
#include <bits/stdc++.h> using namespace std; template <class T> using pq = priority_queue<T>; template <class T> using pqg = priority_queue<T, vector<T>, greater<T>>; int mod(long long int a, long long int b) { return ((a % b) + b) % b; } long long int MODnumber(long long int a) { return (a % (long long int)10000000...
9
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1.0); int n; long long s[30][100010], a[100005]; long long idx[30][100010]; int c[10][20]; int i, j, z, m, k; int lowbit(int x) { return x & (-x); } void insert(int l, long long w, int x) { for (int i = l; i <= n; i += lowbit(i)) idx[x][i] += w; } ...
13
#include <bits/stdc++.h> using namespace std; const int mod = 998244353; const int N = 100005; long long dp[N]; vector<pair<long long, long long> > member[N]; int add(int a, int b) { return ((a += b) >= mod) ? a - mod : a; } void adding(int &a, int b) { if ((a += b) >= mod) a -= mod; } long long pw(long long a, long ...
20
#include <bits/stdc++.h> using namespace std; long long int arr1[26], arr2[26][26]; vector<long long int> ans; map<char, long long int> change; map<string, long long int> mp; int main() { long long int T, n, i; long long int a, b = 0, c, d = 0, e, f, g, h, t; cin >> n >> t >> c; for (i = 1; i <= n; i++) { c...
3
#include <bits/stdc++.h> using namespace std; bool prime(int64_t n) { for (int64_t i = 2; i <= sqrt(n); i++) { if (n % i == 0) { return 0; } } return 1; } void normal(int64_t &a) { a = a % 1000000007; (a < 0) && (a = a + 1000000007); } int64_t Add(int64_t a, int64_t b) { a = a % 1000000007, b ...
0
#include<bits/stdc++.h> using namespace std; const int N = 1e2 + 10; int n; int a[N], b[N], dp[2][N][N * N * 2]; int main() { cin >> n; int suma = 0, sumb = 0; for(int i = 1; i <= n; i++) cin >> a[i] >> b[i]; for(int i = 1; i <= n; i++) suma += a[i], sumb += b[i]; for(int i = 0; i <= n; i++) { ...
12
#include <bits/stdc++.h> using namespace std; const int MOD = 998244353; const double PI = 3.141592653589793; const long long INF = 1e16 + 7; const int nax = 200005; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int tc = 1; cin >> tc; while (tc--) { int n; cin >> n; int a[n + 10]; ...
0
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; float sum = 0; for (int i = 1; i <= n; i++) { sum += (float(1) / float(i)); } printf("%.12f", sum); return 0; }
2
#include <bits/stdc++.h> #include<cmath> #include<set> #include<vector> #include<iterator> using namespace std; #define test() int t;cin>>t;while(t--) #define MOD 1000000007 #define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); #define ff first #define ss second #define ll ...
0
#include <bits/stdc++.h> using namespace std; const long long inf = 1e9; const long long INF = 2e18; const long long M = 1e9 + 7; int b[3][10004], a[3][10004]; long long last[20], now[20]; int n; long long cnt() { for (int i = 0; i < 20; ++i) last[i] = now[i] = 0; last[0] = 1; for (int j = 0; j < n; ++j) { fo...
13
#include <bits/stdc++.h> using namespace std; const double MAGIC = 1; int main() { int n; cin >> n; vector<int> w(n); for (int i = 0; i < n; i++) cin >> w[i]; int m; cin >> m; vector<pair<int, int> > qs(m), ord; for (int i = 0; i < m; i++) { cin >> qs[i].second >> qs[i].first; qs[i].second--; ...
13
#include <bits/stdc++.h> char str[1000010]; int cnt[20]; int out[] = {1869, 6198, 1896, 1689, 1986, 1968, 1698, 1869, 6198, 1896}; int main() { int i, j; scanf("%s", str); for (i = 0; str[i]; i++) { cnt[str[i] - '0']++; } cnt[1]--; cnt[8]--; cnt[6]--; cnt[9]--; j = 0; for (i = 1; i <= 9; i++) { ...
8
#include <bits/stdc++.h> using namespace std; int i, n, T, m, x; double c, mn[500000], sas[500000], s[500000], a[500000], mean; double module(double x) { if (x < 0) return -x; else return x; } int main() { cin >> n >> T >> c; for (i = 1; i <= n; i++) { cin >> a[i]; mean = (mean + a[i] / (double)...
7