solution
stringlengths
53
181k
difficulty
int64
0
13
#include <bits/stdc++.h> using namespace std; int main() { int n, m, i; cin >> n >> m; cout << (n + m - 2 + n * m) << '\n'; for (i = 1; i <= m - 1; i++) cout << "L"; for (i = 1; i <= n - 1; i++) cout << "U"; for (i = 1; i <= n; i++) { for (int j = 1; j < m; j++) cout << (i & 1 ? "R" : "L"); cout << ...
4
#include <bits/stdc++.h> using namespace std; struct Message { int person = -1; vector<bool> v; int cnt = 0; bool add(int x) { if (!v[x]) { return false; } else { cnt--; v[x] = false; return true; } } string msg; }; vector<string> parseMsg(string msg) { msg += '.'; st...
7
#include <bits/stdc++.h> using namespace std; long int mod = 1000000007; const int MAXN = 5000005; int spf[MAXN], arr[MAXN]; void sieve() { spf[1] = 1; for (int i = 2; i < MAXN; i++) spf[i] = i; for (int i = 4; i < MAXN; i += 2) spf[i] = 2; for (int i = 3; i * i < MAXN; i++) { if (spf[i] == i) { for (...
4
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; char a[n]; for (int i = 0; i < n; i++) cin >> a[i]; int open = 0, close = 0; int res = 0; for (int i = 0; i < n; i++) { if (a[i] == ')') { close++; } else open++; } if (close != open) { cout << "-1\n"; ...
2
#include <bits/stdc++.h> using namespace std; int n; long long A, B; struct node { long long vx, vy, w; } p[400005]; bool cmp(const node p1, const node p2) { if (p1.w == p2.w) return p1.vx < p2.vx; return p1.w < p2.w; } int main() { scanf("%d%I64d%I64d", &n, &A, &B); int i, j; long long gg; for (i = 1; i ...
6
#include <bits/stdc++.h> using namespace std; long long ma[30002]; long long dp[30002][502], n, d; long long solve(long long cur, long long le) { if (cur > 30000) return 0; long long jj = 250 + le - d; if (dp[cur][jj] != -1) return dp[cur][jj]; long long ans = 0; for (long long i = -1; i < 2; i++) { long ...
5
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; int a[n + 5], b[n + 5]; for (int i = 1; i <= n; i++) cin >> a[i]; for (int j = 1; j <= n; j++) cin >> b[j]; bool flag = true; if (n % 2 && a[n / 2 + 1] != b[n / 2 + 1]) flag = fal...
6
#include <bits/stdc++.h> using namespace std; int v[10000]; void swap(char &a, char &b) { char ch; ch = a; a = b; b = ch; } int main() { int n; int i, t, j; string s; while (cin >> n >> t) { cin >> s; for (i = 1; i <= t; i++) { for (j = s.size() - 1; j >= 0; j--) v[j] = 0; for (j = s...
0
#include <bits/stdc++.h> using namespace std; struct Node { int key; int color; Node *l, *r, *p; }; struct Tree { Node *root; Node *begin, *end; int size; }; Tree *create_tree() { Tree *T = (Tree *)malloc(sizeof(Tree)); T->root = T->begin = T->end = NULL; T->size = 0; return T; } Node *right_rotate(...
4
#include <bits/stdc++.h> using namespace std; template <typename Arg1> void __f(const char* name, Arg1&& arg1) { cerr << name << ": " << arg1 << endl; } template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args) { const char* comma = strchr(names + 1, ','); cerr.write(name...
4
#include <bits/stdc++.h> using namespace std; vector<long long> a(16), v[2], row, col; int n, k; void g(int h, int in, long long cur) { if (in == (int)v[h].size()) { if (h == 0) row.push_back(cur); else col.push_back(cur); return; } long long temp = 1; for (int i = 0; i < 60; i++) { ...
8
#include <bits/stdc++.h> using namespace std; int main() { long long n; string s; string a = "0000000000"; cin >> n >> s; for (long long i = 0; i < n; i++) { if (s[i] == 'L') a[a.find('0')] = '1'; if (s[i] == 'R') a[a.rfind('0')] = '1'; else a[s[i] - '0'] = '0'; } cout << a; }
0
#include <bits/stdc++.h> using namespace std; bool debug = 1; class pes { public: int v; int x, dir; }; vector<pes> v; int n, s; vector<int> pl, pr; bool pos(long double t) { pl.clear(); pr.clear(); pl.resize(1e6 + 10, 0); pr.resize(1e6 + 10, 0); for (int i = 0; i < (n); i++) { if (v[i].dir == 2) con...
8
#include <bits/stdc++.h> using namespace std; int mod = 998244353; long long int gcd(long long int a, long long int b) { if (b == 0) return a; else return gcd(b, a % b); } int min(int a, int b) { if (a > b) return b; return a; } long long int max(long long int a, long long int b) { if (a > b) return a...
5
#include <bits/stdc++.h> int main(int argc, char *argv[]) { int x = 2; int n, ans = 1; scanf("%d", &n); while ((x * x - x) / 2 <= n) { if (n % ((x * x - x) / 2) == 0) ans = (x * x - x) / 2; x *= 2; } printf("%d", ans); return 0; }
1
#include <bits/stdc++.h> using namespace std; const double eps = 1e-6; const int MOD = 1e9 + 7; const int INF = 2147000000; const long long inf = 1e18; long long gcd(long long a, long long b) { if (!b) return a; return gcd(b, a % b); } long long lcm(long long a, long long b) { return a / gcd(a, b) * b; } const int ...
5
#include <bits/stdc++.h> using namespace std; const int N = 1000005 * 2; int n; char a[N], b[N]; int Next[N], len[N]; unsigned long long Ha[2][N], Hb[2][N], Fac[2][N], T[2] = {233, 65537}; unsigned long long Get_Hash(unsigned long long *Ha, unsigned long long *Fac, int L, int R) { if (L > ...
8
#include <bits/stdc++.h> using namespace std; int const M = 2e5 + 10; vector<int> adj[M]; bool seen[2]; int p[M]; bool mark[M]; void dfs(int v, int l, int path) { if (adj[v].size() == 1) seen[path] = 1, p[v] = l; else p[v] = -1; for (int i = 0; i < adj[v].size(); i++) { int u = adj[v][i]; if (u !=...
5
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; for (int i = 300001; i < 300001 + n; i++) { cout << i << " "; } return 0; }
2
#include <bits/stdc++.h> using namespace std; template <class P, class Q> inline P smin(P &a, Q b) { if (b < a) a = b; return a; } template <class P, class Q> inline P smax(P &a, Q b) { if (a < b) a = b; return a; } const long long N = 1e6 + 6; long long read() { long long x; cin >> x; return x; } long lo...
9
#include <bits/stdc++.h> using namespace std; int d[305], ml[305]; int S, T, len = 1, ans, E[305][305], a[305]; int n, head[305], mr[305], vis[305], cnt; struct way { int num, next, cap; } G[305 * 305]; void link(int x, int y, int z) { G[++len] = (way){y, head[x], z}, head[x] = len; G[++len] = (way){x, head[y], 0...
10
#include <bits/stdc++.h> using namespace std; int n, k; int v[5][1005], u[5][1005]; int dp[1005][1005]; bool mark[1005][1005]; int f(int last, int idx) { if (idx == n) return 0; if (mark[idx][last]) return dp[idx][last]; mark[idx][last] = 1; int ret = f(last, idx + 1); int toLook = v[0][idx + 1]; bool deu =...
5
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; long long ans = 0; for (int i = 0; i < min(n / 2, k); ++i) { ans += 2LL * (n - 1LL - 2LL * i) - 1; } cout << ans << endl; return 0; }
2
#include <bits/stdc++.h> std::string getlast(std::string str, int value) { return str.substr(str.size() - value, value); } int main() { int tcase; scanf("%d", &tcase); std::string str; while (tcase--) { std::cin >> str; int len = str.size(); if (len >= 2) { if (getlast(str, 2) == "po") { ...
0
#include <bits/stdc++.h> using namespace std; const int inf = 1e9; int read() { int x = 0, p = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') p = 0; ch = getchar(); } while (ch >= '0' && ch <= '9') x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar(); return p ? x : -x; } i...
10
#include <bits/stdc++.h> using namespace std; int n, lx, ly, l, cnt[2 * 100005], len, aib[2 * 100005]; int v[2 * 100005], ll; unordered_map<int, int> M; struct el { int val, x, y; bool operator<(const el A) const { if (val == A.val) return x < A.x; return val < A.val; } } Ox[100005], Oy[100005]; struct ev...
7
#include <bits/stdc++.h> using namespace std; double power(double i, long long j) { if (j == 0) return 1.0; if (j == 1) return i; double ass = power(i, j / 2); if (j % 2 == 0) return ass * ass; return i * ass * ass; } int main() { long long n, m; scanf("%I64d%I64d", &n, &m); double x = 0; double y = (...
4
#include <bits/stdc++.h> using namespace std; vector<long long> adj[100005]; bool visited[100005]; int main() { ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); int a[3], b[3]; for (int i = 0; i < 3; i++) cin >> a[i]; long long h = 0; for (int i = 0; i < 3; i++) { cin >> b[i]; if (a[i] != b...
1
#include<bits/stdc++.h> using namespace std; typedef long long ll; #define YES cout<<"YES" #define NO cout<<"NO" #define Yes cout<<"Yes" #define No cout<<"No" #define yes cout<<"yes" #define no cout<<"no" #define FOR(S , E) for(ll i=S;i<=E;i++) #define ROF(E , S) for(ll i=E;i>=S;i--) // V.push_back() // V.pop_front()//...
2
#include <bits/stdc++.h> using namespace std; long long i, j, k, n, m, t, l, r, mid; long long g[600000], inf, b[600000], c[600000], L[600000], R[600000], mi; inline bool judge() { int i, j; for (i = 1; i <= r - mid + 1; i++) { j = i + mid - 1; if (g[j] - g[i] > mi) continue; if (L[i] + R[j] <= m) retur...
8
#include <bits/stdc++.h> using namespace std; template <class T1, class T2> ostream& operator<<(ostream& out, const pair<T1, T2> p) { out << '(' << p.first << ',' << p.second << ')'; return out; } template <class T1, class T2> istream& operator>>(istream& in, pair<T1, T2>& p) { in >> p.first >> p.second; return...
7
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; const long long INF = 1e18; const int inf = 1e9; const int MX = 1e5 + 1; long long gcd(long long a, long long b) { return (a ? gcd(b % a, a) : b); } int main() { long long x0, y0, ax, ay, bx, by; cin >> x0 >> y0 >> ax >> ay >> bx >> by; ...
4
#include <bits/stdc++.h> using namespace std; int main() { long long int q, l1, r1, l2, r2; cin >> q; while (q--) { cin >> l1 >> r1 >> l2 >> r2; cout << l1 << ' '; if (l2 == l1) { cout << l2 + 1 << endl; } else { cout << l2 << ' ' << endl; } } }
0
#include <bits/stdc++.h> using namespace std; using ll = long long; ll n; int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> n; vector<ll> a(n + 1, 0); for (ll i = 1; i <= n; ++i) cin >> a[i]; if (n == 1) { cout << 1 << " " << 1 << endl; cout << -a[1] << endl; cout << 1 << " " << 1 << ...
4
#include <bits/stdc++.h> using namespace std; int main() { std::ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); int n; cin >> n; vector<int> v(n); for (int i = 0; i < n; i++) cin >> v[i]; sort(v.rbegin(), v.rend()); long long sum = 0; while (n > 0) { for (int i = 0; i < n; i++) sum += v[i]; n ...
3
#include <bits/stdc++.h> using namespace std; long long modular_pow(long long base, long long exponent, long long modulus) { long long result = 1; while (exponent > 0) { if (exponent % 2 == 1) result = (result * base) % modulus; exponent = exponent >> 1; base = (base * base) % modulus; } return resu...
3
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 10; long long ans, pw[N], p, x; string s; int main() { pw[0] = 1; for (int i = 1; i < N; i++) pw[i] = pw[i - 1] * 2; ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); cin >> s; for (int i = 1; i < s.size(); i++) { if (((s[i - 1] - '0') * 10...
2
#include <bits/stdc++.h> using namespace std; int a[102], b[102]; int main() { int n; cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; int k = 1; for (int i = 0; i < n; i++) { if (a[i] == k) { b[i] = 1; k++; } } cout << k - 1 << endl; for (int i = 0; i < n; i++) { if (b[i] == 1...
2
#include <bits/stdc++.h> using namespace std; int n, k, i, ans = 0; string s; int main() { cin >> n >> k >> s; sort(s.begin(), s.end()); for (i = 1; i < s.size(); i++) if (s[i] - s[i - 1] <= 1) { s.erase(i, 1); i = i - 1; } if (s.size() < k) { cout << -1; return 0; } for (i = 0; ...
0
#include <bits/stdc++.h> using namespace std; long long tm[1000]; long long f(long long k, long long d) { assert(((1LL << 62LL) + (1LL << 61LL)) / d >= (1LL << k) - 1LL + (d - 1LL) / 2LL); return ((1LL << k) - 1LL + (d - 1LL) / 2LL) * d; } int main() { long long nts = 0; long long n; cin >> n; for ...
5
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 6; const long long inf = N; vector<pair<long long, long long> > va[20], vb[20]; int x[N]; bool cek(long long a, long long b, long long w, long long h) { return (a <= w && b <= h) || (a <= h && b <= w); } int main() { int n, a, b, h, w; scanf("%d %d...
6
#include <bits/stdc++.h> using namespace std; template <class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; } template <class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; } long long f[2001], dp[2001][2001], m = 998244353; long long fun(long long i, long long j) { if (i == 0) ...
9
#include <bits/stdc++.h> using namespace std; const int N = 3003; int g, g0, n, m, a, b, x, y, z, grid[N][N]; long long ans; vector<int> v[N]; deque<int> dq; void solve() { for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { while (!dq.empty() && dq.front() <= j - b) dq.pop_front(); while (!...
6
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; std::vector<std::pair<int, int> > cur; void get(int n) { if (n <= 1) return; int k = n - 4; get(n - 4); for (int i = 1; i < k + 1; i++) cur.push_back(make_pair(i, k + 1)); cur.push_back(make_pair(k + 1, k + 2)); for (int i = k; ...
11
#include <bits/stdc++.h> using namespace std; signed main() { ios::sync_with_stdio(false); int Q; cin >> Q; while (Q--) { int64_t N; cin >> N; auto f = [&](int64_t x) { return N - x + min(N - x, x * (x - 1) / 2); }; int64_t lb = 1, ub = N; while (ub - lb > 2) { int64_t x = lb + (ub - l...
6
#include <bits/stdc++.h> using namespace std; int a[100005]; int last[100005]; int lson[5000005]; int rson[5000005]; int data[5000005]; int roots[100005]; int tot; int build(int l, int r) { int cur = ++tot; int mid = (l + r) >> 1; if (l != r) { lson[cur] = build(l, mid); rson[cur] = build(mid + 1, r); }...
8
#include <bits/stdc++.h> using namespace std; vector<long long> a, b; vector<pair<long long, char> > ans; long long n, k; bool check(int lf, int rt) { bool b = 0; long long se = 0; for (int i = lf; i <= rt; i++) { long long sum = a[i], l = i - 1, r = i + 1, cur = i; vector<pair<long long, char> > v; w...
5
#include<bits/stdc++.h> typedef int LL; typedef double dl; #define opt operator #define pb push_back #define pii std::pair<LL,LL> const LL maxn=1e3+9,mod=998244353,inf=0x3f3f3f3f; LL Read(){ LL x(0),f(1); char c=getchar(); while(c<'0' || c>'9'){ if(c=='-') f=-1; c=getchar(); } while(c>='0' && c<='9'){ x=(x<<3ll...
9
#include <bits/stdc++.h> using namespace std; const int N = 200005; long long s[N], e[N]; int T, cur, w, l; long long win(long long x, long long y) { if (y & 1) { if (x & 1) return 0; return 1; } if (x > y / 2) { if (x & 1) return 1; return 0; } if (x > y / 4) return 1; return win(x, y >> 2)...
9
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 100; const double PI = 3.1415926536; vector<string> v; long long n, m, k, t, sum, r, l, d, b, c, a, p, e; map<int, string> mp; bool f; string s; stack<char> st; int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); cin >> s; n = s.size(); s...
2
#include <bits/stdc++.h> using namespace std; int n; const int maxn = 1000000; long long a[10]; long long b[10]; int bel[10]; bool is_fact[10][10]; bool is_prime[10]; int fact[10]; int work(long long val) { int cnt = 0; for (int i = 2; i <= maxn; i++) { while (val % i == 0) { val /= i; cnt++; } ...
7
#include <bits/stdc++.h> using namespace std; template <typename T> inline T read() { register T sum = 0; register char cc = getchar(); int sym = 1; while (cc != '-' && (cc > '9' || cc < '0')) cc = getchar(); if (cc == '-') sym = -1, cc = getchar(); sum = sum * 10 + cc - '0'; cc = getchar(); while (cc >...
6
#include <bits/stdc++.h> using namespace std; int main() { int n, x, y, m, ans = 0, lastX = -1, lastY = -1, h, d; scanf("%d %d", &n, &m); for (int i = 0; i < m; i++) { scanf("%d %d", &x, &y); if (lastX == -1) { lastX = x; lastY = y; ans = x + y - 1; d = x; h = y; contin...
4
#include <bits/stdc++.h> using namespace std; const int MAXN = 3010; const int INF = 1e9; const int MOD = 1e9 + 7; int rnk[MAXN], par[MAXN]; int n, m; vector<pair<pair<int, int>, int> > mv, sv; int vis[MAXN]; int getpar(int a) { return par[a] == a ? a : par[a] = getpar(par[a]); } bool merge(int a, int b) { int pa = g...
7
#include <bits/stdc++.h> using namespace std; const int maxn = 200010; int Laxt[maxn], Next[maxn], To[maxn], cost[maxn], dis[maxn], fa[maxn], cnt; int a[maxn], vis[maxn], tN, S, T, ans = 1e9 + 7; int Sdis[maxn], Tdis[maxn], Ldis[maxn]; multiset<int> s; void add(int u, int v, int c) { Next[++cnt] = Laxt[u]; Laxt[u] ...
8
#include <bits/stdc++.h> using namespace std; int cnt = 1, n, d, k; vector<vector<int>> graph; vector<pair<int, int>> edges; void dfs(int u, int maxd); int main() { cin >> n >> d >> k; graph = vector<vector<int>>(n + 1); if (n < d + 1) { cout << "NO" << endl; return 0; } for (int i = 0; i < d; i++) { ...
6
#include <bits/stdc++.h> using namespace std; int cnt(int bit) { int ret = 0; for (int i = 0; i < 26; i++) { if (bit >> i & 1) { ret++; } } return ret; } char op[100000]; string s[100000]; int main() { cin.tie(0); ios::sync_with_stdio(false); int N; cin >> N; int all = 0, sum = 0; for ...
4
#include <bits/stdc++.h> using namespace std; int main() { int n, c = 0, i; cin >> n; string a; cin >> a; for (i = 0; i < n - 1; i++) { if (a[i] != a[i + 1]) { cout << "YES" << endl << a[i] << a[i + 1]; c++; break; } } if (c == 0) cout << "NO"; }
1
#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 (...
0
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n; cin >> n; string s, m; cin >> s >> m; int ara[300] = {0}; for (int i = 0; i < n; i++) { ara[m[i]]++; } int mn = 0, mx = 0, k = 0; sort(m.begin(), m.end()); sort(s.begin(), s.end())...
2
#include <bits/stdc++.h> const int N = 15; const int M = 2005; const int S = 4105; int n, m, col[M], a[N][M], id[M], bin[N], w[N][S], f[N][S], nx[S][N], mx[N][S]; void clear() { memset(col, 0, sizeof(col)); memset(w, 0, sizeof(w)); memset(f, 0, sizeof(f)); memset(nx, 0, sizeof(nx)); memset(mx, 0, sizeof(mx));...
6
#include <bits/stdc++.h> const int N = 1e5 + 5; const long double pi = 3.141592653; const long long MOD = 1e9 + 7; const long long mod = 998244353; const long long INF = 9223372036854775807LL; using namespace std; int dx[9] = {1, -1, 0, 0, 1, 1, -1, -1, 0}; int dy[9] = {0, 0, 1, -1, 1, -1, 1, -1, 0}; int main() { ios...
4
#include <bits/stdc++.h> using namespace std; vector<pair<int, int> > e; queue<int> q; int h[200010]; int main() { int n, k, i; scanf("%d%d", &n, &k); for (i = 2; i <= k + 1; i++) { e.push_back(pair<int, int>(1, i)); h[i] = 1; q.push(i); } for (i = k + 2; i <= n; i++) { e.push_back(pair<int, i...
5
#include <bits/stdc++.h> using namespace std; const int N = 200 * 1000; int n; int l[N], r[N], t[N]; set<pair<int, int>> st[2]; int main() { scanf("%d", &n); for (int i = 0; i < int(n); ++i) scanf("%d%d%d", &l[i], &r[i], &t[i]), --t[i]; vector<pair<int, pair<int, int>>> ev; for (int i = 0; i < int(n); ++i) { ...
9
#include <bits/stdc++.h> using namespace std; using ll = long long; const int N = 2e5 + 10; struct node { int l, r, id; friend bool operator<(node A, node B) { return A.r == B.r ? A.l < B.l : A.r < B.r; } }; node a[N]; bool add[N]; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ll n, m...
5
#include <bits/stdc++.h> using namespace std; long long int max(long long int a, long long int b) { if (a > b) return a; return b; } long long int min(long long int a, long long int b) { if (a < b) return a; return b; } long long int abbs(long long int a, long long int b) { if (a - b < 0) return b - a; retu...
0
#include <bits/stdc++.h> using namespace std; int p, n; string s; bool solve(int a) { if (a == n) return 1; for (char i = 'a'; i < p + 'a'; i++) { if (s[a - 1] == i || s[a - 2] == i) continue; s[a] = i; if (solve(a + 1)) return true; } return false; } int main() { cin >> n >> p; cin >> s; int ...
4
#include <bits/stdc++.h> const int N = 200020; std::set<int> s[N]; int n, m, a, b, ans, p[N], e[N]; int find(int x) { return !e[x] ? x : e[x] = find(e[x]); } void f(int i, int x) { if (find(p[x - 1]) == find(i)) ans--; if (find(p[x + 1]) == find(i)) ans--; s[i].insert(x); } int main() { scanf("%d%d", &n, &m); ...
7
#include <bits/stdc++.h> using namespace std; const int K = 26; const int NMAX = 4e5; struct info_t { int len = 0; long long c = 0; long long endc = -1; info_t() {} }; struct vertex { int next[K]; int next_term = -1; bool leaf; int p; char pch; int link; int go[K]; info_t info; vertex() : link...
8
#include <bits/stdc++.h> int digits(int i) { int a, b, c, d; a = i % 10; b = (i / 10) % 10; c = (i / 100) % 10; d = (i / 1000) % 10; if (a != b && b != c && c != d && a != c && a != d && b != d) return 1; else return 0; } int main() { int n, res; scanf("%d", &n); int i = n + 1; while (i > ...
0
#include <bits/stdc++.h> using namespace std; const int maxn = 200010, maxm = 32; string s, t; int L[maxn], R[maxn], W[maxn]; bool valid() { memset(W, -1, sizeof(W)); for (int i = 0; i < ((int)(s).size()); ++i) { if (L[i] != -1) W[t[L[i]] - 'a'] = L[i]; if (W[s[i] - 'a'] == -1 || W[s[i] - 'a'] < R[i]) retur...
5
#include <bits/stdc++.h> using namespace std; int ecnt; struct Edge { int to, w, id; Edge *next; } * mat[5010], edges[100010 * 2]; void link(int x, int to, int w, int id) { edges[ecnt].to = to; edges[ecnt].id = id; edges[ecnt].w = w; edges[ecnt].next = mat[x]; mat[x] = &edges[ecnt++]; } bool in_tree[5010]...
8
#include <bits/stdc++.h> int read() { register int x = 0; register char ch = getchar(), f = 1; for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = !f; for (; isdigit(ch); ch = getchar()) x = (x << 1) + (x << 3) + (ch ^ '0'); return f ? x : -x; } int n, a[200005]; int main() { n = read(); if (!(n &...
2
#include <bits/stdc++.h> using namespace std; vector<vector<int>> g; bool visitados[105]; int total = 0; void dfs(int v) { if (visitados[v]) { return; } visitados[v] = 1; total++; for (auto u : g[v]) { dfs(u); } } int32_t main() { int n, m, x, y; cin >> n >> m; g.resize(n + 1); for (int i = ...
3
#include <bits/stdc++.h> using namespace std; const int N = 51, M = N * 100000; bitset<M> f; int n, d, a[N]; int main() { scanf("%d%d", &n, &d); for (int i = 1; i <= n; ++i) scanf("%d", a + i); sort(a + 1, a + n + 1); f[0] = 1; int ans = 0; for (int i = 1; i <= n; ++i) { if (ans + d < a[i]) break; a...
7
#include <bits/stdc++.h> using namespace std; long long a[100009], b[100009], pre[100009]; long long top1, top2, n, d, m; bool com(long long q, long long w) { return q > w; } signed main() { cin >> n >> d >> m; for (long long i = 1; i <= n; i++) { long long x; scanf("%lld", &x); if (x <= m) a[++to...
5
#include <bits/stdc++.h> using namespace std; int main() { int n, ans = 0, x; string a, b; cin >> n; cin >> a; cin >> b; while (n--) { x = abs(a[n] - b[n]); ans += min(x, 10 - x); } cout << ans; return 0; }
0
#include <bits/stdc++.h> using namespace std; int min(int a, int b) { return (a < b) ? a : b; } int main() { int n, m; cin >> n >> m; string str; cin >> str; int dp[n]; for (int i = 0; i < n; i++) { dp[i] = 10000; } dp[0] = 0; for (int i = 0; i < n; i++) { if (str[i] == '1') { for (int j...
0
#include <bits/stdc++.h> using namespace std; const int maxN = 2e5 + 100; long long int bigL[maxN], bigR[maxN], L[maxN], a[maxN]; long long int n, q; void input() { cin >> n >> q; for (int i = 1; i <= n; i++) cin >> a[i]; } int recBigL(int pos, int x) { if (x <= L[pos]) return pos; if (pos <= 1) return 0; ret...
6
#include <bits/stdc++.h> using namespace std; long long f(long long n) { if (n < 1) return 0; return (n * (n + 1)) / 2; } int main() { long long n, i, j, k, s = 0, x, y, z; cin >> n; long long a[n + 1]; a[n] = 0; for (i = 0; i < n; i++) { cin >> a[i]; } for (i = 0; i < n; i++) { if (a[i + 1] !...
6
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin >> n; map<long long, long long> a; long long x, i; long long max = 0; for (i = 0; i < n; i++) { cin >> x; a[x]++; if (a[x] > max) { max = a[x]; } } cout << n - max << endl; }
2
#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, i, ans = 0, mans = 0; cin >> n; long long int a[n]; for (i = 0; i < n; i++) cin >> a[i]; for (i = 1; i < n; i++) { if ...
2
#include <bits/stdc++.h> using namespace std; ifstream fin("AAtest.in.txt"); int q, n, jada['z' + 1], jadb['z' + 1]; string a, b; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cerr.tie(0); cin >> q; while (q--) { cin >> n >> a >> b; memset(jada, 0, sizeof(jada)); memset(jadb, 0,...
6
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c; cin >> a >> b >> c; string s; cin >> s; for (int i = 0; i <= 100; i++) { for (int j = 0; j <= 100; j++) { if (i * b + j * c == a) { cout << i + j << endl; for (int k = 0; k < i; k++) { cout << s.substr(...
2
#include <bits/stdc++.h> using namespace std; int dx[9] = {1, -1, 0, 0, 1, 1, -1, -1, 0}; int dy[9] = {0, 0, 1, -1, 1, -1, 1, -1, 0}; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); vector<string> v; string s; cin >> s; int i; for (i = 0; i < 6; i++) { string s1, s2; s1.push_...
1
#include <bits/stdc++.h> using namespace std; int main() { string s; int a, b, x; cin >> a >> b >> x; if (a > b) s += '0', a--; else s += '1', b--; while (x > 1) { char c = s.back(); if (c == '0') s += '1', b--; else s += '0', a--; x--; } char c = s.back(); if (c ==...
2
#include <stdio.h> #include <bits/stdc++.h> using namespace std; #define rep(i,n) for (int i = 0; i < (n); ++i) #define modulo 1000000007 #define mod(mod_x) ((((long long)mod_x+modulo))%modulo) #define Inf 1000000000000000000 vector<int> p; vector<vector<int>> depth; void dfs(vector<vector<int>> &E,int cur,int par,int ...
8
#include <bits/stdc++.h> using namespace std; int main() { int n, a = 0, b = 0; cin >> n; for (int i = 0, c; i < n; ++i) { cin >> c; if (c % 2) ++a; else ++b; } cout << min(a, b); }
0
#include <bits/stdc++.h> using namespace std; long long n, k, mod; map<long long, long long> mp; long long v(long long a) { long long r = a * a % mod; (r *= r) %= mod; return (r - k * a % mod + mod) % mod; } int main() { cin >> n >> mod >> k; for (int i = 0; i < n; i++) { long long a; cin >> a; mp...
7
#include <bits/stdc++.h> using namespace std; inline long long rd() { char c; long long sign = 1; while ((c = getchar()) < '0' || c > '9') if (c == '-') sign = -1; long long res = c - '0'; while ((c = getchar()) >= '0' && c <= '9') res = res * 10 + c - '0'; return res * sign; } const int MAXN = 100010; ...
10
#include <bits/stdc++.h> using namespace std; #define ll long long int #define fr(i,n) for(int i=0;i<2*n;i++) #define min3(a, b, c) min(c, min(a, b)) #define min4(a, b, c, d) min(d, min(c, min(a, b))) #define rfr(i, n) for(int i=n-1;i>=0;i--) #define PI 3.1415926535897932384626 const int mod=1000000007; int main() { ...
0
#include <bits/stdc++.h> using namespace std; const long long oo = 100000000000ll; struct node { long long nx; long long w; }; vector<node> e[100005]; struct Heap { long long p; long long val; bool operator<(const Heap &t) const { return t.val < val; } } tp; priority_queue<Heap> Q; long long n, m; long long i...
5
#include <bits/stdc++.h> using namespace std; struct gtr { int x; int y; }; int n, i, x, y; gtr a[1000000], b[1000000]; bool cmp(gtr a, gtr b) { return (a.x < b.x || (a.x == b.x && a.y > b.y)); } int main() { scanf("%ld", &n); for (i = 1; i <= n; i++) { scanf("%ld%ld", &a[i].x, &a[i].y); b[i] = a[i]; ...
1
#include <bits/stdc++.h> using namespace std; map<long long, int> mp; long long a[200010], b[200010], c[200010]; int main() { long long n, q, k, m, i, j, total = 0, op; cin >> n >> q >> a[0]; long long mx = a[0]; for (i = 1; i < n; i++) { cin >> a[i]; b[i] = mx; c[i] = min(a[i], mx); mx = max(mx...
3
#include <bits/stdc++.h> using namespace std; void solution(vector<int> ar, int n) { map<int, bool> mp; int ans = -1; for (int i = 0; i < n; i++) { mp[ar[i]] = 1; } for (int i = 1; i <= 1024; i++) { int c = 0; for (int j = 0; j < n; j++) { int p = ar[j] ^ i; if (mp[p] == 1) { c...
2
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; char str[10]; bool flag; cout << 0 << " " << 0 << endl; cout.flush(); cin >> str; if (str[0] == 'w') flag = true; else flag = false; if (n == 1) { cout << "1 0 1 1" << endl; return 0; } int l = 0, r = 1 <...
5
#include <bits/stdc++.h> using namespace std; long long a, b, Ans[10010]; int l[10010], flag; int main() { scanf("%I64d%I64d", &a, &b), flag = 1; while (a > 1 || b > 1) { if (a > b) Ans[++*Ans] = (a - 1) / b, a -= (a - 1) / b * b, l[*Ans] = 0; else if (b > a) Ans[++*Ans] = (b - 1) / a, b -= (b -...
8
#include <bits/stdc++.h> using namespace std; int i, n, x, C[101]; int main() { cin >> n; for (i = 0; i < n; i++) { cin >> x, C[x]++; } for (i = 0; i < 101; i++) { while (C[i]--) cout << i << " "; } return 0; }
0
#include <bits/stdc++.h> using namespace std; int main() { int k, l; cin >> k >> l; int i = 0; while (l % k == 0 && k != l) { l = l / k; i += 1; }; if (k == l) { cout << "YES" << endl << i; } else { cout << "NO"; }; return 0; }
1
#include <bits/stdc++.h> using namespace std; int n, m; int res = 0; int u[1000][1000]; int a[1111][1111]; int dd[9][2] = {0, 0, -2, -1, -2, 1, -1, -2, -1, 2, 1, 2, 1, -2, 2, 1, 2, -1}; void ban(int x, int y, int t) { for (int i = 0; i < 9; i++) { int xx = x + dd[i][0]; int yy = y + dd[i][1]; if (xx >= 0 ...
5