solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> using namespace std; int dirx[] = {-1, -1, -1, 0, 0, 1, 1, 1}; int diry[] = {-1, 0, 1, -1, 1, -1, 0, 1}; int dx[] = {-1, 1, 0, 0}; int dy[] = {0, 0, -1, 1}; bool compare(const pair<int, int>& i, const pair<int, int>& j) { return i.second < j.second; } int main() { long long n, k; cin >> n...
7
#include <bits/stdc++.h> using namespace std; int main() { int n, x; scanf("%d%d", &n, &x); int a[n + 5][2]; for (int i = 0; i <= n - 1; i++) scanf("%d %d", &a[i][0], &a[i][1]); int prev = 1, view = 0; for (int i = 0; i <= n - 1; i++) { view = view - prev - (((a[i][0] - prev) / x) * x) + a[i][1] + 1; ...
2
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { int n, k; cin >> n >> k; int i = 1, j = n; int cnt = 0; vector<int> v; for (int p = 1; p <= n; p++) { if (p % 2 != 0) { cout << i << " "; i++; cnt++; if (cnt == k) { for (int q = i; q <= j; q...
4
#include <bits/stdc++.h> const int MOD = 1e9 + 7; const int MAXN = 1e9 + 1; const double PI = 3.14159265359; using namespace std; int main() { ios_base::sync_with_stdio(0); long long n, k; cin >> n >> k; long long mn = 1e18; for (int i = 1; i <= n; ++i) { long long w = n / i; if (n % i == 0 && w < k) ...
3
/** ____ ____ ____ ____ ____ ||a |||t |||o |||d |||o || ||__|||__|||__|||__|||__|| |/__\|/__\|/__\|/__\|/__\| **/ #include <bits/stdc++.h> using namespace std; typedef long long ll; const int N_MAX = 100002; const int M_MAX = 100002; const int A_MAX = 100002; const int A = 100000; int n, m; int arr[N_MAX]; in...
23
#include <bits/stdc++.h> using namespace std; int f[200200]; char P[200200], T[200200]; long long nump[200200], numt[200200]; int m, n; long long ans = 0; int test(char s[], char t[], int si, int ti, long long nums[], long long numt[]) { if (s[si] != t[ti] || numt[ti] < nums[si]) return 0; if (si < 2) { ...
13
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t = 0, n = 0, l = 0, r = 0, flag = 0, p = 0, my = 0; cin >> t; while (t--) { cin >> n; vector<tuple<int, int, int> > v; for (int i = 0; i < n; ++i) { cin >> l >> r; v.emplace...
7
#include <bits/stdc++.h> using namespace std; int main() { long long u, v; scanf("%lld %lld", &u, &v); auto p = (v - u) / 2; if (u == 0 && v == 0) printf("0"); else if (u == v) printf("1\n%lld", u); else if (u % 2 != v % 2 || u > v) printf("-1"); else if (((u + p) ^ p) == u) printf("2\n%ll...
9
#include <bits/stdc++.h> using namespace std; const int N = 500005, M = 105; int n, m, p; int a[N], sum[N], tmp[N], ans; int g[N], len = 1; struct tree { int c[M], d[M]; tree() { memset(c, 0x3f, sizeof(c)); memset(d, 0x3f, sizeof(d)); } void add1(int x, int k) { x++; for (; x <= p; x += x & (-x)...
4
#include <bits/stdc++.h> using namespace std; int main() { int n, x = 0, y = 0; char f[1000]; cin >> n; for (int i = 0; i < n; i++) { cin >> f[i]; if (i % 2 == 0) if (f[i] == '0') x++; else y++; else if (f[i] == '1') x++; else y++; } if (x < y) y = x; ...
10
#include <bits/stdc++.h> using namespace std; int n, a[505], f[505][505], g[505][505], ans; int main() { cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = (1); i <= (n); i++) for (int j = (1); j <= (n); j++) { g[i][j] = n + 1; } for (int i = (1); i <= (n); i++) { f[i][i] = a[i];...
13
#include <bits/stdc++.h> using namespace std; int main() { int a, maxcount = 0, t, count = 0, last = 0; cin >> a; for (int i = 0; i < a; i++) { cin >> t; if (last >= t) { if (count > maxcount) maxcount = count; count = 1; } else count++; last = t; } if (maxcount > count) ...
0
#include <bits/stdc++.h> using namespace std; int main() { int b, k; cin >> b >> k; int l; int odd = 0, even = 0; for (int i = 0; i < k; i++) { cin >> l; if (l % 2 != 0 && (k - i - 1) == 0) odd++; else if (l % 2 != 0 && b % 2 != 0) odd++; else even++; } if (odd % 2 == 0) ...
1
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; int n, d[N]; inline int read() { int x = 0, p = 1; char c = getchar(); while (c < '0' || c > '9') { if (c == '-') p = -1; c = getchar(); } while (c >= '0' && c <= '9') { x = x * 10 + c - '0'; c = getchar(); } return x * ...
3
#include <bits/stdc++.h> using namespace std; int main() { long long a, b, c; cin >> a >> b >> c; cout << c * 2 + min(a, b) * 2 + (a != b); }
0
#include <bits/stdc++.h> using namespace std; const int N = 5004; int memo[N][N], go[N], n, k; int solve(int indx, int rem) { if (indx == n) return 0; int &ret = memo[indx][rem]; if (~ret) return ret; ret = 0; ret = max(ret, solve(indx + 1, rem)); if (rem) ret = max(ret, go[indx] - indx + solve(go[indx], re...
10
#include <bits/stdc++.h> using namespace std; const int N = 100100 * 2; int s[N], p[N], a[N], b[N]; int cmp(int i, int j) { return s[i] < s[j]; } int main() { int n, m; scanf("%d", &n); m = (n + 2) / 3; printf("YES\n"); for (int i = 0; i < n; i++) scanf("%d", &s[i]), p[i] = i; sort(p, p + n, cmp); for (in...
16
#include <bits/stdc++.h> using namespace std; int main() { int n, m, c, d, k; int ans = 0; cin >> c >> d >> n >> m >> k; if (n * m - k <= 0) { ans = 0; } else { if (d * n > c) { ans += (n * m - k) / n * c; if ((n * m - k) % n * d > c) { ans += c; } else { ans += (n * ...
7
#include <bits/stdc++.h> using namespace std; const int A = 1e3 + 10; int k, n[15], a[15][A], x[15], sum; int main() { cin >> k; for (int i = 0; i < k; i++) { cin >> n[i]; for (int j = 0; j < n[i]; j++) { cin >> a[i][j]; } for (int j = n[i]; j > 0; j--) { for (int h = 0; h < n[i]; h++) {...
0
#include <bits/stdc++.h> using namespace std; int main() { cout.precision(15); cout.setf(ios::floatfield, ios::fixed); long t; cin >> t; while (t--) { double a1, a2, b1, b2, c, r, d; cin >> d; r = d * d - 4 * d; if (r < 0) { cout << "N" << endl; continue; } a1 = (d + sqrt(r...
5
#include <bits/stdc++.h> using namespace std; long long n, q; long long mi[200010], ma[200010], cnt[200010]; vector<pair<long long, long long> > g[200010]; long long f[200010]; int main() { for (int i = 0; i < 200010; i++) { mi[i] = 1e17, ma[i] = -1e17, cnt[i] = 0; } cin >> n >> q; for (long long i = 0; i <...
12
#include <bits/stdc++.h> using namespace std; #define ff first #define ss second #define int long long #define pb emplace_back #define pii pair<int,int> #define vi vector<int> #define mii map<int,int> #define pq priority_queue<int> #d...
4
#include <bits/stdc++.h> using namespace std; vector<vector<int>> edge; vector<int> dist; vector<int> et; vector<int> first; void inedge(int n, int m) { edge.resize(n + 1); dist.resize(n + 1, -1); first.resize(n + 1); int a, b; for (int i = 0; i < m; i++) { cin >> a >> b; edge[a].push_back(b); edg...
12
#include <bits/stdc++.h> using namespace std; int atk[102], def[102], my[102]; int solve1(int m, int a) { int ans = 0; int j = 0; for (int i = m - 1; i >= 0; --i) { if (j < a && my[i] >= atk[j]) { ans += my[i] - atk[j++]; } else { break; } } return ans; } int solv(int m, int a, int b) ...
11
#include <bits/stdc++.h> using namespace std; char a[1010], b[1010]; int main() { int i, a1 = 0, b1 = 0; scanf("%s%s", &a, &b); i = 0; while (a[i] == '0' || a[i] == '1') { a1 = a1 + a[i] - '0'; i++; } i = 0; while (b[i] == '0' || b[i] == '1') { b1 = b1 + b[i] - '0'; i++; } if (a1 + a1 ...
9
#include <bits/stdc++.h> using namespace std; int const maxn = 3e5 + 5; int a[maxn]; int lef[maxn]; int righ[maxn]; int go[maxn]; void solve() { int n, x; cin >> n; for (int i = 1; i <= n; ++i) cin >> a[i]; set<int> bb; for (int i = 1; i <= n; ++i) { bb.insert(a[i]); } vector<int> b; for (auto key :...
12
#include <bits/stdc++.h> using namespace std; const long double pi = acos(-1), EPS = 1e-8; long long gcd(long long a, long long b) { if (b == 0) return a; return gcd(b, a % b); } long long lcm(long long a, long long b) { return (a / gcd(a, b)) * b; } bool getBit(long long num, int idx) { return ((num >> idx) & 1); ...
3
#include <bits/stdc++.h> using namespace std; const int MAXN = 5e3 + 42; int n, m; vector<int> dp; const int mod = 1e9 + 7; int main() { cin >> n; dp.resize(MAXN); dp[1] = 1; int maxi = 1; char prv = 's'; for (int i = 0; i < n; ++i) { char c; cin >> c; if (c == 'f') ++maxi; vector<int> newdp...
10
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 7, RT = 200; int p[N]; int fr[N]; bool dp[N]; int cnt[N]; int mn[N], mx[N]; int main() { ios::sync_with_stdio(0); cin.tie(0); int n, k; cin >> n >> k; int odd = 0; for (int i = 1; i <= n; i++) cin >> p[i]; for (int i = 1; i <= n; i++) { ...
18
#include <bits/stdc++.h> using namespace std; const long long MOD = 998244353; const int MAXN = 1000010; long long a[MAXN]; long long pow2[MAXN]; void init() { pow2[0] = 1; for (int i = 1; i < MAXN; i++) pow2[i] = pow2[i - 1] << 1, pow2[i] %= MOD; } long long f(int n) { if (n == 0) return 1; long long N = n; ...
12
#include <bits/stdc++.h> using namespace std; const long double EPS = 1E-9; const int INF = (int)1E9; const long long INF64 = (long long)1E18; const long double PI = 2 * acos(.0); int n, m, k; int dp[105][105][12]; char path[105][105][12]; char mapa[105][105]; int main() { ios_base::sync_with_stdio(0); cin >> n >> ...
11
#include <bits/stdc++.h> using namespace std; template <class T> string tostring(T x) { ostringstream out; out << x; return out.str(); } long long toint(string s) { istringstream in(s); long long x; in >> x; return x; } int dx[8] = {0, 0, 1, -1, 1, 1, -1, -1}; int dy[8] = {1, -1, 0, 0, -1, 1, -1, 1}; int ...
11
#include <bits/stdc++.h> using namespace std; int p1 = -1000000001; int p2 = -1000000001; int n; int q1, h, q2, a, b, c1, c2; int main() { cin >> n; for (; n; n--) { cin >> q1 >> h; q2 = q1 + h; a = -1; if (q1 - h > p1) a = max(a, c1 + 1); if (q1 > p1) a = max(a, c1); if (q1 - h > p2) a = ma...
7
#include <bits/stdc++.h> using namespace std; vector<vector<pair<int, int>>> adj(200000); int a[200000]; int ans = 0; void dfs(int v, int d) { if (d > a[v]) { return; } ans++; for (int i = 0; i < adj[v].size(); ++i) { dfs(adj[v][i].first, max(0, adj[v][i].second + d)); } } int main() { int n, x, y; ...
8
#include <bits/stdc++.h> using namespace std; int main(int argc, const char* argv[]) { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long n, t; cin >> n >> t; long long sum = 0; vector<long long> a(n); for (long long i = 0; i < n; i++) { cin >> a[i]; sum += a[i]; } lo...
9
#include <bits/stdc++.h> using namespace std; int n; int main() { scanf("%d", &n); int m = n / 3; for (int i = 1; i <= m; i++) { printf("%d %d\n", 2, i * 2); printf("%d %d\n", 0, i * 2); printf("%d %d\n", -2, i * 2); } int k = n % 3; if (k) printf("%d %d\n", 2, (m + 1) * 2), k--; if (k) printf...
18
#include <bits/stdc++.h> using namespace std; mt19937 rnd(time(0)); const long long inf = 0x3f3f3f3f3f3f3f3fLL; const long long N = 3e5 + 10; const long long MOD = 1e9 + 7; int32_t main() { ios::sync_with_stdio(false); cin.tie(0); vector<long long> cnt(26); for (long long i = 0; i < 26; i++) { cin >> cnt[i]...
10
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 10; const int mo = 1e9 + 7; const int inf = 1e9; int a[N]; char s[N]; int main() { int n; scanf("%d%s", &n, s + 1); for (auto i = (1); i <= (n); ++i) a[i] = a[i - 1] + (s[i] == '(' ? 1 : -1); if (a[n]) return printf("0\n1 1\n"), 0; int mi = n +...
17
#include <bits/stdc++.h> using namespace std; const int iinf = 0x3f3f3f3f; const long long linf = 0x3f3f3f3f3f3f3f3f; const int N = 1000, M = 10; int n, m, hsh[200], et[M]; const int mod = 1e9 + 9; void fmod(int &first) { first += first >> 31 & mod; } const int aN = 101, C = 4; int an, ch[aN][C], fa[aN], len[aN]; int t...
17
#include <bits/stdc++.h> using namespace std; int n, m; bool isp(int k) { if (k < 2) return false; for (int i = 2; i * i <= k; i++) if (k % i == 0) return false; return true; } int main() { scanf("%d", &n); m = n * (n + 1) / 2; int p2 = -1, p3 = -1; if (!isp(m)) { if (m % 2 == 1 && !isp(m - 2)) { ...
14
#include <bits/stdc++.h> using namespace std; int n, a, cnt[(int)1e5 + 1]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; while (n--) { cin >> a; cnt[a]++; } for (int i = 1; i <= 1e5; i++) { if (cnt[i] & 1) { cout << "Conan"; return 0; } } cou...
4
#include <bits/stdc++.h> using namespace std; int main() { int n; scanf("%d", &n); int sum = 0; for (int i = 1; i <= n; ++i) { int x; scanf("%d", &x); sum = sum + (x - 1); sum %= 2; puts(sum & 1 ? "1" : "2"); } return 0; }
3
#include <bits/stdc++.h> using namespace std; int n, a[1005], sz; bool flag = false; pair<int, int> ans[5]; bool dfs(int dep) { int i; for (i = 1; i <= n && a[i] == i; i++) ; if (i == n + 1) { printf("%d\n", dep); for (i = dep - 1; i >= 0; i--) printf("%d %d\n", ans[i].first, ans[i].second); ...
19
#include <bits/stdc++.h> using namespace std; const int MAXN = 2e5 + 5; const long long INF = 1e10; const int MAXH = 1e4; const long long MOD = 1e9 + 7; long long dp[2][MAXN]; void solve() { long long r, g; cin >> r >> g; int fl; if (r > 0) dp[1][1] = 1; if (g > 0) dp[1][0] = 1; int mx = 0; long long s = ...
12
#include <bits/stdc++.h> using namespace std; int n, m, b, a[505]; long long mod, dp[505][505]; int main() { cin >> n >> m >> b >> mod; for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = 0; i <= m; i++) for (int j = 0; j <= b; j++) dp[i][j] = 0; dp[0][0] = 1; for (int i = 1; i <= n; i++) for (int ...
10
#include <bits/stdc++.h> using namespace std; vector<long long> vi[300005]; int color[100005]; bool visited[1000005] = {false}; bool is[100005]; long long fac[10000001]; long long prime[1000000]; long long bit[100005]; void fact() { fac[0] = 1; for (int i = 1; i <= 10000000; i++) { fac[i] = (fac[i - 1] * i) % 1...
5
#include <bits/stdc++.h> using namespace std; const int INF = 1000000000; const double EPS = 1e-8; using namespace std; void _kill() { cout << "NO"; exit(0); } int a[3]; int main() { int n, m; cin >> n >> m; if (n == 1 && m == 2) { cout << 0 << '\n' << "1 1\n1 2\n1 1"; return 0; } if (n == 2 && m ...
12
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> v; vector<int> adj[n + 1]; int a, b; for (int i = 0; i < n - 1; i++) { cin >> a >> b; adj[a].push_back(b); adj[b].push_back(a); } int max = 0, root, count = 0; for (int i = 1; i <= n; i++) { if ((in...
6
#include <bits/stdc++.h> using namespace std; long long M, X, ans, pri[1000100], tot, num, a[1001000]; bool vis[10000010]; void pre() { for (long long i = 2; i <= 10000000; i++) { if (!vis[i]) { pri[++tot] = i; } for (long long j = 1; j <= tot && pri[j] * i <= 10000000; j++) { vis[pri[j] * i] ...
18
#include <bits/stdc++.h> using namespace std; bool isVowel(char c) { if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' || c == 'y') return true; return false; } int main() { int n; cin >> n; string s; cin >> s; int lastWasVowel = 0; int i = 0; string ans = ""; while (s[i]) { if (l...
0
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 5; int a[maxn], nex[maxn], b[maxn], pos[maxn]; int f[maxn][21], bin[maxn], c[maxn], mn[maxn][21]; char ans[maxn]; void build(int n) { for (int i = 1; i <= n; i++) mn[i][0] = c[i]; for (int j = 1; j <= bin[n]; j++) { for (int i = 1; i + (1 << j...
12
#include <bits/stdc++.h> using namespace std; int vis[200005]; char clr[200005]; int main() { long long n, k; cin >> n >> k; string s; cin >> s; queue<pair<int, int> > q; for (int i = 0; i < n; i++) { if (s[i] == s[(i - 1 + n) % n] || s[i] == s[(i + 1) % n]) { q.push(make_pair(i, 0)); vis[i]...
15
#include <bits/stdc++.h> int main(int argc, char const *argv[]) { int a, b, c; while (scanf("%d%d%d", &a, &b, &c) != EOF) { int mod = a % b * 10; int counter = 1; while (counter < b + 1) { if (mod / b == c) { printf("%d\n", counter); break; } counter++; mod = mod ...
5
#include <bits/stdc++.h> using namespace std; long long int gcd(long long int x, long long int y) { if (y > x) { return gcd(y, x); } if (y == 0) { return x; } return gcd(y, x % y); } bool prime(long long int x) { for (long long int i = 2; i <= sqrt(x); i++) { if (x % i == 0) { return 0; ...
0
#include <bits/stdc++.h> using namespace std; const long double PI = acos(-1.0); const int MAXN = 3000001; int f[MAXN]; void ad(int x) { for (int i = x; i < MAXN; i = (i | (i + 1))) f[i]++; } int gt(int x) { int an = 0; for (int i = x; i >= 0; i = ((i & (i + 1)) - 1)) an += f[i]; return an; } int main() { int...
16
#include <bits/stdc++.h> using namespace std; const int MAXN = 1 << 20, mod = 998244353; int w[2][1111111], S[1111111], T[1111111], n, m, sz, cnt, rev[1111111], cur, gg[1111111], G[1111111], K, a[333333], b[333333], crt, ans; long long c[1111111]; const int maxn = 1000; char buffer[maxn], *s, *t; inline char Get_Ch...
14
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long n, lst = -1, now = -1, ans = 0; cin >> n; cin >> now; n--; while (n--) { lst = now; cin >> now; if (lst > now) ans += (lst - now); } cout << ans << '\n'; return 0...
6
#include <bits/stdc++.h> using namespace std; const long long N = 1e5 + 9; const long long oo = 1e15; const long long mod = 1e9 + 7; struct book { long long u, v, val; } eg[N]; long long n, m, sum = 0ll; long long pr[N], child[N]; vector<vector<pair<long long, long long> > > vi; void dfs(long long pre, long long u) {...
11
#include <bits/stdc++.h> using namespace std; int n, a[111][111], was[111][111], sz[111], m[111]; int main() { ios_base ::sync_with_stdio(0); cin >> n; for (int i = 1; i <= n; i++) { cin >> m[i]; for (int j = 1; j <= m[i]; j++) cin >> a[i][j], was[i][a[i][j]] = 1; } for (int i = 1; i <= n; i++) { ...
5
#include <bits/stdc++.h> using namespace std; const int N = 5e5 + 5; int n, a, b, t; int curt; int orit; char arr[N]; int ans = 0; int curans; int sum[N]; int r; int main() { scanf("%d %d %d %d", &n, &a, &b, &t); orit = t; scanf("%s", arr + 1); sum[0] = 0; for (int i = 1; i <= n; ++i) { sum[i] = sum[i - 1...
11
#include <bits/stdc++.h> using namespace std; long long M = 1000000007; int arr[300005]; int rig[300005][21]; int last[21]; int main() { int n, q; cin >> n >> q; for (int i = 1; i <= n; i++) { cin >> arr[i]; } for (int i = 0; i <= 20; i++) { last[i] = -1; } for (int i = n; i >= 1; i--) { int j...
14
#include <bits/stdc++.h> using namespace std; int main() { char chess[8][8]; for (int i = 0; i < 8; i++) for (int j = 0; j < 8; j++) cin >> chess[i][j]; int min_a = 1e9, min_b = 1e9; for (int j = 0; j < 8; j++) { bool A = 0, B = 0; int a = -1, b = -1, pre_a = min_a, pre_b = min_b; for (int i = 0...
4
#include <bits/stdc++.h> using namespace std; long long read() { long long c = getchar(), Nig = 1, x = 0; while (!isdigit(c) && c != '-') c = getchar(); if (c == '-') Nig = -1, c = getchar(); while (isdigit(c)) x = ((x << 1) + (x << 3)) + (c ^ '0'), c = getchar(); return Nig * x; } const int maxn = 3e6 + 7; l...
15
#include <bits/stdc++.h> const int maxn = 0x3f3f3f3f; const double EI = 2.71828182845904523536028747135266249775724709369995957496696762772407663035354594571382178525166427; const double PI = 3.141592653589793238462643383279; using namespace std; struct s { int a, b, f; } z[110], zz[110]; inline bool comp(s a, s ...
15
#include <bits/stdc++.h> using namespace std; const int N = 400010; const int LOGN = 20; int n; long long dp[N], a[N], sum[N]; int main() { scanf("%d", &n); for (int i = 1; i <= n; ++i) { scanf("%lld", &a[i]); sum[i] = a[i] + sum[i - 1]; } dp[n] = sum[n]; for (int idx = n - 1; idx >= 2; idx--) { d...
14
#include <bits/stdc++.h> using namespace std; const int maxn = 1010; int n, m, dp[maxn][maxn]; char iomap[maxn][maxn]; long long ans = 0; int main() { cin >> n >> m; for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) cin >> iomap[i][j]; for (int i = 1; i <= m; i++) dp[n][i] = 1; for (int i = n - 1; i...
11
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; int a[n]; int sum = 0; for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (a[i] < a[j]) { swap(a[i], a[j]); } } } for (int i = 0;...
1
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); string str; cin >> str; int len = str.length(); char c = str[0]; int cnt = 1; for (int i = 1; i < len; i++) { if (str[i] == c) cnt += 1; else { c = str[i]; cnt = 1; } if (cnt >= 7) { ...
1
#include <bits/stdc++.h> using namespace std; int main() { int t, n, z, x, y, b, v, l; string s; cin >> t; while (t--) { z = 0; cin >> n >> s; for (int i = 0; i < n; i++) { if (s[i] == '1') z++; } if (z == 0) { cout << n << endl; continue; } for (int i = 0; i < n; i...
2
#include <bits/stdc++.h> using namespace std; const int MAXN = 210000; const int MAXK = 19; const int INF = 1e9; const long long MOD = 998244353; vector<int> V[MAXN]; int N, a, b, Q; vector<int> qry; int RQ; pair<int, int> ask() { ++RQ; assert(RQ <= 13); cout << "? " << (int)qry.size() << ' '; for (auto i : qry...
16
#include <bits/stdc++.h> using namespace std; double dp[1 << 20]; double ans[21]; void solve(int K, vector<double> p) { int N = p.size(); if (K >= N) { for (int i = 0; i < N; i++) ans[i] = 1.0; return; } dp[0] = 1.0; for (int set = 0; set < (1 << N); set++) { double q = 0; for (int j = 0; j < ...
16
#include <bits/stdc++.h> using namespace std; const long long MXN = 3e5 + 10; long long n, p, t; long long A[MXN], dp[MXN]; bool bad[MXN]; vector<long long> ANS; bool check(long long x) { for (int i = 1; i <= n; i++) { if (x < A[i]) return 0; x++; } return 1; } int main() { ios::sync_with_stdio(0); ci...
15
#include <bits/stdc++.h> using namespace std; void merge(int arr[][2], int l, int m, int r) { int i, j, k; int n1 = m - l + 1; int n2 = r - m; int L[n1][2], R[n2][2]; for (i = 0; i < n1; i++) { L[i][0] = arr[l + i][0]; L[i][1] = arr[l + i][1]; } for (j = 0; j < n2; j++) { R[j][0] = arr[m + 1 +...
3
#include <bits/stdc++.h> using namespace std; vector<pair<int, int>> a[5]; int main() { int k, m; static int pw[9]; pw[0] = 1; for (int i = 1; i <= 8; i++) pw[i] = pw[i - 1] * 10; cin >> k >> m; for (int d = 0; d <= 9; d++) { a[1].push_back(make_pair(d, d)); if (d) a[1].push_back(make_pair(d, -d)); ...
19
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); int n, k, sum, res, c; cin >> n >> k; res = 240 - k, sum = 0, c = 0; for (int i = 1; i <= n; i++) { sum += 5 * i; if (sum > res) break; c = c + 1; } cout << c << "\n"; }
0
#include <bits/stdc++.h> using namespace std; int main() { int n, k; while (cin >> n >> k) { if (n < 4) { cout << -1 << endl; continue; } if (k != 2 && k != 3) { cout << -1 << endl; continue; } if (k == 2) { if (n == 4) { cout << -1 << endl; continue...
16
#include <bits/stdc++.h> using namespace std; int n; long long a[1001]; long long b[1001]; int main() { cin >> n; for (int c = 0; c < n; c++) { cin >> a[c]; } for (int c = 0; c < n; c++) { cin >> b[c]; } long long maxx = 0; for (int c = 0; c < n; c++) { maxx |= a[c]; } long long maxx2 = 0;...
1
#include <bits/stdc++.h> using namespace std; struct Circle { pair<double, double> center; int radius; Circle() {} Circle(pair<double, double> center, int radius) : center(center), radius(radius) {} }; const double PI = acos(-1); pair<double, double> O; Circle c[100005]; int v, T, n; double reach; vector<...
17
#include <bits/stdc++.h> using namespace std; vector<pair<int, int> > edges[2000 + 1]; bitset<2000> a[2000]; int parent[2000]; char s[2000 + 1]; int Find(int i) { return (parent[i] == i) ? i : parent[i] = Find(parent[i]); } bool Union(int i, int j) { i = Find(i), j = Find(j); if (i == j) { return 0; } if (i...
25
#include <bits/stdc++.h> void doit(int); int main() { int N; scanf("%d", &N); printf("%.0lf\n", (double)N * ((double)N + 1)); doit(N); printf("\n"); return 0; } void doit(int n) { int i = 0, p = 0; while ((1 << (i + 1)) - 1 <= n) i++; p = (1 << i) - 1; if (p == n) for (i = 0; i <= n; i++) ...
9
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c; cin >> a >> b >> c; int k = min(a, min(b / 2, c / 4)); cout << k + k * 2 + k * 4; }
0
#include <bits/stdc++.h> using namespace std; struct edge { int v, w, c, nxt; } e[2000005]; int n, m, h[100005], tot = 1, s, t, dis[100005], vis[100005], pt, p[100005], las[100005][2]; int q[5000005], head, tail, g[105][105], f[105][105]; int add(int u, int v, int w, int c) { e[++tot].v = v; ...
19
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef pair<int, int> pi; typedef pair<ll,ll> pl; typedef vector<int> vi; typedef vector<ld> vd; typedef vector<ll> vl; typedef vector<pi> vpi; typedef vector<pl> vpl; #define loop(i,a,n) for(int i=a;i<n;i++) #define rloop(i...
0
#include <bits/stdc++.h> using namespace std; int n, m, ta, tb, par[100005], anc[100005], cnt[100005], ans[100005]; vector<int> va[100005], vb[100005], vc[100005]; bool v[100005]; int find(int a) { if (par[a] == a) return a; return par[a] = find(par[a]); } int dfs(int a, int b) { par[a] = a; anc[a] = a; for (...
11
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 20; int A[maxn], C[maxn]; struct P { int first, second; P(int a = 0, int b = 0) : first(a), second(b) {} bool operator<(const P& p) const { return first < p.first; } }; P B[maxn]; map<int, int> dp; int res[maxn], res1[maxn]; queue<int> Q[maxn]; ...
13
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; cout << (n / k + 1) * k << endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; int A[1000000]; int S[1000000]; int T[1000000]; int P[1000000]; long long N, K, L; long long LN; long long R = 0; int TL = 0; long long mul(long long a, long long b) { return (a * b) % 1000000007; } long long add(long long a, long long b) { return (a + b) % 1000000007; } vo...
13
#include <bits/stdc++.h> using namespace std; int aa[110]; int main() { int n, k; scanf("%d%d", &n, &k); for (int i = 0; i < n; i++) { scanf("%d", &aa[i]); } sort(aa, aa + n); int op; for (int i = n - 1; i >= 0; i--) { if (k % aa[i] == 0) { op = k / aa[i]; break; } } printf("%d...
1
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); ; int i, j, k, n, a, x, ans; set<int> st; vector<int> vec; cin >> n; for (int i = 0; i < n; i++) { cin >> x; vec.push_back(x); } sort(vec.begin(), vec.end()); for (int i = 0; i < n; i++) { ...
0
#include <bits/stdc++.h> using namespace std; const long long int inf = 1e9 + 5; const long long int MOD = 998244353; using namespace std; void solve() { long long int n; cin >> n; vector<int> res; int s = (int)sqrtl(n); for (int i = 0; i <= s; ++i) { res.push_back(i); } for (int i = 1; i <= s; ++i) {...
6
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 10, M = 3010, mod = 998244353; long long a[N], w[N]; long long dp[M][M]; long long inverse(long long x); long long pwr(long long x, long long e); int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, m; cin >> n >> m; long long b...
15
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; long long n, a[N], sum, mx, ans; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; sum += a[i]; if (a[i] > mx) mx = a[i]; } cout << max(mx, (long long)cei...
8
#include <bits/stdc++.h> using namespace std; int main() { int n, p; cin >> n >> p; string s; cin >> s; char c = 'a'; std::vector<char> allChars; for (int i = 1; i <= p; ++i) { allChars.push_back(c); c++; } int ptr = s.size() - 1; int end = s.size() - 1; while (ptr >= 0) { if (ptr == e...
9
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; vector<int> a(n); for (auto &it : a) cin >> it; int ans = 0; ans += a[0] == 1; for (int i = 1; i < n; ++i) { if (a[i] == 0) { continue; } int j = i; ...
7
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const long long INFF = 0x3f3f3f3f3f3f3f3fll; const long long M = 998244353; const long long maxn = 1e6 + 7; const double pi = acos(-1.0); const double eps = 1e-10; long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } template...
19
#include <bits/stdc++.h> using namespace std; int n; long long f[710][11][710][2], r; char s[710]; int main() { cin >> s; n = strlen(s); for (int i = 0; i < 10; i++) f[0][i][0][0] = 1; for (int i = 0; i < n; i++) for (int j = 1; j < 10; j++) for (int k = 0; k <= i; k++) for (int m = 0; m < 2; ...
20
#include <bits/stdc++.h> using namespace std; const int N = 8; int statue[N][N][N]; char mapa[N][N]; int dx[] = {1, 1, 1, 0, -1, 1, -1, 0, 0}; int dy[] = {1, 0, -1, 1, -1, 0, 1, 1, 0}; int ans = 0; void dfs(int first, int second, int deep) { if (deep >= N) { ans = 1; return; } if (first >= N || first < 0 ...
7
#include <bits/stdc++.h> using namespace std; const int inf = 163577857; const long long linf = 1ll * inf * inf; const int N = 1000000 + 7; const int M = 20; const int multipleTest = 0; long long calc(long long index, long long n) { if (index & 1) return (index + 1) / 2; long long cur = (n + 1) / 2; long long m =...
9
#include <bits/stdc++.h> using namespace std; vector<int> a[52]; int main() { int n, k; cin >> n >> k; for (int i = 1; i <= n; i++) { int x; cin >> x; for (int j = 0; j < x; j++) { int p; cin >> p; a[i].push_back(p); } sort(a[i].begin(), a[i].end()); } int cnt = 0; vect...
2
#include <bits/stdc++.h> using namespace std; int N, k; vector<vector<int>> E; long long weight[200 + 10]; long long dp[200 + 10][200 + 10]; void dfs(int v, int bef) { for (int i = 0; i < E[v].size(); i++) { int son = E[v][i]; if (son == bef) continue; dfs(son, v); } dp[v][0] += weight[v]; for (int ...
14