solution
stringlengths
52
181k
difficulty
int64
0
6
#include <bits/stdc++.h> using namespace std; int x; string p, t; struct node { int parentchar; node* parent; int index; vector<int> terminal; node* go[26]; node* suf; node* supersuf; node() { index = 0; suf = NULL; supersuf = NULL; for (int i = 1; i < 10; i++) { go[i] = NULL; ...
6
#include <bits/stdc++.h> using namespace std; void XsliferX() { ios::sync_with_stdio(0); ios_base::sync_with_stdio(0); cin.tie(0), cout.tie(0); } 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() { XsliferX(); int n, m, x, y, c = 0, mx = -1; cin >> n >> m; ...
1
#include <bits/stdc++.h> const double Pi = 3.14159265; const int N = 2e5 + 10; const unsigned long long base = 163; const long long INF = 0x3f3f3f3f3f3f3f3f; const int mod = 1e8; const double eps = 1e-9; const double pi = acos(-1); using namespace std; long long a, b, c, d; string ss = "Impossible\n"; int main() { ci...
2
#include <iostream> #include <algorithm> #include <iomanip> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <math.h> #include <vector> #include <string> #include <queue> #include <deque> #include <list> #include <set> #include <unordered_set> #include <map> #include <unordered_map> #include <bitset>...
0
#include <bits/stdc++.h> using namespace std; int suff[4010]; char str[4010]; int pr[4010]; int N; int ways(int sum) { int i, j, ct; ct = 0; j = N; for (i = N - 1; i >= 0; --i) { while (j > i && suff[i] - suff[j] > sum) --j; if (suff[i] - suff[j] == sum) ct += j - max(i, pr[j]); } return ct; } int A...
1
#include <bits/stdc++.h> bool flag[2000][2000]; struct node { int x; int y; }; node point[3001]; int main() { int n; memset(flag, false, sizeof(flag)); scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d %d", &point[i].x, &point[i].y); flag[point[i].x + 1000][point[i].y + 1000] = true; } i...
2
#include <bits/stdc++.h> namespace solve { int V[410]; int n, ans = -1; int read() { int f = 1, x = 0; char c; while ((c = getchar()) < '0' || c > '9') if (c == '-') f = -1; while (c <= '9' && c >= '0') { x = (x << 3) + (x << 1) + (c ^ 48); c = getchar(); } return f * x; } void init() { n = re...
5
#include <bits/stdc++.h> #pragma GCC optimize("-O3") using namespace std; long long MOD = 998244353; double eps = 1e-6; long long mpow(long long a, long long b) { if (a == 0) return 0; if (b >= (MOD - 1)) b %= (MOD - 1); if (b == 0) return 1; long long t1 = mpow(a, b / 2); t1 *= t1; t1 %= MOD; if (b % 2) ...
5
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 10, inf = 1e9 + 10, mod = 998244353; long long ans = 0; int c[N], tp[N], tp1[N], was[N], bad_inside[N]; vector<pair<int, int>> rib[N]; vector<int> a[N], el[N], need_check, na[N], with_type[N]; bool dfs(int u, int cl, int type) { tp[u] = cl; for (auto...
3
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c = 0; cin >> a >> b; while (a <= b) { a = 3 * a; b = 2 * b; c++; } cout << c; }
1
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; int ans(0); for (int i(0); i < s.size(); i++) { int frc(0), nrst(0), nrdr(0), nr0(0); for (int j(i); j < s.size(); j++) { if (s[j] == ')') { frc--; if (frc < 0 && nrst) nrst--, nrdr++, frc += 2; } ...
1
#include <bits/stdc++.h> using namespace std; long long absk(long long x) { if (x < 0) { return -x; } return x; } int32_t main() { long long n, k; cin >> n >> k; string s; cin >> s; long long a[n]; for (long long i = 0; i < n; i++) { a[i] = (s[i] - '0'); } for (long long i = k; i < n; i++)...
1
#include <bits/stdc++.h> using namespace std; const int INF = 1e9 + 7; const int MXN = 3e5 + 7; map<pair<int, int>, int> cnt; long long ans; int n, p; int d[MXN]; vector<int> deg; int main() { scanf("%d%d", &n, &p); for (int i = 0; i < n; i++) { int x, y; scanf("%d%d", &x, &y); if (y > x) swap(x, y); ...
4
#include <bits/stdc++.h> using namespace std; long long k, b, n, t; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); cin >> k >> b >> n >> t; long long nr = 1; for (int i = 1; i <= n; ++i) { nr = nr * k + b; if (nr >= ...
1
#include <bits/stdc++.h> using namespace std; int n; double s, l = 0, u = 1000000007LL; int main() { cin >> n; int cur; for (int i = 0; i < n; i++) { cin >> s; if (i == n - 1) cur = s; l = max(l, s / (i + 1)); u = min(u, (s + 1) / (i + 1)); } while (cur++) { double x = 1.0 * (cur + 1) / (n...
3
#include <bits/stdc++.h> using namespace std; template <typename T, typename V> void bugp(const pair<T, V> &x) { if (0) cerr << '{' << x.first << ", " << x.second << '}' << endl; } template <typename T, typename U, typename V> void bugpp(const pair<T, pair<U, V> > &x) { if (0) cerr << '{' << x.first << ", {" <<...
4
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; if (s.length() < 4) { cout << 0; return 0; } string bear = "bear"; long long int count = 0; int start = 0; for (int i = 0; i < s.length() - 3;) { if (s.substr(i, 4) == bear) { long long left = 0; long ...
2
#include <bits/stdc++.h> using namespace std; priority_queue<long long> q; inline long long read() { char c = getchar(); long long x = 0, f = 1; while (!isdigit(c) && c != '-') c = getchar(); if (c == '-') { f = -1; c = getchar(); } while (isdigit(c)) { x = (x << 3) + (x << 1) + c - '0'; c =...
3
#include <bits/stdc++.h> using namespace std; int main() { int k, n, w; cin >> k >> n >> w; int temp = 0, b; for (int i = 1; i <= w; ++i) { temp += i * k; } if (temp < n) cout << 0 << endl; else cout << temp - n << endl; return 0; }
1
#include <bits/stdc++.h> using namespace std; int ans, an, cst[100], tmp, pos[100], pt, sum; string s; inline int pd(int u, int v) { int i, res = 0; for (i = 0; i < s.size(); i++) { if (i == u || i == v) continue; if (s[i] != '0') return res; res++; } return res; } int main() { memset(cst, 0x3f, s...
5
#include <iostream> using namespace std; int main() { char c; int ans = 0; while (cin >> c) { if (c == '1') ans++; } cout << ans << endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; int main() { size_t pos, t; char s[100000]; string whitespaces(" \t\f\v\n\r?-+=_}][{\\|./,;\':\"<>~!@#$%^&*()"); cin.getline(s, 10000); string str(s), x; pos = str.find_last_not_of(whitespaces); string v("aeiouAEIOUyY"); x = str[pos]; t = x.find_last_of(v)...
1
#include<cstdio> #include<vector> #include<algorithm> #include<queue> using namespace std; struct edge{ int to,cost; edge(int to,int cost): to(to),cost(cost){} edge(){} }; struct visit{ int pos,total,b; visit(int pos,int total,int b): pos(pos),total(total),b(b){} visit(){} b...
0
#include <bits/stdc++.h> using namespace std; const int MAXN = 3e5 + 100; const int oo = 1e9 + 7; int N; int H[MAXN]; deque<int> dq; int L[MAXN], R[MAXN], l[MAXN], r[MAXN]; int d[MAXN]; vector<int> G[MAXN]; void Dijkstra(int u) { for (int i = (1), _b = (N + 1); i <= _b; ++i) d[i] = +oo; d[u] = 0; priority_queue<p...
4
#include <bits/stdc++.h> using namespace std; void solve() { long long int n; cin >> n; string s; cin >> s; long long int temp = 0; long long int ans = 2; for (long long int i = 0; i < n; i++) { if (s[i] == '(') temp++; else temp--; if (temp < -1) { cout << "No" << '\n'; ...
3
#include <bits/stdc++.h> using namespace std; inline int mul(int a, int b) { return int(a * 1ll * b % 998244353); } inline int norm(int a) { if (a >= 998244353) a -= 998244353; if (a < 0) a += 998244353; return a; } inline int binPow(int a, int k) { int ans = 1; while (k > 0) { if (k & 1) ans = mul(ans, a...
4
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; const int INF = 0x3f3f3f3f; const double eqs = 1e-9; char st[110000]; int n, k, a[110000], sum[110000]; long long fac[110000], inv_fac[110000]; long long qsm(long long n, long long k) { long long ans = 1; while (k > 0) { if (k & 1) ans = ans...
3
#include <bits/stdc++.h> using namespace std; int x[100][100]; int main() { string s, t; char a, b; int c, num; memset(x, 10000, sizeof(x)); for (int i = 0; i < 26; ++i) { x[i][i] = 0; } cin >> s >> t; cin >> num; for (int i = 0; i < num; ++i) { cin >> a; cin >> b; cin >> c; x[a - ...
2
#include <bits/stdc++.h> using namespace std; int main() { int n, m, x, y, u, v; pair<int, int> p; multiset<pair<int, int> >::iterator iter, busca; multiset<int>::iterator iter2, busca2; while (cin >> n >> m) { multiset<pair<int, int> > mark, tapa; multiset<int> solo, dim; while (n--) cin >> x >> ...
2
#include <algorithm> #include <assert.h> #include <bitset> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <fstream> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <ve...
3
#include <bits/stdc++.h> using namespace std; int n, a, x, b; int main() { cin >> n >> x; for (int i = 0; i < n; i++) { cin >> a; b += a; } if (b < 0) b *= -1; cout << (b + x - 1) / x; }
1
#include<bits/stdc++.h> using namespace std; #define int long long void solve() { int n,m; cin>>n>>m; int ans[n]; for(int i = 0;i<n;i++) ans[i] = -1; int dir[n]; int arr[n]; set<pair<int,int>>odd,even; for(int i = 0;i<n;i++) { cin>>arr[i]; } for(int i = 0;i<n;i++) { char ch;cin>>c...
3
#include <bits/stdc++.h> using namespace std; int main(){ int a,b,c,d; cin >>b >>a; d=a*101/100; c=d; for(int i=1;i<=b;i++){ c=c*100; } cout<<c; }
0
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1); inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; } long long Add(long long a, long long b) { long long ret = a + b; if (ret >= 1000000007) ret -= 1000000007; return ret; } long long subtract(long long a, long long b) { long...
5
#include <bits/stdc++.h> using namespace std; int n, t; long long dp[25][15][15][6][6]; long long fun(int i, int h, int u, int y1, int y2) { if (i == 0) { if (h == 0 && u == 0) return 1; else return 0; } if (dp[i][h][u][y1][y2] != -1) return dp[i][h][u][y1][y2]; long long ret = 0; for (int...
5
#include <bits/stdc++.h> using namespace std; inline bool checkBit(long long n, long long i) { return n & ((long long)1 << i); } inline long long setBit(long long n, long long i) { return n | ((long long)1 << i); ; } inline long long resetBit(long long n, long long i) { return n & (~((long long)1 << i)); } inli...
4
#include <bits/stdc++.h> using namespace std; template <class T> T gcd(T a, T b) { return (b == 0) ? a : gcd(b, a % b); } const unsigned int MOD = 1000000007; long long int inf = 1000000000000000000; template <class T> T power(T a, long long int n) { T res = 1; while (n > 0) { if (n % 2) res = (res * a) % MOD...
6
#include <bits/stdc++.h> using namespace std; typedef long long i64; i64 N, A, B; int main() { scanf("%lld%lld%lld", &N, &A, &B); printf("%lld\n", (B-A)&1?min(A, N+1-B)+(B-A-1)/2:(B-A)/2); return 0; }
0
#include <bits/stdc++.h> using namespace std; int N, M, Q; pair<pair<int, int>, pair<int, int> > E[1000005]; int par[2005]; int find_parent(int x) { if (par[x] == x) return x; return par[x] = find_parent(par[x]); } int go(int li, int ri) { for (int i = 1; i <= 2 * N + 1; i++) par[i] = i; for (int i = M - 1; i >...
4
#include <bits/stdc++.h> using namespace std; int main() { int n, f; cin >> n >> f; int d, i, c, count = 0, car = 0; vector<pair<int, int> > v; int h[4000] = {0}; int dc[n]; for (i = 0; i < n; i++) { cin >> d >> c; h[d] += c; dc[i] = d; } int n2 = *max_element(dc, dc + n); for (i = 1; i ...
2
#include <bits/stdc++.h> long long int m,n,z,ans; using namespace std; long long int vp[200010],sum; map<long long int,long long int>q; int main() { int n,k; scanf("%d %d",&n,&k); for(int i=1;i<=n;i++) { scanf("%lld",&vp[i]); vp[i]+=vp[i-1]-1; } for(int i=1;i<=n;i++) vp[i...
0
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); long long n; cin >> n; long long l = 0, r = 1e9; while (l < r - 1) { long long c = (r - l) / 2 + l; if (n - 2 * c - c * (c - 1) / 2 * 3 >= 0) { l = c; } else { r = c; } } while (l > 0 && (n...
3
#include <bits/stdc++.h> using namespace std; int p[1000], r[1000], col[1000]; int getp(int v) { if (p[v] == v) return v; int pr = getp(p[v]); col[v] ^= col[p[v]]; p[v] = pr; return p[v]; } void join(int a, int b, int d) { if (r[a] > r[b]) swap(a, b); else if (r[a] == r[b]) ++r[b]; p[a] = b; c...
4
#include<stdio.h> int main() { int A, B; scanf("%d %d", &A, &B); printf("%d", (A * 3 + B) / 2); }
0
#include <bits/stdc++.h> using namespace std; struct debugger { static void call(string::iterator it, string::iterator ed) {} template <typename T, typename... aT> static void call(string::iterator it, string::iterator ed, T a, aT... rest) { string b; for (; *it != ','; ++it) if (*it != ' ') b += *i...
2
#include <bits/stdc++.h> using namespace std; mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); long long int arr[1000009], brr[1000009], crr[67]; std::vector<long long int> v[1000009], v1[70]; long long int solve(long long int l, long long int r, long long int bit) { long long int lo = 2, hi = crr...
3
#include <bits/stdc++.h> using namespace std; int n, maxn, pos, len; int r[4001000]; long long ll[2010000], rr[2010000]; long long sum; char ss[2010000], s[4001000]; void pre() { scanf("%d%s", &len, ss + 1); s[0] = '$', s[1] = '#', n = (len << 1) | 1; for (register int i = 1; i <= len; i++) s[i << 1] = ss[i],...
5
#include<bits/stdc++.h> using namespace std; const int MOD = (int)1e9+7; map<pair<long long, int>, int> M; int DP(long long N, int k) { if(N<0) return 0; if(N>(2LL<<(k+1))-2) N = (2LL<<(k+1))-2; if(N == 0) return 1; auto it = M.find(make_pair(N, k)); if(it != M.end()) return it->second; long long ans = 0; ...
0
#include <bits/stdc++.h> using namespace std; #define for_(i,a,b) for(int i=a;i<b;i++) #define minit(a,b) memset(a,b,sizeof(a)) int N; int l[300]; int MOD = 256; int r[300], o[300]; void make_str(int S, int A, int C) { minit(r,0); minit(o,0); r[0] = (A*S + C) % MOD; for_(i,1,N) r[i] = (A * r[i - 1] + C) % MOD; ...
0
#include <bits/stdc++.h> using namespace std; long long fibs[111]; int cnt; const long long lim = 1000000000000000000LL; void pre() { cnt = 0; fibs[++cnt] = 1; fibs[++cnt] = 2; while (true) { cnt++; fibs[cnt] = fibs[cnt - 1] + fibs[cnt - 2]; if (fibs[cnt] > lim) break; } --cnt; } long long n; lo...
4
#include<bits/stdc++.h> using namespace std; #define int long long signed main(){ int a,b,c,d=0,e=0; cin>>a>>b>>c; if(a%c==0) d=1; cout<<b/c-a/c+d<<"\n"; }
0
#include <bits/stdc++.h> using namespace std; const int MAXN = 2e5 + 100; const int MAMX = 900; const int MOD = 1e9 + 7; const long long INF = 1e18; int r, g, h, dp[MAXN][2], ans; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); ; cin >> r >> g; h = 1; while ((h + 1) * (h + 2) / 2 <= r +...
4
#include <bits/stdc++.h> using namespace std; struct Edge { int from, to, cost; Edge() : from(), to(), cost() {} Edge(int _from, int _to, int _cost) : from(_from), to(_to), cost(_cost) {} void read() { scanf("%d%d%d", &from, &to, &cost); from--; to--; } bool operator<(const Edge &A) const { retu...
4
#include <bits/stdc++.h> using namespace std; int main() { int n, i, j, m; double a, b, mini = 1000000; cin >> n >> m; for (i = 0; i < n; i++) { cin >> a >> b; mini = min(mini, (double)a / b); } printf("%.8lf", mini * m); return 0; }
1
#include <bits/stdc++.h> using namespace std; long long tree[2][1000001]; int n; pair<long long, long long> a[1000001]; int b[1000001]; long long find(int ind, int t) { if (ind == 0) return 0; return (tree[t][ind] + find(ind - (ind & -ind), t)); } void insert(int ind, long long num, int t) { if (ind > 1000000) re...
5
#include <bits/stdc++.h> using namespace std; const int Size = 1024; const int mod = 998244353; const int inf = 0x3f3f3f3f; const int maxn = 2e6 + 15; int head[maxn]; int ver[maxn]; int nxt[maxn]; int tot; void add(int x, int y) { ver[++tot] = y; nxt[tot] = head[x]; head[x] = tot; } int in[maxn]; int num[maxn]; i...
5
#include <bits/stdc++.h> using namespace std; const int inf = 0x20202020; const int mod = 1000000007; const double eps = 1e-9; const double pi = 3.1415926535897932384626; int powmod(int a, int b) { int res = 1; a %= mod; for (; b; b >>= 1) { if (b & 1) res = (long long)res * a % mod; a = (long long)a * a ...
3
#include <bits/stdc++.h> using namespace std; stringstream ss; string s[40], res = ""; int n; int ok(string x) { for (int i = 0; i < n; i++) if (s[i].find(x) != s[i].npos) return 0; return 1; } void bt(string x) { for (char i = 'a'; i <= 'z'; i++) if (ok(x + i)) { if (!res.size() || x.size() + 1 < r...
2
#include <bits/stdc++.h> using namespace std; void __print(int x) { cerr << x; } void __print(long x) { cerr << x; } void __print(float x) { cerr << x; } void __print(double x) { cerr << x; } void __print(unsigned x) { cerr << x; } void __print(long long x) { cerr << x; } void __print(long double x) { cerr << x; } void...
1
#include <bits/stdc++.h> using namespace std; void func() { int n; cin >> n; int last = 0; bool sorted = true; for (int i = 0; i < n; ++i) { int x; cin >> x; if (x < last) sorted = false; last = x; } bool zero = false; bool one = false; for (int i = 0; i < n; ++i) { int x; cin ...
2
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; struct mat { int a[2][2]; mat() { memset(a, 0, sizeof(a)); } mat(int) { memset(a, 0, sizeof(a)); a[0][0] = a[1][1] = 1; } }; mat operator+(const mat &a, const mat &b) { mat c = mat(); for (int i = 0; i < 2; ++i) { for (int j ...
3
#include <bits/stdc++.h> using namespace std; const int maxn = 500000; struct arc { int u,v,w; bool used,mark,del; arc(int x = 0,int y = 0,int z = 0) { u = x; v = y; w = z; mark = del = used = false; } bool operator<(const arc &tmp) const { ...
0
#include <bits/stdc++.h> using namespace std; int const N = 1e5 + 100; map<string, int> mp; int n, k, m; string s[N]; int cost[N]; int main() { cin >> n >> k >> m; for (int i = 0; i < n; i++) { cin >> s[i]; } for (int i = 0; i < n; i++) { cin >> cost[i]; } for (int i = 0, x; i < k; i++) { cin >>...
2
#include <bits/stdc++.h> using namespace std; long long power(long long x, long long y); long long mpower(long long x, long long y, long long p); long long modInv(long long a, long long m); long long gcdExtended(long long a, long long b, long long *x, long long *y); bool isPrime(long long n); long long id[200001], siz[...
6
#include<iostream> #include<cstdio> #include<cstring> namespace nmy { template<typename T>inline void check_max(T a,T &b){if(a>b)b=a;} template<typename T>inline void check_min(T a,T &b){if(a<b)b=a;} const int N=101000,M=N*2,K=20; int begin[N],next[M],to[M]; int kjd[N],hdd[N]; int n,e,ans; void add(int x,int y,b...
0
#include <bits/stdc++.h> int IntMaxVal = (int)1e20; int IntMinVal = (int)-1e20; long long LongMaxVal = (long long)1e20; long long LongMinVal = (long long)-1e20; using namespace std; template <typename T> struct argument_type; template <typename T, typename U> struct argument_type<T(U)> {}; template <typename T1, typena...
2
#include <bits/stdc++.h> using namespace std; int64_t dx[] = {0, 0, 1, -1, 1, 1, -1, -1}; int64_t dy[] = {1, -1, 0, 0, 1, -1, 1, -1}; int64_t gcd(int64_t n, int64_t m) { return m ? gcd(m, n % m) : n; } int64_t lcm(int64_t n, int64_t m) { return n / gcd(n, m) * m; } struct debugger { static void call(string::iterator ...
1
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") using namespace std; const int mxn = 2e5; int a[mxn]; char s[mxn]; void subMain() { long long int n, c0, c1, h, ans = 0; cin >> n >> c0 >> c1 >> h; cin >> s + 1; for (long long int i = 1; i <= n; i++) { if (s[i] == '0') { ans += min(c0, c1 + h); ...
1
#include <bits/stdc++.h> using namespace std; vector<int> getdig(int x) { vector<int> ans; while (x) { ans.push_back(x % 10); x /= 10; } return ans; } int main() { vector<long long> p10(30); p10[0] = 1; for (int i = 1; i < p10.size(); i++) p10[i] = (p10[i - 1] * 10) % 998244353; ios::sync_with_s...
4
#include <bits/stdc++.h> using namespace std; const int INF = 1000001; const long long mod = 1000000007; bool isprime(long long n) { for (long long i = 2; i * i <= n; ++i) { if (n % i == 0) { return false; } } return true; } long long factorial(long long n) { return (n == 1 || n == 0) ? 1 : n * fa...
1
#include <bits/stdc++.h> using namespace std; int main() { long long n, m, i, t, v, x, y, q, add = 0; cin >> n >> m; vector<long long> a(n); for (i = 0; i < n; i++) cin >> a[i]; for (i = 1; i <= m; i++) { cin >> t; if (t == 1) { cin >> v >> x; a[v - 1] = x - add; } if (t == 2) { ...
2
#include <bits/stdc++.h> namespace IO { char buf[100]; } template <typename T> inline void qr(T &x) { char ch = getchar(), lst = ' '; while (ch > '9' || ch < '0') lst = ch, ch = getchar(); while (ch >= '0' && ch <= '9') x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar(); if (lst == '-') x = -x; } template ...
1
#include<bits/stdc++.h> using namespace std; typedef long long int ll; int main(){ int a,b;cin >> a >> b; for(int i = 1;i <= 1300;i++){ if(int(i * 0.08) == a && int(i * 0.1) == b)return cout << i, 0; } cout << -1; }
0
#include <bits/stdc++.h> using namespace std; const int MAX = 110; int n, m; int G[MAX][MAX]; vector<int> v_row; vector<int> v_col; void find_row_max_min(int r, int& v_max, int& v_min) { for (int c = 0; c < m; ++c) { v_max = max(v_max, G[r][c]); v_min = min(v_min, G[r][c]); } } void find_col_max_min(int c, ...
1
#include <bits/stdc++.h> using namespace std; long long dp[5100][5100]; long long factor[1000001]; long long fact(long long n); long long power(long long a, long long b, long long f1) { long long x = 1, y = a; while (b > 0) { if (b % 2 == 1) { x = (x * y); if (x > f1) x %= f1; } y = (y * y);...
1
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; deque<char> d; for (int i = 0; i < s.size(); ++i) { d.push_back(s[i]); } s.clear(); cin >> s; int n = 1; for (int i = 0; i < s.size(); ++i) { if (s[i] == d.front()) { d.pop_front(); n++; } } cout...
1
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 100; struct edge { int u, v, len; edge(int U, int V, int Len) : u(U), v(V), len(Len) {} }; vector<pair<int, int> > ve[maxn]; vector<edge> g; int n, m, in[maxn], num[maxn]; void init() { scanf("%d%d", &n, &m); for (int i = 1; i <= m; i++) { ...
5
#include<iostream> #include<sstream> #include<algorithm> #include<climits> #include<cmath> #include<cstdio> #include<cstdlib> #include<ctime> #include<cfloat> #include<functional> #include<map> #include<string> #include<cstring> #include<vector> #include<queue> #include<stack> #include<deque> #include<set> #include<bit...
0
#include <bits/stdc++.h> using namespace std; template <typename T> T getint() { T x = 0, p = 1; char ch; do { ch = getchar(); } while (ch <= ' '); if (ch == '-') p = -1, ch = getchar(); while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar(); return x * p; } mt19937 gen(chrono::system_cl...
1
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a[n]; for (int i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); int ans[n]; int x = 0, y = n - 1; for (int i = 0; i < n; i++) { if (i % 2 == 0) { ans[x] = a[i]; x++; } else { ans[y] = a[i]; y--...
3
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; #define fi first #define se second #define mp make_pair #define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); const int N = (int)1e5 + 9; vector<pii> L[N]; vector<pii> R[N]; int x[N]; int y[N]; bool lf[N]; ...
0
#include <bits/stdc++.h> int main() { long long int n, temp = 1, now; long long int ans = 0; scanf("%lld", &n); now = n; for (long long int i = 2; now > 1; i <<= 1) { ans += (now / 2) * temp; now -= now / 2; temp <<= 1; } printf("%lld\n", ans); }
5
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 7; long long f[maxn], g[maxn], s = 0; int a[maxn], n, n_ch[maxn] = {}; vector<int> adj[maxn]; bool alls = 0; 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) { long l...
2
#include <bits/stdc++.h> using namespace std; int main() { long long a, b; cin >> a >> b; long long count = 0; long long l = 1; for (long long i = 0; i <= 44721; i++) { long long k = 1; for (long long j = 0; j <= 1259; j++) { if (k * l >= a && k * l <= b) { count++; } k *= 3;...
1
#include <bits/stdc++.h> using namespace std; int main() { vector<int> F(100); int n; cin>>n; F[0]=1; F[1]=1; for(int i=2;i<=n;i++){ F[i]=F[i-2]+F[i-1]; } cout<<F[n]<<'\n'; return 0; }
0
#include <bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<int, int>; int main() { cin.tie(0); ios_base::sync_with_stdio(false); cout << fixed << setprecision(10); int a, b; while (cin >> a >> b) { int deg[100] = {}; deg[0]++; deg[1]++; deg[a - 1]++; deg[b - 1]++; ...
0
#include <bits/stdc++.h> using namespace std; const int MAX_N = 110; char arr[MAX_N]; int n, d, ans, t, l; void _operation() { for (int i = 1; i + d < n; i = i) { for (int j = i + d; j > i; j--) { if (arr[j] == '1') { ans++; i = j; j = i; t++; } } if (t == 1) { ...
1
#include <bits/stdc++.h> using namespace std; template <class htpe, class cmp> using heap = priority_queue<htpe, vector<htpe>, cmp>; template <class htpe> using min_heap = heap<htpe, greater<htpe> >; template <class htpe> using max_heap = heap<htpe, less<htpe> >; const int INF = 1791791791; const long long INFLL = 1791...
2
#include <vector> #include <list> #include <map> #include <set> #include <deque> #include <queue> #include <stack> #include <bitset> #include <algorithm> #include <functional> #include <numeric> #include <utility> #include <sstream> #include <fstream> #include <iostream> #include <iomanip> #include <cstdio> #include <c...
0
#include <bits/stdc++.h> using namespace std; int n, k, c[30]; string s; int main() { cin >> n >> k; cin >> s; for (int i = 0; i < n; ++i) { c[s[i] - 'A']++; } int ans = 1e9; for (int i = 0; i < k; ++i) { ans = min(ans, c[i]); } cout << ans * k << endl; return 0; }
1
#include <bits/stdc++.h> using namespace std; bool con[110][110]; int main() { int k; cin >> k; int n; con[0][1] = con[1][0] = true; for (n = 2; k and n <= 100; n++) { for (int i = 0; k >= i and i < n; i++) { con[i][n] = con[n][i] = true; k -= i; } } cout << n << endl; for (int i = 0...
3
#include <bits/stdc++.h> using namespace std; const int maxn = 305; int n, bol, v, ii; int head[maxn], geshu[maxn], pan[maxn], vis[maxn], ans[100000], flag[maxn][maxn]; struct tree { int e, ne; } edg[maxn]; struct node { int temp; int dd[maxn]; } num[maxn]; inline void init() { for (int i = 1; i <= n; i++) ...
4
#include <bits/stdc++.h> using namespace std; int main() { long double o, k, t, l, p, q; cin >> l >> p >> q; if (p > q) { k = p; o = q; t = k / o; t = t + 1; cout << l - (l / t); } else { k = q; o = p; t = k / o; t = t + 1; cout << l / t << endl; } return 0; }
1
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 50; long long a[N], par[N]; int n; long double check(int k, int in) { if (k == 0 || n - k < in || in <= k) return 0; long double sum = par[in] - par[in - k - 1] + par[n] - par[n - k]; long double ans = 1.0 * sum / (1.0 * 2 * k + 1); ans -= a[in];...
5
#include <iostream> #include<bits/stdc++.h> using namespace std; typedef long long ll; ll n,m,q,a,lo,lo2,ans; vector<ll>v,vv; int main(void){ cin>>n>>m>>q; v.push_back(-(1LL<<50)); for(int i=0;i<n;i++){ cin>>a; v.push_back(a); } v.push_back(1LL<<50); vv.push_back(-(1LL<<50)); ...
0
#include <bits/stdc++.h> using namespace std; string second, T; int main() { cin >> second >> T; int res = 0, i; for (int a = 0, b = ((int)T.size()) - 1; a < ((int)second.size()); b <= 0 ? a++ : b--) { int cnt = 0; for (i = 0; a + i < ((int)second.size()) && b + i < ((int)T.size()); i++) { if...
1
#include <iostream> #include <cstdio> #include <vector> #include <map> #include <algorithm> #include <cmath> using namespace std; #define REP(i,n) for(int (i)=0; (i)<(n); (i)++) #define For(i,a,b) for(int (i)=(a); (i)<(b); (i)++) void solve5(int N, int M) { int p[M]; REP(i,M) p[i] = 0; REP(i,N) { ...
0
#include <bits/stdc++.h> using namespace std; int n, m, G[505][505]; long long ans = 0; bitset<505> f[61][2][505], ok, tmp; int main() { int i, j, k, x, y, z; scanf("%d %d", &n, &m); memset(G, -1, sizeof(G)); for (i = 1; i <= m; i++) { scanf("%d %d %d", &x, &y, &z); G[x][y] = z; f[0][z][x][y] = 1; ...
6
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, k; cin >> n >> k; if (k == 1 || k > 3) { cout << -1 << '\n'; return 0; } if (k == 3) { if (n < 4) { cout << -1 << '\n'; } else { vector<pair<int, int> > e; e...
5
#include <bits/stdc++.h> using namespace std; long long i, k, p, n, a, c; int main() { cin >> n; while (i < n) { cin >> a; if (a % 3 == 1) { k++; } if (a % 3 == 2) { p++; } if (a % 3 == 0) { c++; } i++; } cout << min(k, p) + c / 2; }
3