solution
stringlengths
52
181k
difficulty
int64
0
6
#include <bits/stdc++.h> #define rep(i, a, n) for(int i = a; i < n; i++) #define int long long using namespace std; typedef pair<int, int> P; const int mod = 1000000007; const int INF = 1e18; int dp[210][100010]; signed main(){ cin.tie(nullptr); ios::sync_with_stdio(false); int n, x; cin >> n >> x; ...
0
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 5, Inf = 1e9 + 1312; int idx, cur, tree[25 * N], le_[25 * N], ri_[25 * N], node[N], n, m, k, i, q; set<int> S; map<int, int> ind; pair<pair<int, int>, int> p[N]; vector<pair<int, int> > st[N]; vector<int> x; void build(int u, int l, int r) { if (l == r...
6
#include <bits/stdc++.h> int d[10240]; int main() { int n, m, k; scanf("%d%d%d", &n, &m, &k); for (int i = 0; i < n; i++) scanf("%d", &d[i]); long long ans; if (n & 1) { int need = n / 2 + 1; if (m < need) ans = 0; else { ans = d[0]; for (int i = 0; i < n; i++) if ((i & 1...
1
#include <bits/stdc++.h> using namespace std; const int MAXN = 200010; int a[MAXN], n, Max = -0x3F3F3F3F, maxpos; int main() { cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; if (a[i] > Max) { Max = a[i]; maxpos = i; } } for (int i = 2; i <= maxpos; i++) if (a[i] < a[i - 1]) { ...
2
#include <bits/stdc++.h> using namespace std; struct Node { Node *next[26]; Node() { memset(next, 0, sizeof(next)); } }; Node *root = new Node(); vector<bool> v(26); string s; int ans, k; void insert(int l, int r) { Node *cur = root; for (int i = l; i <= r; ++i) { int to = s[i] - 'a'; if (!cur->next[to]...
4
#include <bits/stdc++.h> using namespace std; int main(void) { int n; while (scanf("%d", &n) == 1) { vector<long long> a; for (int i = 0; i < n; ++i) { long long tmp; scanf("%lld", &tmp); a.push_back(-tmp); } if (n == 1) { printf("0\n"); continue; } make_heap(a....
4
#include <bits/stdc++.h> using namespace std; int findMax(int a, int b, int c) { if ((a == 1 && b == 1 && c == 1) || (a == 1 && c == 1)) { return (a + b + c); } else { int x = a * b * c; int x1 = (a + b) * c; int x2 = a * (b + c); int x3 = a + (b * c); return max(max(x, x3), max(x1, x2)); ...
1
#include <bits/stdc++.h> using namespace std; const int mn = 101000, inf = 1 << 30; int n, m, L, R, len, ans = 0, st, ed, mi; int sa[mn], f[mn], s[mn], px[mn], py[mn], q[mn]; int tt, po[mn], w[mn], g[mn]; bool del[mn]; struct list { int la[mn], next[mn * 2], y[mn * 2], v[mn * 2], tt; void add(int i, int j, int k) {...
5
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const long long mod = 1e9 + 7; const int N = 100005; int main() { int _; cin >> _; while (_--) { int n; cin >> n; vector<int> a; for (int i = 1; i <= n;) { a.push_back(n / i); i = n / (n / i) + 1; } rever...
3
#include <bits/stdc++.h> int main() { int i, j, k, l, n, m; long long int a; scanf("%lld", &a); scanf("%d", &n); for (i = 1; i <= n; i++) { if (a % 10 != 0) { a = a - 1; } else { a = a / 10; } } printf("%lld\n", a); return 0; }
1
#include <bits/stdc++.h> using namespace std; int main() { long long int n, c1 = 0, c2 = 0; cin >> n; string a; cin >> a; for (long long int i = 0; i < n; i++) { if (a[i] == '1') c1++; else c2++; } if (c1 != c2) { cout << "1\n" << a; } else { cout << "2\n" << a[0] << " "; ...
1
#include <bits/stdc++.h> using namespace std; int main() { string str; cin >> str; char ch = str[0]; ch = toupper(ch); cout << ch << str.substr(1, str.size()); return 0; }
1
#include<bits/stdc++.h> #define fo(i,a,b) for(i=a;i<=b;i++) #define fd(i,a,b) for(i=a;i>=b;i--) #define min(a,b) (a<b?a:b) #define max(a,b) (a>b?a:b) typedef long long ll; using namespace std; int d,k,L,i,j,ten[15],a[25]; int s[25],mx,f[25];ll ans,an; void dfs(int x,ll now){ if (L-x>=k-1&&abs(now)>=10) return; if (n...
0
#include <bits/stdc++.h> using namespace std; int a[26]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n, check = 1; string s; cin >> n >> s; for (int i = 0; i < n; i++) { check = max(check, ++a[s[i] - 'a']); } check > 1 or n == 1 ? cout << "YES" : cout << "NO"; cout << endl; re...
1
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 5; vector<int> L, R; void solve() { int n; scanf("%d", &n); for (int i = 1; i <= n; i++) { int l, r; scanf("%d", &l); scanf("%d", &r); L.push_back(l); R.push_back(r); } sort((L).begin(), (L).end()); sort((R).begin(), (R...
4
#include <bits/stdc++.h> using namespace std; int main() { cin.tie(NULL); cout.tie(NULL); ios_base::sync_with_stdio(0); long long n, m; cin >> n >> m; vector<long long> a(n); long long max = 0; for (int i = 0; i < n; i++) { cin >> a[i]; if (a[i] > max) { max = a[i]; } } max += m; ...
1
#include <bits/stdc++.h> using namespace std; template <class T> void read(T &x) { int f = 0; x = 0; char ch = getchar(); for (; !isdigit(ch); ch = getchar()) f |= (ch == '-'); for (; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0'; if (f) x = -x; } const int next_x[8] = {0, 1, -1, 0, 1, 1, -1, -1}; cons...
6
#include <bits/stdc++.h> using namespace std; int ada[105]; int main() { int n, a, b; cin >> n >> a >> b; memset(ada, -1, sizeof ada); for (int i = 0; i < a; i++) { int x; cin >> x; ada[x] = 1; } for (int i = 0; i < b; i++) { int x; cin >> x; } for (int i = 1; i <= n; i++) { if (...
1
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c; scanf("%d%d%d", &a, &b, &c); printf("%d\n", 3 * min(min(a + 1, b), c - 1)); return 0; }
1
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; const int mod = 1e9 + 7; const int maxn = 205; int n, ans, T; char a[maxn][maxn]; int main() { cin >> T; while (T--) { cin >> n; for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) cin >> a[i][j]; } int p1 = a[1]...
2
#include <bits/stdc++.h> using namespace std; const int maxn = 400001; struct segtree { int kk[maxn << 2], lz[maxn << 2]; void pd(int i, int k) { kk[i] += k, lz[i] += k; } void pdd(int i) { if (lz[i]) pd(i << 1, lz[i]), pd(i << 1 | 1, lz[i]), lz[i] = 0; } void add(int i, int l, int r, int x, int y, int k)...
6
#include <bits/stdc++.h> using namespace std; int n; struct OTree { int ccnt; int v1, v2, v3; int subSize; int heavy; } oTree[1000009]; int queries[500003]; vector<int> decomposed[1000113]; int decomposeStart[1000013]; int decomposeParent[1000013]; int decomposeDcmpParent[1000013]; int indexToDcmp[1000013]; int...
6
#include <bits/stdc++.h> using namespace std; using pii = pair<int,int>; using ll = long long; #define rep(i, j) for(int i=0; i < (int)(j); i++) #define repeat(i, j, k) for(int i = (j); i < (int)(k); i++) #define all(v) v.begin(),v.end() #define debug(x) cerr << #x << " : " << x << endl template<class T> bool set_min...
0
#include <bits/stdc++.h> using namespace std; int n, m, i, j, c; double tt; int dp[10000]; int main() { cin >> n >> m; dp[0] = 1000000000; for (i = 0; i < n; i++) { cin >> c >> tt; for (j = 1; j <= m; j++) { if (j != c) dp[j] = dp[j] + 1; } for (j = 1; j <= m; j++) dp[j] = min(dp[j], dp[j - ...
4
#include <bits/stdc++.h> using namespace std; long long int C2(long long int n) { long long int ans = max(((n * (n - 1)) / 2), (long long int)0); return ans; } long long int sq(long long int n) { return n * n; } long long int gcd(long long int a, long long int b) { if (a < b) { swap(a, b); } if (b == 0) {...
1
#include <bits/stdc++.h> using namespace std; const int maxn = 110; int n; char str[maxn]; bool check(char c) { return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c > 47 && c < 58) || c == '_'; } int count(char c) { int res = 0; for (int i = 1; i <= n; i++) { res += str[i] == c; } return...
1
#include <bits/stdc++.h> using namespace std; const int maxn = 5e6 + 5; int p[maxn], vis[maxn], pn; void init() { for (int i = 2; i < maxn; ++i) { if (!vis[i]) p[pn++] = i; for (int j = 0; j < pn && i * p[j] < maxn; j++) vis[i * p[j]] = 1; } } map<int, int> aaa; int solve() { init(); int n, x, t, cnt(0)...
5
#include <bits/stdc++.h> using namespace std; int n, m; vector<long long> arr; vector<int> parents; long long minCost = LLONG_MAX; long long costOutput; struct edge { int u, v; long long cost; edge(){}; edge(int u_, int v_, long long cost_) { u = u_; v = v_; cost = cost_; } }; struct less_than_key...
6
#include <bits/stdc++.h> using namespace std; double dp[1 << 18]; int main() { int n; cin >> n; int a[n]; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n; i++) { --a[i]; } int ans = 0; for (int mx = 1; mx <= n / 8 + 1; mx++) { int dp[n + 1][1 << 8]; for (int i = 0; i <= n; i++...
5
#include <bits/stdc++.h> using namespace std; int32_t main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; long long t; cin >> t; while (t--) { long long n, r; cin >> n >> r; if (r >= n) { long long ans = (1 + n - 1) * (n - 1) / 2 + 1; cout << ans << "\n"; } else { ...
2
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; bool impr = false; bool taken[n + 1]; for (int i = 0; i <= n; i++) { taken[i] = false; } int notTaken = -1; for (int i = 0; i < n; i++) { int k; cin >> k; ...
2
#include <bits/stdc++.h> using namespace std; int main() { vector<int> a(3); for (int i = 0; i < 3; i++) cin >> a[i]; int cnt_two = 0, cnt_one = 0, cnt_three = 0, cnt_four = 0; for (int i = 0; i < 3; i++) { if (a[i] == 1) cnt_one++; if (a[i] == 2) cnt_two++; if (a[i] == 3) cnt_three++; if (a[i] ...
3
#include <bits/stdc++.h> using namespace std; const int max_n = 201111, inf = 1000111222; int add = 100011; struct segment_tree { char tr[4 * max_n]; void build(int cur, int l, int r, int stplus) { if (l == r) { if (l < stplus) { tr[cur] = '-'; } else { tr[cur] = '+'; } r...
5
#include <bits/stdc++.h> using namespace std; template <typename T1, typename T2> void chkmin(T1 &x, T2 y) { if (x > y) x = y; } template <typename T1, typename T2> void chkmax(T1 &x, T2 y) { if (x < y) x = y; } template <typename T> void read(T &x) { x = 0; char c = getchar(); T neg = 1; while (!isdigit(c)...
4
#include <bits/stdc++.h> using namespace std; const long long mx = 300009; long long a[mx], b[mx]; int n; string str; int main() { cin >> n >> str; int ans = 0, ans1 = 0; for (int i = 0; i < n; i++) { int d = str[i] - '0'; ans += (d != (i & 1)); ans1 += (d == (i & 1)); } cout << min(ans, ans1) << ...
4
#include <iostream> #include <string> #include <vector> #include <algorithm> #define llint long long using namespace std; llint readE(); string s, t; vector<char> vec; llint pos; bool err; llint readN() { if(t[pos] == '0'){ pos++; return 0; } if(t[pos] != '1'){ err = true; return 0; } llint ret = 0; ...
0
#include <bits/stdc++.h> using namespace std; const int MOD = 998244353; int n, a[2005][2005]; struct BIT { int tre[2005]; void push(int id) { while (id <= n) { tre[id]++; id += id & -id; } } void pop(int id) { while (id <= n) { tre[id]--; id += id & -id; } } int quer...
5
#include <bits/stdc++.h> using namespace std; const double dancila = 3.14159265359; int main() { ios_base::sync_with_stdio(); cin.tie(0); int t; cin >> t; while (t--) { int n, m; cin >> n >> m; int prod = n * m; int k = 1; while (k * 2 < prod) k++; cout << k << "\n"; } }
1
#include <bits/stdc++.h> using namespace std; long a, b, c, d, ct, i, j, ans, gg = -1; ; string s; int main() { cin >> s; if (s.size() == 1) { cout << 0; return 0; } reverse(s.begin(), s.end()); for (i = 0; i < s.length() - 1; i++) { ct = 0; if (s[i] == '0') { ans++; continue; ...
2
#include <bits/stdc++.h> using namespace std; int main(int argc, char const *argv[]) { int len; string str; cin >> str; len = str.size(); cout << ((len + 1) * 26) - len << endl; return 0; }
1
#include <bits/stdc++.h> using namespace std; int n, m, k, hed[200050], cnt; struct EG { int to, id, nxt; } e[2 * 200050]; void ae(int f, int t, int v) { e[++cnt].to = t; e[cnt].id = v; e[cnt].nxt = hed[f]; hed[f] = cnt; } int dep[200050]; bool vis[200050]; void dij() { memset(dep, 0x3f, sizeof(dep)); dep...
6
#include <bits/stdc++.h> using namespace std; const int MAXN = 5010; struct func { string isim; string type[6]; int cnt; } ar[MAXN], tmp; map<string, string> TYPE; int main() { int n; char ch; scanf(" %d%c", &n, &ch); string str; int cnt = 0; for (int i = 1; i <= n; i++) { cnt = 0; str.clear()...
4
#include<bits/stdc++.h> #define fi first #define se second #define pb push_back #define ll long long #define pii pair<int,int> const int N=1e6+10; const int mod=998244353; using namespace std; void solve(){ int n, m; scanf("%d %d", &n, &m); vector<vector<int> > mp(n+1, vector<int>(n+1, (int)(1e9))); vecto...
4
#include <bits/stdc++.h> using namespace std; struct segment_tree{ vector<long long> st, plusz; int maxn; void init(int n){ maxn = n; st.resize(4*maxn, 0); plusz.resize(4*maxn, 0); return; } void pont_update(int x, int l, int r){ st[x] = 0; if(l+1 ...
6
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int N, M; cin >> N >> M; vector<int> k(N); for (int &x : k) cin >> x; int sum_k = accumulate(k.begin(), k.end(), 0); vector<vector<int>> sales(N); while (M--) { int d...
6
#include <bits/stdc++.h> using namespace std; int n, i, a[22], j, x[22][2], k = 0, s[11], b[5][5], s0 = 0; int rec(int x0, int y0) { if (!((x0 == n - 1) && (y0 == n))) { if (y0 == n) { y0 = x0; x0++; } if (x0 == n) { y0++; x0 = y0; } for (int i = 0; i < k; i++) { if (...
4
#include <bits/stdc++.h> using namespace std; string s[105]; vector<long long> v; int main() { long long n, i, t, mn, y, z, x, num, ans; cin >> n >> t; mn = 10000000; for (i = 1; i <= n; i++) { cin >> x >> y; num = t; if (x <= num) { num = num - x; } else { num = 0; } z = cei...
1
#include <bits/stdc++.h> using namespace std; int main() { int n, i, f1 = 0, x = 0, y = 0; cin >> n; long long a[n], min1 = 1000000001, min2 = min1; for (i = 0; i < n; i++) { cin >> a[i]; if (a[i] < min1) { min1 = a[i]; } } for (i = 0; i < n; i++) { if (a[i] == min1 && f1 == 0) { ...
1
#include <bits/stdc++.h> using namespace std; const long long M = 1e9 + 7; const long long mod = 998244353; mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); long long binpow(long long a, long long b) { long long res = 1; while (b > 0) { if (b & 1) res = res * a % M; a = a * a % M; ...
5
#include <bits/stdc++.h> using namespace std; class Debugger { public: Debugger(const std::string& _separator = ", ") : first(true), separator(_separator) {} template <typename ObjectType> Debugger& operator,(const ObjectType& v) { if (!first) cerr << separator; cerr << v; first = false; re...
6
#include <bits/stdc++.h> using namespace std; const int LEN = 1010; const int MOD = 1000000007; const int INF = 0x3f3f3f3f; int a[LEN], n; long long dp[LEN][LEN]; long long dfs(int l, int r) { if (dp[l][r] != -1) return dp[l][r]; if (l >= r) return dp[l][r] = 1; long long ret = 0; for (int i = l + 1; i <= r + 1...
6
#include <bits/stdc++.h> using namespace std; const long long N = 4e5 + 50, mod = 1e9 + 7; int n, m, color[N], in[N], out[N], Node[N], id; long long tree[4 * N], lazy[4 * N]; vector<int> g[N]; void dfs(int node, int par) { in[node] = ++id; Node[id] = node; for (auto i : g[node]) { if (i == par) continue; ...
5
#include <bits/stdc++.h> using namespace std; const long long inf = 9223372036854775806; const long long mod = 1e9 + 7; const double pi = 3.1415926; const long long N = 1e5 + 10; const long long small = 251; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long n, m; cin >> n >> m; l...
4
#include <bits/stdc++.h> using namespace std; const int INF = (int)1e9; const int N = 201; const int M = N * 30; int n, k, f1[N], f2[N]; long long a[N]; int dp[N][M], tmp[N][M]; void maximize(int &x, const int &y) { x = max(x, y); } void solve() { cin >> n >> k; for (int i = 1; i <= n; ++i) { cin >> a[i]; w...
4
#include <bits/stdc++.h> int main() { int n, a = 0, d = 0, i; scanf("%d", &n); getchar(); char s[n]; for (i = 0; i < n; i++) { scanf("%c", &s[i]); if (s[i] == 'A') { a++; } else if (s[i] == 'D') { d++; } } if (a == d) { printf("Friendship\n"); } else if (a > d) { prin...
1
#include <bits/stdc++.h> using namespace std; vector<long long> vl, v1, v2; long long N, M, K, Q, T; int main() { ios_base::sync_with_stdio(false); cin >> N; long long mod1 = 0; long long mod1neg = 0; for (long long i = 0; i < N; i++) { long long a; cin >> a; if (a % 2 == 0) { cout << a / 2 ...
1
#include <bits/stdc++.h> using namespace std; const int Maxn = 100005; const int Maxm = 524288; int n; int a[Maxn]; int lst[Maxn]; int prv[Maxn]; vector<int> st[Maxm]; void Create(int v, int l, int r) { if (l == r) st[v].push_back(prv[l]); else { int m = l + r >> 1; int lc = 2 * v, rc = 2 * v + 1; C...
3
#include <bits/stdc++.h> using namespace std; const int mo = 1073741823; int A, B, C, cnt; int mu[2005], prime[2005], gd[2005][2005]; bool vis[2005]; int gcd(int x, int y) { return !y ? x : gcd(y, x % y); } void pre() { mu[1] = 1; for (int i = 2; i <= 2000; ++i) { if (!vis[i]) { mu[i] = -1; prime[++...
5
#include <bits/stdc++.h> using namespace std; const int maxd = 10, maxl = 18, maxs = 81, BLEN = 5, BMSK = 31, maxv = 32175, maxv2 = 191791; int htot, cnt[maxv], inc[maxv][maxd + 1], sub[maxv][maxd + 1], ptot, pos[maxl + 1][maxv]; map<long long, int> Hash; long long bit[maxd + 1], c[2][maxl + 1]; long long...
6
#include <bits/stdc++.h> using namespace std; const int inf = 0x7fffffff; const double eps = 1e-10; const double pi = acos(-1.0); inline int read() { int x = 0, f = 1; char ch; ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = 0; ch = getchar(); } while (ch >= '0' && ch <= '9') { ...
2
#include <bits/stdc++.h> const long long int MOD = 1e9 + 7; const long long int INF = 1011111111; const long long int LLINF = 1000111000111000111LL; const long double EPS = 1e-10; const long double PI = 3.14159265358979323; using namespace std; long long int power(int x, int n) { if (n == 0) return 1; else if (...
3
#include <bits/stdc++.h> using namespace std; int main() { long long n, m, a[1000] = {0}, x, maxx = -1, res = 0; cin >> n >> m; if (m - 1 >= n - m) { x = m - 1; } else x = m + 1; if (x == 0) x = 1; cout << x << endl; return 0; }
2
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 7; map<pair<int, int>, int> mp; set<int> adj[N]; int par[N], cld_cnt[N], vis[N], dep[N]; vector<tuple<int, int, int> > ans; set<pair<int, int> > st; void dfs(int u, int p) { par[u] = p; vis[u] = true; dep[u] = dep[p] + 1; vector<int> a; for (in...
4
#include <bits/stdc++.h> using namespace std; const int OO = (int)2e9; const double eps = 1e-9; int daysInMonths[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; int di[] = {-1, 0, 1, 0}; int dj[] = {0, 1, 0, -1}; int main() { std::ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n, ...
2
#include <bits/stdc++.h> using namespace std; inline int read() { int 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 * 10 + ch - '0'; ch = getchar(); } return x * f; } struct edge { int nx,...
5
#include <bits/stdc++.h> using namespace std; long long all, ans, i, j, base; int n; bool flag; int a[100]; void solve() { base = 1; for (i = 1; i <= n; i++) base *= 3; base--; while (base) { ans = 0, j = 0; for (i = base; i != 0; i /= 3) { if (i % 3 == 2) ans += a[j]; if (i % 3 == 1) ans -=...
4
#include <bits/stdc++.h> using namespace std; int main(){ int x; cin >> x; int ans = 1; for(int i = 2; i <= sqrt(x); i++){ int a = i; while(a <= x) a *= i; ans = max(ans, a/i); } cout << ans << endl; }
0
#include <bits/stdc++.h> using namespace std; const int MAX_N = 1e5 + 5; struct node { int val, times; }; deque<node> q; int n; long long k; int a[MAX_N]; int main() { scanf("%d", &n), scanf("%lld", &k); for (register int i = 1; i <= n; i++) scanf("%d", &a[i]); sort(a + 1, a + 1 + n); int cnt = 0; for (regi...
5
#include <bits/stdc++.h> using namespace std; int n, A[100005]; int xyx, q[100005], c[100005], p[100005]; vector<int> v[100005]; int pos; void get_v(int pos) { v[pos].clear(); if (pos == 1) return; if (A[pos] == A[pos - 1]) v[pos].push_back(2); for (auto x : v[pos - 1]) if (A[pos] == A[pos - x - 1]) v[pos]....
5
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const long long LINF = 0x3f3f3f3f3f3f3f3f; const int MAX = 1e5 + 10; const int mod = 1e9 + 7; mt19937 rng((int)chrono::steady_clock::now().time_since_epoch().count()); int uniform(int l, int r) { uniform_int_distribution<int> uid(l, r); retur...
5
#include <bits/stdc++.h> using namespace std; const int N = 4005, M = 1000005; int n, kk, trie[M][26], ptr, cnt[M], sz[M]; char s[N]; void insert(char *s) { int l = strlen(s), cur = 0; for (int i = 0; i < l; i++) { if (!trie[cur][s[i] - 'a']) trie[cur][s[i] - 'a'] = ++ptr, ++sz[cur]; cur = trie[cur][s[i] - ...
6
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long n, ans; cin >> n; ans = (n * (n - 1)) >> 1; string s; cin >> s; vector<int> A, B; for (int i = 0; i < int(n); i++) { if (s[i] == 'A') A.push_back(i); else B.push_ba...
4
#include <bits/stdc++.h> using namespace std; int a[1000], s[1000], f[1000]; double d[1000]; void qs(int q, int w) { int e = q, r = w, t = f[q + (rand() % (w - q + 1))], y; double u; do { while (f[e] < t) e++; while (f[r] > t) r--; if (e <= r) { y = a[e]; a[e] = a[r]; a[r] = y; ...
3
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int maxn = 200005, maxm = 200005; inline int gi() { char c = getchar(); while (c < '0' || c > '9') c = getchar(); int sum = 0; while ('0' <= c && c <= '9') sum = sum * 10 + c - 48, c = getchar(); return sum; } #define pb pu...
0
#include <bits/stdc++.h> using namespace std; const int n_max = 100005; int n, m, i, j, k, x, y, f[n_max]; vector<int> g[n_max]; vector<pair<int, pair<int, int> > > ans; bool go(int u, int p) { f[u] = 1; int i, to, h = 0, e, x; for (i = 0; i < g[u].size(); i++) { to = g[u][i]; if (to == p || f[to] == 2) c...
3
#include <bits/stdc++.h> using namespace std; struct S { int a, b; }; S Exam[5005]; bool comp(S A, S B) { if (A.a == B.a) { return A.b < B.b; } return A.a < B.a; } int main() { int n, i; scanf("%d", &n); for (i = 0; i < n; i++) scanf("%d%d", &Exam[i].a, &Exam[i].b); sort(Exam, Exam + n, comp); boo...
1
#include <bits/stdc++.h> using namespace std; bool ok = false; long long x, y, n, sl = 0; long long kq[100111]; void go(long long vt, long long xx, long long yy) { if (vt == 1) { if (yy * yy < xx || yy <= 0) return; sl++; kq[sl] = yy; ok = true; return; } if (yy == 0) return; sl++; kq[sl] ...
1
#include <bits/stdc++.h> using namespace std; const double eps = 1e-8; const double pi = acos(-1.0); int dblcmp(double d) { if (fabs(d) < eps) return 0; return d > eps ? 1 : -1; } int dp[111111][6]; int main() { int i, j, k; string s; cin >> s; int l = (int)((s).size()); s = "@" + s; set<string> st; m...
1
#include <bits/stdc++.h> using namespace std; int main() { int n, l; cin >> n >> l; vector<int> a(n); vector<int> b(n); for (int i = 0; i < n; ++i) cin >> a[i]; for (int i = 0; i < n; ++i) cin >> b[i]; vector<int> c(n); for (int zsuv = 0; zsuv < l; ++zsuv) { for (int i = 0; i < n; ++i) { c[i] ...
2
#include <bits/stdc++.h> using namespace std; int main() { int N; long long X; cin >> N >> X; vector<long long> x(N); vector<long long> S(N+1, 0); for(int i=0; i<N; ++i) { cin >> x[i]; S[i + 1] = S[i] + x[i]; } long long res = -1; for(int k=1; k<=N; ++k) { l...
0
#include <bits/stdc++.h> using namespace std; struct node { int u; int v; int d; bool operator<(node b) const { return d < b.d; } }; node nn[256]; unsigned f[155][5], g[155][5], gg[155][5], tmp[155][5]; int n, m; void cgf() { for (int i = 1; i <= n; i++) { for (int j = 0; j <= (n >> 5); j++) { tmp[i...
4
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); long long int n, *a, x, sum = 0; cin >> n; a = new long long int[n]; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n; i++) { cin >> x; a[i] -= x; } sort(a, a + n); for (int i = ...
4
#include <bits/stdc++.h> using namespace std; int n, len, nxt[202]; char ss[202]; long long dp[202][202][202][2], mod = 1000000007; void getnxt() { for (int i = 2, j = 0; i <= len; i++) { while (j && ss[j + 1] != ss[i]) j = nxt[j]; if (ss[j + 1] == ss[i]) j++; nxt[i] = j; } } long long dfs(int now, int ...
6
#include <bits/stdc++.h> using namespace std; int b[1050], seq[1050], fl[1050], fr[1050], a[1050][1050], u[1050][1050], d[1050][1050], l[1050][1050], r[1050][1050], n, m, q; void initf(int d) { for (int i = 1; i <= d; i++) { fl[i] = fr[i] = i; } } void init() { for (int i = 1; i <= n; ++i) for (int j ...
2
#include <iostream> #include <cstring> using namespace std; long long a[300005]; const int MOD = 1000000007; int main() { int n; cin >> n; for(int i = 0; i < n; i++) cin >> a[i]; long long ans = 0; for(int j = 0; j < 60; j++) { long long u = 0, v = 0; for(int i = 0; i < n; i++) { if(a[...
0
#include <bits/stdc++.h> using namespace std; const int N = 500000 + 10; const int md = 1e6 + 3; int p[md]; int mpow(int x, int k) { int re = 1; while (k) { if (k & 1) re = 1ll * re * x % md; k >>= 1; x = 1ll * x * x % md; } return re; } int inv(int x) { return mpow(x, md - 2); } int f(int n, int c)...
4
#include <bits/stdc++.h> const int N = 5000; const int M = 1000002; int n, k, m, size, limit, a[N], timestamp[N]; std::vector<int> graph[N]; std::vector<std::pair<int, int>> bucket[M]; void dfs(int u) { size++; timestamp[u] = m; for (int v : graph[u]) { if (timestamp[v] != m) { dfs(v); } } } bool ...
5
#include <bits/stdc++.h> using namespace std; const int N = 155; int n, m, k; int ex, ey; string s; char a[N][N]; bitset<N> cur[N], spasite[N], blocked[N], new_cur[N]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> m >> k; int ss = 0; for (int i = 1; i <= n; i++) { for (...
4
#include <bits/stdc++.h> using namespace std; int mult(int x, int y) { long long ans, x1 = (long long)x, y1 = (long long)y; ans = (x1 * y1) % 1000000007; return (int)ans; } 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)); } int pow1(int a, int b) { ...
2
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; const int N = 2e5 + 10; long long a[N]; long long fac[N], rev_fac[N]; long long qpow(long long a, long long k) { long long ret = 1; while (k) { if (k % 2) ret = (a * ret) % MOD; a = (a * a) % MOD; k /= 2; } return ret; } void ini...
2
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long n; cin >> n; if (n % 2 && n > 3) { cout << 1 << " " << ((n - 3) / 2) << endl; } else { cout << "NO"; } return 0; }
1
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e3 + 5; const unsigned long long ulinf = -1ull; struct Node { int id; unsigned long long x; } p[MAXN], q[MAXN]; int pcnt = 0, qcnt = 0; inline bool cmp(const Node &p, const Node &q) { return p.x > q.x; } deque<Node> pp, qq; int main(void) { int n; ...
6
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long int t; cin >> t; while(t--){ long long int n; cin >>n; long long int a[n], sum = 0; for(long long int i = 0; i < n; i++){ cin >> a[i]; } if(n==1){ ...
3
#include <bits/stdc++.h> using namespace std; char op[600001]; long long id[600001], ans[600001], s[600001]; long long n, m, t; bool cmp(long long x, long long y) { long long pa, pb; if (op[x] == 'L') { pa = ((s[x] - t) % m + m) % m; } else pa = (s[x] + t) % m; if (op[y] == 'L') { pb = ((s[y] - t) %...
6
#include <bits/stdc++.h> using namespace std; int main() { int n = 0; scanf("%d", &n); int a[n]; bool in = false, con = false, de = false, flag = true; for (int i = 0; i < n; i++) { scanf("%d", &a[i]); if (!i) { continue; } else if (flag) { if (a[i] > a[i - 1]) { if (!con && !d...
1
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin >> n; long long a = n / 10; long long r = n % 10; if (r <= 5) cout << a * 10 << endl; else cout << (a + 1) * 10 << endl; return 0; }
1
#include <bits/stdc++.h> using namespace std; const int maxn = (int)1e6; long long n, q, sum[maxn], x[maxn], vis[maxn]; vector<pair<int, int> > e[maxn]; double ans, fac; struct Line { long long x, y, w; } l[maxn]; void dfs(int u) { vis[u] = 1; sum[u] = 1; for (int i = 0, j = (int)e[u].size(); i < j; ++i) { ...
4
#include <bits/stdc++.h> using namespace std; const int maxn = 100005; struct node { int id, size, money; } sh[maxn], pn[maxn]; long long dp[maxn][4]; int pnt[maxn][4], flag[maxn][4], a[maxn][2], n, m; map<int, int> ans; void init() { scanf("%d", &n); for (int i = 0; i < n; i++) { sh[i].id = i; scanf("%d%...
4
#include <bits/stdc++.h> using namespace std; const int N = 2005; const double inf = 1e18; int n, tot, pos[N], id[N]; long long S; struct point { int x, y; } p[N]; struct data { int x, y; double w; } a[N * N]; bool cmpx(point a, point b) { return a.x < b.x; } bool cmpw(data a, data b) { return a.w < b.w; } long l...
4
#include<bits/stdc++.h> #define ll long long using namespace std; const int MAXN = 107; int dp[MAXN][MAXN * 3], w[MAXN], v[MAXN]; int main() { int n, W; scanf("%d%d", &n, &W); for (int i = 1; i <= n; i++) scanf("%d%d", &w[i], &v[i]); int ww = w[1]; for (int i = 1; i <= n; i++) w[i] -= ww; int ans =...
0