solution
stringlengths
52
181k
difficulty
int64
0
6
#include <bits/stdc++.h> using namespace std; int n, m; int dsu[200005]; int fi_root(int nod) { if (dsu[nod] == 0) { return nod; } return dsu[nod] = fi_root(dsu[nod]); } bool unite(int x, int y) { x = fi_root(x); y = fi_root(y); if (x == y) { return false; } dsu[x] = y; return true; } int main...
5
#include <bits/stdc++.h> using namespace std; long long int n, m, a, b; void solve() { cin >> a >> b; if (a == b) cout << 0 << endl; else if (a < b) { if ((b - a) % 2 == 0) cout << 2 << endl; else cout << 1 << endl; } else { if ((a - b) % 2 == 0) cout << 1 << endl; else ...
1
#include <bits/stdc++.h> using namespace std; int main() { int n, i, j, k, x, y; cin >> n; int a[n], b[n + 1]; bool f[n + 1]; memset(f, false, sizeof(f)); memset(b, -1, sizeof(b)); for (i = 0; i < n; i++) cin >> a[i]; for (i = 0; i < n;) { j = i + 1; while (j < n && a[j] == a[i]) j++; b[j] =...
3
#include <bits/stdc++.h> using namespace std; struct Query { int num, a, b; Query(int num = 0, int a = 0, int b = 0) : num(num), a(a), b(b) {} bool operator<(const Query& q) const& { return b < q.b; } }; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; vector<int> a(n); ...
5
#include <bits/stdc++.h> using namespace std; const int INF = (1 << 29); const int INFF = 0x7fffffff; const long long LINF = (1ll << 60); const long long LINFF = 0x7fffffffffffffff; const long double PI = 3.14159265359; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); long long rnd(long long a, long...
3
#include <bits/stdc++.h> #pragma comment(linker, "/stack:200000000") #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") using namespace std; const long long INF = 1000LL * 1000 * 1000 * 1000 * 1000 * 1000; const int inf = 1000...
1
#include <bits/stdc++.h> int main() { int n, m; std::cin >> n >> m; std::string a, b; std::cin >> a >> b; std::vector<std::vector<int>> DP(n + 1, std::vector<int>(m + 1)); for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { if (a[i] == b[j]) DP[i + 1][j + 1] = std::max(DP[i + 1][j ...
2
#include <bits/stdc++.h> using namespace std; queue<int> q; int n, m, vis[1600][1600]; char s[1600][1600]; int hea[7100], nex[7100], vv[7100], uu[7100]; int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, 1, 0, -1}; void bfs(int x, int y, int k) { while (!q.empty()) q.pop(); int cx, cy, nx, ny; vis[x][y] = k; q.push(x); q...
2
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 100; vector<int> adj[MAXN]; int mark[MAXN]; pair<int, int> hd[MAXN]; int main() { int n, m, h, t; scanf("%d%d%d%d", &n, &m, &h, &t); while (m--) { int a, b; scanf("%d %d", &a, &b); adj[a].push_back(b); adj[b].push_back(a); } ...
2
#include<bits/stdc++.h> /** ******************* Author:Bisnu sarkar **************************** **/ /* #pragma GCC target ("avx2") #pragma GCC optimization ("O3") #pragma GCC optimization ("unroll-loops") */ //PBDS /* #include<ext/pb_ds/assoc_container.hpp> #include<ext/pb_ds/tree_policy.hpp> using namespace __gnu_...
1
#include <iostream> #include <algorithm> #include <vector> #include <cmath> #include <queue> using namespace std; const int MAX = 14348907; // 3 ^ 15 int N,M,init; bool memo[MAX]; vector<int> v[3]; struct state{ int n,bit; state(int n=0, int bit=init):n(n),bit(bit){} }; int calcBit(int n, int pos){ return (in...
0
#include <bits/stdc++.h> using namespace std; long long tb[1000005], inv[1000005], invtb[1000005]; void getA() { tb[0] = tb[1] = inv[0] = inv[1] = invtb[0] = invtb[1] = 1; for (long long i = 2; i <= 1000005 - 1; i++) { tb[i] = tb[i - 1] * i % 998244353; inv[i] = (998244353 - 998244353 / i) * inv[998244353 %...
3
#include <bits/stdc++.h> using namespace std; int n; const int M = 303; double dp[M][M][M]; double f(int i, int j, int k){ if(i+j+k==0){ return 1.0; } if(i < 0 || i > n || j < 0 || j > n || k < 0 || k > n ){ return 0; } if(dp[i][j][k] > 0.00001) return dp[i][j][k]; double total = i+j+k; return dp[i][j]...
0
#include <bits/stdc++.h> const int N = 2e5; int n, q; int Suf[N + 5]; struct Node { int Val, Time; } R[N + 5]; int main() { scanf("%d", &n); for (int i = 1; i <= n; ++i) scanf("%d", &R[i].Val); scanf("%d", &q); for (int i = 1; i <= q; ++i) { int opt, p, x; scanf("%d", &opt); if (opt & 1) { s...
2
#include <bits/stdc++.h> using namespace std; int max(int a, int b) { if (a > b) return a; else return b; } int main() { vector<int> arr[26]; string s; cin >> s; int len = s.length(); for (int i = 0; i < len; i++) arr[s[i] - 'a'].push_back(i); string res = ""; int ind = -1; for (int i = 25; ...
1
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string s; cin >> s; int p = 0; for (int i = 0; i < n; i++) { if (s[i] == '-') { if (p > 0) { p--; } } else { p++; } } cout << p; return 0; }
1
#include <bits/stdc++.h> using namespace std; int n, m; char s[100005]; long long ans = 0; int main() { scanf("%d%d%s", &n, &m, s); int k = 1; for (int i = 0; i < (int)(n - 1); ++i) if (s[i] != s[i + 1]) { ++k; } ans = (long long)n * (m - 1) * k; for (int beg = 0; beg < n - 1;) if (s[beg] !=...
4
#include <bits/stdc++.h> using namespace std; long long n, m; long long a[200020], d[200020]; long long h1[200020], hr1[200020]; vector<long long> ans; long long kasumi(long long x, long long y) { long long z = 1; while (y) { if (y & 1) z = z * x % 1000000007; x = x * x % 1000000007; y >>= 1; } retu...
2
#include <bits/stdc++.h> namespace IO { char gc() { return getchar(); } template <typename Tp> bool get1(Tp &x) { bool neg = 0; char c = gc(); while (c != EOF && (c < '0' || c > '9') && c != '-') c = gc(); if (c == '-') c = gc(), neg = 1; if (c == EOF) return false; x = 0; for (; c >= '0' && c <= '9'; c =...
4
#include<iostream> #include<algorithm> #include<set> using namespace std; int q; int main(){ cin >> q; multiset<int> msa; for(int i = 0; i < q; i++){ char query; cin >> query; if(query == '0'){ int x; cin >> x; msa.insert(x); cout << msa.size() << endl; }else if(query == '1'){ int x; cin ...
0
#include <bits/stdc++.h> using namespace std; const double eps(1e-8); int n, m; int x[5010], cnt[1010], l[5010], r[5010]; int main() { scanf("%d%d", &n, &m); for (int i = 1; i <= n; i++) { scanf("%d", &x[i]); l[i] = x[i]; cnt[x[i]]++; } int Max = 0; sort(l + 1, l + 1 + n); for (int i = 1; i <= m...
3
#include<iostream> #include<cstdio> #include<cstdlib> #include<cstring> #include<string> #include<algorithm> #include<math.h> using namespace std; const int N=3e5+5; int n,q,x,a[N]; long long sf[N],sg[N]; void init() { int i; scanf("%d%d",&n,&q); for(i=1;i<=n;++i) scanf("%d",&a[i]); for(i=1;i<=n;++i) sf[i]=sf[i-1...
0
#include <bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:667772160") template <class T1> void deb(T1 e1) { cout << e1 << endl; } template <class T1, class T2> void deb(T1 e1, T2 e2) { cout << e1 << " " << e2 << endl; } template <class T1, class T2, class T3> void deb(T1 e1, T2 e2, T3 e3) { co...
4
#include <bits/stdc++.h> using namespace std; const uint64_t mod = (1ull << 61) - 1; const unsigned long long bas = 31; inline uint64_t mult(uint64_t a, uint64_t b) { uint64_t l1 = (uint32_t)a, h1 = a >> 32, l2 = (uint32_t)b, h2 = b >> 32; uint64_t l = l1 * l2, m = l1 * h2 + l2 * h1, h = h1 * h2; uint64_t ret = ...
5
#include <bits/stdc++.h> using namespace std; typedef __int128_t Long; int main() { int n, x; cin >> n >> x; vector<int> as(n); for (int i = 0; i < n; i++) { cin >> as[i]; } long long ans = 1ll * x * n; Long nin = 1e18; vector<long long> sum(n + 1); for (int i = 0; i < n; i...
0
#include<iostream> #include<map> using namespace std; int main(){ map<int,bool> h; int q,n,cnt; cin >> q; while(q--){ cin >> n; cnt = 0; h.clear(); for(;;){ int m = -1, k = 10; if(h[n]){ cout << -1 << endl; break; } h[n] = true; if(n<10){ cout << cnt << endl; b...
0
#include <bits/stdc++.h> using namespace std; inline int read() { int ans = 0; char ch = getchar(); while (ch < '0' || ch > '9') ch = getchar(); while (ch >= '0' && ch <= '9') ans = (ans << 1) + (ans << 3) + (ch ^ 48), ch = getchar(); return ans; } inline long long L_read() { long long ans = 0; char c...
3
#include <bits/stdc++.h> using namespace std; const int inf = 1000000000; const int MAXN = 32; int k[MAXN]; int a[MAXN][MAXN]; int b[MAXN]; int p[MAXN]; int n, r; long long doit(int u, bool xr) { long long s = -1ll << 60; if (u % 2 == 0) { s = 0; for (int i = 0; i < (n); ++i) s += (long long)a[u][i] * k[i];...
4
#include <bits/stdc++.h> using namespace std; int answ, n, x, q, pi[1000001], fix[2000001]; string st1, st; vector<pair<int, string>> v[2000001]; pair<int, int> get_ans(int q, int pr, int x) { pair<int, int> ans; ans.first = 0; ans.second = 0; string s = v[pr][x].second; for (int i = 1; i <= s.size(); i++) { ...
5
#include <bits/stdc++.h> using namespace std; int a[1000005]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int i, j, k, l, m, n, t, r, cnt; int flag = 0; long long ans = 0, an = 0; t = 1; while (t--) { cin >> n; string str, str2; cin >> str >> str2; long long o...
2
#include <bits/stdc++.h> using namespace std; const long long infl = 5e16 + 5; long long int m, n, q, cn, k, w, pos, tmp1, size(), mx = 0, tmp, mx1 = -1, b, c, d, mn = infl, k1, p, x, f; long long int a[1523456]; double d1; string s, t; int check(long long int val) { long long int i; long long int sm = 0; for...
3
#include <bits/stdc++.h> using namespace std; const int mod = 998244353; const int N = 1 << 19; int A[N], B[N], w[N], inv[N], len, len1, len2, pos[N], res[N], f[N], g[N]; void init() { int op = len >> 1, k = N / len; for (int i = 0, j = 0; i < len; ++i, j += k) { w[i] = f[j]; inv[i] = g[j]; pos[i] = pos...
4
#include <bits/stdc++.h> using namespace std; string S; int main() { for (int i = 1; i <= 1000; i++) { S += to_string(i); } int n; std::ios::sync_with_stdio(false); cin >> n; cout << S[n - 1]; return 0; }
1
#include <bits/stdc++.h> #pragma comment(linker, "/stack:16777216") using namespace std; const int INF = 1000000000; const int MAX = 100007; const int MAX2 = 1000000; const int MAXD = 20; const int BASE = 1000000007; const int MOD = 1000000007; int n, k, s, t; vector<int> A, B; vector<pair<int, int> > C; bool F(int x) ...
1
#include <bits/stdc++.h> using namespace std; int p[100005] = {0}; int used[100005] = {0}; vector<pair<int, int> > ans; vector<int> v; int main() { int n; cin >> n; if (n <= 2) { cout << "0" << endl; return 0; } int lim = n / 2; for (int i = 3; i <= lim; i += 2) { if (p[i] == 0) { int t = ...
3
#include <bits/stdc++.h> using namespace std; int main() { bool ok = false; unsigned long long k, l, count = 0, z; cin >> k >> l; z = k; while (k <= l) { if (k == l) { cout << "YES" << endl; cout << count << endl; ok = true; break; } k = k * z; count++; } if (!ok) c...
1
#include <bits/stdc++.h> using namespace std; const long long N = 1e6 + 2; long long ar[N], grun[N]; multiset<long long> wow; set<long long> okfine; signed main() { long long n, i, j, k, l, r, lef = 0, rig = -1, now = 0, max1 = N; cin >> n; for (i = 1; i <= n; i++) { cin >> ar[i]; } sort(ar + 1, ar + 1 + ...
3
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c, k; cin >> a >> b >> c >> k; cout << a + b + c + max(a, max(b, c)) * (int)pow(2, k) - max(a, max(b, c)) << endl; }
0
#include<bits/stdc++.h> using namespace std; int NAX=3001; #define ll long long int main(){ ll n; scanf("%lld",&n); vector<ll> arr(n); for(int i=0;i<n;i++)scanf("%lld",&arr[i]); vector<vector<ll> > dp(NAX,vector<ll>(NAX)); for(int i=n-1;i>=0;i--){ for(int j=i;j<n;j++){ if(i==j) dp[i][j]=arr[i]; el...
0
#include <bits/stdc++.h> using namespace std; template <class T1, class T2> ostream& operator<<(ostream& out, pair<T1, T2>& p) { out << p.first << ' ' << p.second; } template <class T> istream& operator>>(istream& in, vector<T>& v) { for (auto& x : v) in >> x; return in; } template <class T> ostream& operator<<(o...
2
#include <bits/stdc++.h> using namespace std; const long long maxN = 1e6 + 5; const long long inf = 1e10; const long long mod = 1e9 + 7; long long n; long long x[maxN]; long long a, b; int main() { ios_base::sync_with_stdio(0); cin >> n; for (long long i = 1; i <= n; i++) cin >> x[i]; cin >> a >> b; sort(x + ...
3
#include<bits/stdc++.h> using namespace std; using i64 = long long int; i64 gcd(i64 m, i64 n) { return (n == 0 ? m : gcd(n, m % n)); } i64 lcm(i64 m, i64 n) { return m / gcd(m, n) * n; } int main(){ int n; cin >> n; i64 ans = 1; for(int i=0;i<n;++i){ i64 a; cin >> a; ...
0
#include <bits/stdc++.h> #define fi first #define sd second #define ll long long using namespace std; const int maxn = 200200; const int base = 1e9+7; const ll inf = 1145141919; pair<ll, int> p[maxn],q[maxn]; int n,l[maxn],r[maxn],id[maxn],t[maxn],f[maxn]; void update(int i,int k) { while (i<=n+1) { t[i...
0
#include <bits/stdc++.h> using namespace std; long long bigmod(long long b, long long p, long long md) { if (p == 0) return 1; if (p % 2 == 1) { return ((b % md) * bigmod(b, p - 1, md)) % md; } else { long long y = bigmod(b, p / 2, md); return (y * y) % md; } } int in[20000]; int out[20000]; vector<...
1
#include <bits/stdc++.h> #define P pair<int, int> using namespace std; const int INF=1e5; int dx[4]={-1,0,1,0}; int dy[4]={0,-1,0,1}; int main(){ int h,w,a[1009][1009]; string s[1009]; cin >> h >> w; memset(a, -1, sizeof(a)); for(int i=0;i<h;i++)cin >> s[i]; queue<P> q; for(int i=0;i<h;i++){ for(i...
0
#include <bits/stdc++.h> using namespace std; int n, m, k, x, y, sum, cnt, ans, a[100005], c[100005]; pair<int, int> edges[100005]; vector<pair<int, int> > v[100005]; void dfs(int x, int paint) { if (c[x]) { if (c[x] != paint) { printf("NO\n"); exit(0); } return; } c[x] = paint; for (aut...
4
#include <bits/stdc++.h> using namespace std; long long int power(long long int x, long long int y, long long int p) { long long int res = 1; x = x % p; while (y >= 1) { if (y % 2) res = (res * x) % p; x = ((x % p) * (x % p)) % p; y /= 2; } return res; } void solve() { long long int n, m; cin ...
2
#include<bits/stdc++.h> #define ll long long using namespace std; int n,m,cnt,la,a[200010][2],rt; char s[200010]; void build(int x,int y){ a[++cnt][0]=x;a[cnt][1]=y; } int main(){ int i,j; scanf("%s",s+1); n=strlen(s+1); for(i=1;i<n;i++)if(s[i]!=s[n-i])return puts("-1"),0; if(s[1]=='0'||s[n]=='1')return puts("-1"...
0
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7, mx = 1e3 + 1; long long inv[mx]; void precomp(int n) { inv[1] = 1; for (int i = 2; i <= n; ++i) inv[i] = mod - mod / i * inv[mod % i] % mod; } long long bin_exp(long long a, long long x) { long long res = 1; while (x > 0) { if (x %...
4
#include <bits/stdc++.h> const int mod = 1000000007; int p, k; bool us[1 << 20]; void go(int v) { if (us[v]) return; us[v] = 1; go(((long long)v * k) % p); } int main() { scanf("%d %d", &p, &k); if (k == 1) { long long ans = 1; for (int i = 0; i < p; ++i) { ans = (ans * p) % mod; } print...
2
#include <bits/stdc++.h> using namespace std; long long pre[105]; long long nxt[105]; int main() { long long n; cin >> n; long long cur = 0; vector<long long> v[n + 1]; for (long long i = 0; i <= n; i++) { v[i].push_back(0); } for (long long i = 0; i < n; i++) { long long t1; cin >> t1; lo...
2
#include <bits/stdc++.h> using namespace std; bool cant[26][26]; int main() { string s; cin >> s; int n; cin >> n; for (int i = 0; i < n; ++i) { string st; cin >> st; int i1 = (int)(st[0] - 'a'); int i2 = (int)(st[1] - 'a'); cant[i1][i2] = cant[i2][i1] = true; } int ret = 0, count1 = 1...
1
#include <bits/stdc++.h> using namespace std; set<string> visited_; string rotate_left(string &str) { string ret = str; ret[0] = str[1]; ret[1] = str[2]; ret[2] = str[3]; ret[3] = str[0]; return ret; } string rotate_front(string &str) { string ret = str; ret[4] = str[1]; ret[1] = str[5]; ret[5] = st...
1
#include <bits/stdc++.h> using namespace std; int tu[15][15]; bool test(int x, int y, int n, int m, int g) { int i, j, sum = 0; for (i = x; i < x + n; i++) { for (j = y; j < y + m; j++) { if (tu[i][j] == 1) { sum++; } } } if (sum >= g) { return true; } else { return false; ...
6
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; const int MAXN = 2e5 + 100; int expo(int a, int b) { int res = 1; while (b) { if (b & 1) res = (1ll * res * a) % 998244353; a = (1ll * a * a) % 998244353; b >>= 1; } return res % 998244353; } void solve() { string a; cin >> a...
4
#include <bits/stdc++.h> using namespace std; int main(){ while(1){ int a,c=0; cin>>a; if(a==0) break; for(int n=1;n<=a;n++){ if(n%2==1 && a%n==0){ c++; }else if(n%2==0 && a%n==n/2){ c++; } } cout<<(c-1)/2<<endl; } return...
0
#include <bits/stdc++.h> using namespace std; int main() { int t, n, m, a[1005], ans, min, min2; a[1004] = 100000; cin >> t; for (int i = 0; i < t; i++) { scanf("%d%d", &m, &n); ans = 0; min = 1004; min2 = 1004; for (int j = 0; j < m; j++) { scanf("%d", &a[j]); ans += a[j]; ...
2
#include <bits/stdc++.h> using namespace std; template <class T> inline bool updateMin(T& a, T b) { return a > b ? a = b, 1 : 0; } template <class T> inline bool updateMax(T& a, T b) { return a < b ? a = b, 1 : 0; } inline int nextInt() { int x; scanf("%d", &x); return x; } inline long long nextI64() { long...
3
#include <bits/stdc++.h> using namespace std; using ll = long long; const double eps = 1e-10; const int MOD = 1000000007; const int INF = 1000000000; const ll LINF = 1ll<<50; template<typename T> void printv(const vector<T>& s) { for(int i=0;i<(int)(s.size());++i) { cout << s[i]; if(i == (int)(s.size())-1...
0
#include <bits/stdc++.h> using namespace std; const int MOD = 100000007; const int MAXN = 1000000; const int inf = 0x3f3f3f3f; int n, a[200005], b[200005]; int book[200005]; bool check(int x) { memset(book, 0, sizeof(book)); for (int i = 1; i <= n; i++) { if (a[i] == 1) book[i] = 0; } if (x <= n) { int ...
3
#include <bits/stdc++.h> auto clk = clock(); const int dx[] = {0, 0, -1, 1}, dy[] = {-1, 1, 0, 0}; const int dx8[] = {-1, -1, -1, 0, 1, 1, 1, 0}, dy8[] = {-1, 0, 1, 1, 1, 0, -1, -1}; using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); long long Gcd(long long a, long long ...
2
#include<bits/stdc++.h> using namespace std; int main(){ ios::sync_with_stdio(0); cin.tie(0); int n, k; cin >> n >> k; map<int,int> a; for(int i = 0; i < n; ++i) { int x; cin >> x; ++a[x]; } int ans = 0; vector<int> v; for(auto i : a) v.push_back(i.second); sort(v.begin(), v.end()); for(int i = 0; i ...
0
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; int n, Q, a[N], deg[N]; long long t[N], sum[N]; multiset<long long> s[N], all; long long calc(int x) { return sum[x] + (t[x] - t[x] / (deg[x] + 1) * deg[x]); } void Del(int x) { if (s[x].size()) { long long selfv = t[x] / (deg[x] + 1); all....
4
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; long long ans = 0; for (int i = (0); i < (n); ++i) { long long t, T, x, cost; cin >> t >> T >> x >> cost; if (t >= T) { ans += cost + m * x; continue; } long long aux1 = cost; if (m > (T - t))...
4
#include <bits/stdc++.h> using namespace std; const long long N = 100005; vector<pair<long long, long long>> gr[N]; long long dist[N]; long long vis[N]; void djikstra(long long node) { priority_queue<pair<long long, long long>, vector<pair<long long, long long>>, greater<pair<long long, long long>>> ...
4
#define _USE_MATH_DEFINES #include <bits/stdc++.h> using namespace std; #define int long long int dx[] = {1, 0, -1, 0, 1, -1, -1, 1}; int dy[] = {0, 1, 0, -1, 1, 1, -1, -1}; /* #define cin ifs #define cout ofs ifstream ifs("in.txt"); ofstream ofs("out.txt"); //*/ // DPを用いて最長増加部分列問題を解く const int MAX_N = 200000; cons...
0
#include <iostream> #include <cstdio> using namespace std; int main(){ double a,an,sum; while(cin>>a){ an=a*2; sum=0; for(int i=0;i<5;i++){ sum+=a+an; a=an/3; an=a*2; } printf("%.8lf\n",sum); } return 0; }
0
#include <bits/stdc++.h> using namespace std; int n, a[102]; int main(){ cin >> n; int ans = 1e9; for(int i = 1; i <= n; ++i) cin >> a[i]; for(int i = 0; i <= 100; ++i){ int sum = 0; for(int j = 1; j <= n; ++j) sum += (a[j] - i) * (a[j] - i); ans = min(ans, sum); } cout << ans << endl; return 0; }
0
#include <bits/stdc++.h> const int p = 777777777; int a1[] = { 0, 412133651, 386543325, 139952108, 289303402, 102404925, 317067177, 396414708, 80515854, 663739304, 317300809, 228877044, 493725043, 715317967, 490300965, 315527373, 743539734, 488329191, 553627998, 533025234, 242583957, 706116537,...
4
#include <bits/stdc++.h> using namespace std; long long n, k, a[200005], nxt[200005], ans; bool check(long long sum, long long pro, long long len) { long long temp = pro - sum * k; if (temp % k) return false; if (temp / k >= 0 && temp / k <= len) return true; else return false; } int main() { cin >> n...
4
#include <bits/stdc++.h> using namespace std; const int MAXN = 200007; int n, a[MAXN], p[MAXN]; set<int> done; signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; for (int i = 1; i <= n; ++i) { cin >> a[i]; p[a[i]] = i; } done.insert(0); done.insert(n + 1); int ans...
5
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; const ll OO = 1e8; int di[8] = {0, 0, 1, -1, -1, 1, -1, 1}; int dj[8] = {1, -1, 0, 0, 1, 1, -1, -1}; string ys = "YES", no = "NO"; const long double dgr = acos(-1) / 180, dg = 180 / acos(-1); const int mod = 1e18, N = 2e5, M = 5...
3
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1.0); const int inf = 0x3f3f3f3f; const int MAXN = 0x7fffffff; const long long INF = 0x3f3f3f3f3f3f3f3fLL; void file() {} const int N = 3e5 + 5; int fat[N * 2], Size[N * 2], n, k; vector<int> vec[N]; int find(int x) { return fat[x] == x ? x : fat[x] ...
5
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; const int maxn = 2e5 + 7; const long long mod = 1e9 + 7; inline long long read() { long long x = 0; bool f = 0; char ch = getchar(); while (ch < '0' || '9' < ch) f |= ch == '-', ch = getchar(); while ('0' <= ch && ch <= '9') x = x * 10 ...
3
#include <bits/stdc++.h> using namespace std; const int INF = 1000000007; const int N = 100100; const double PI = 3.141592654; const double eps = 0.00000001; double sqr(double x) { return x * x; } struct Point { double x, y; Point() {} Point(double x, double y) : x(x), y(y) {} Point rotate(double alpha) { r...
3
#include <bits/stdc++.h> using namespace std; int q; int n = 1; int par[500007]; int d = 60; double dp[500007][63]; int p1, p2; vector<int> sta; void ans(int v) { double res = 0.0; for (int i = 1; i <= d; i++) { res += 1.0 - dp[v][i]; } printf("%.10lf\n", res); } void add(int v) { n++; par[n] = v; sta...
5
#include <bits/stdc++.h> #define FOR(i, n, m) for(ll i = n; i < (int)m; i++) #define REP(i, n) FOR(i, 0, n) #define ALL(v) v.begin(), v.end() #define pb push_back using namespace std; using ll = long long; using P = pair<ll, ll>; constexpr ll inf = 1000000000; constexpr ll mod = 998244353; constexpr long double eps = 1...
0
#include <iostream> #include <cstring> #include <vector> #include <algorithm> using namespace std; int sz1 , sz2; string s; vector<int> c[128]; int off[128][322]; int dp[301][301]; pair<int,int> to[301][301]; int flag[301][301]; int dp_search(int sz1,int sz2){ memset(dp,-1,sizeof(dp)); memset(flag,0,sizeof(flag))...
0
#include <bits/stdc++.h> using namespace std; int t, a, b, c; int main() { ios_base::sync_with_stdio(); cin.tie(0); cout.tie(0); cin >> t; while (t--) { cin >> a >> b >> c; int x = min(b, c / 2); b -= x; int y = min(a, b / 2); cout << 3 * (x + y) << endl; } return 0; }
1
#include <bits/stdc++.h> using namespace std; const int maxn = 200000 + 10; const int oo = 1 << 30; long long tmax[4 * maxn], tsum[4 * maxn], A[maxn], N, Q; int sig; void build(int node, int start, int end) { if (start == end) { tmax[node] = A[start]; tsum[node] = A[start]; return; } int mid = (start ...
5
#include <bits/stdc++.h> using namespace std; int main() { vector<int> sticks(6); for (int i = 0; i < 6; i++) cin >> sticks[i]; string ans = "Alien"; sort(sticks.begin(), sticks.end()); do { set<int> vals; for (int i = 0; i < 4; i++) vals.insert(sticks[i]); if (vals.size() == 1) { ans = "Bea...
1
#include <bits/stdc++.h> using namespace std; int main() { long long t; cin >> t; while (t--) { string s; cin >> s; long long cur = 0, pre = 0; long long ans = 0; for (int i = 0; i < s.length(); i++) { if (s[i] == 'R') { pre = i + 1; } cur = i + 1; ans = max(ans...
3
#include<bits/stdc++.h> using namespace std; const int N=3e5+10; int n,v[20],x[N],dep,dpl[N],dpr[N]; int blo[20][N],L[20][N],R[20][N]; void init(int dep){ int cnt=0; blo[dep][1]=L[dep][1]=R[dep][1]=cnt=1; for (int i=2;i<=n;i++){ if (x[i-1]+v[dep]>=x[i]) blo[dep][i]=cnt,R[dep][cnt]++;else blo[dep][i]=++cnt,L[dep]...
0
#include <bits/stdc++.h> using namespace std; const int maxn = 85; int N, n, sep[maxn << 1], L[maxn], R[maxn], minL[maxn][maxn], maxR[maxn][maxn]; double ans[maxn][maxn], f[maxn][maxn][maxn], reci[maxn]; void Push(int x, int i, int z) { double a, b, c; a = double(min(sep[x], R[z]) - L[z]) * reci[z]; b = double(se...
5
#include <bits/stdc++.h> using namespace std; const int INF = (int)2e9; const double EPS = (double)1e-9; const double PI = (double)acos(-1.0); const int MOD = (int)1e9 + 7; set<string> hashh; int main() { int n, m; char dat[25][25]; scanf("%d %d", &n, &m); for (int i = 0; i <= n - 1; i += 1) scanf("%s", dat[i])...
2
#include <bits/stdc++.h> using namespace std; const long long mod0 = 1e9 + 7; const long long mod1 = 998244353; const long long mod2 = 1e9 + 9; const long long mod3 = 2147483647; const int maxn = 2e5 + 3; const int inf = 2 * 1024 * 1024 * 1023; const long double eps = 1e-7; int n, k; void init() { ios_base::sync_with...
2
#include<bits/stdc++.h> using namespace std; int main(){ int n,a; cin>>n>>a; if(n%500<=a){ cout<<"Yes"; } else cout<<"No"; }
0
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } int id = n - 1; while (id >= 0 && a[id] <= a[id - 1]) id--; while (id >= 0 && a[id] >= a[id - 1]) id--; if (id...
3
#include<iostream> #include<string> #include<vector> #include<algorithm> using namespace std; int main(){ string str; while(getline(cin,str),str!="END OF INPUT"){ str+=" "; int cnt=0; for(int i=0;i<str.length();i++){ if(str[i]==' '){ cout<<cnt; ...
0
#include <bits/stdc++.h> using namespace std; vector<int> g[2010]; int ans; void dfs(int u, int dep) { if (g[u].size() == 0) ans = max(ans, dep); for (int i = 0; i < (int)g[u].size(); i++) { dfs(g[u][i], dep + 1); } } int main() { int N, u; scanf("%d", &N); ans = 0; for (int v = 1; v <= N; v++) { ...
1
#include <bits/stdc++.h> int main() { int n; std::cin >> n; int a = 0, d = 0; std::string s; std::cin >> s; for (int i = 0; i < n; i++) { if (s[i] == 'A') a++; else d++; } if (a > d) std::cout << "Anton"; else if (d > a) std::cout << "Danik"; else std::cout << "Friend...
1
#include <stdio.h> int main() { int n;int j=0; scanf("%d",&n); char s[n+1]; scanf("%s",s); for(int i=0;s[i]!='\0';i++) { if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C') j++; } printf("%d",j); return 0; }
0
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n, k; cin >> n >> k; int a[n + 1]; for (int i = 1; i <= n; i++) cin >> a[i]; a[0] = 0; sort(a, a + (n + 1)); int ans; int sum = 0; int index = -1; for (int i = 1; i <= n; i++) { ...
1
#include <bits/stdc++.h> using namespace std; template <typename T> ostream& operator<<(ostream& os, const vector<T>& v) { for (auto i : v) os << "(" << i.x << ", " << i.y << ") "; return os; } template <typename T> ostream& operator<<(ostream& os, const set<T>& v) { for (auto i : v) os << i << " "; return os; ...
3
#include <bits/stdc++.h> using namespace std; long long x[20], n = 0, ans = 0, current; long long cnv(char c) { if (c == 'a') return current; return c - '0'; } long long f(string t) { long long ans = 0, cur = 0; string s = "+" + t + "+"; for (int i = 1; i < s.length(); i += 2) { if (s[i - 1] == '+' && s[i...
5
#include <bits/stdc++.h> using namespace std; const int N = 200 * 1000 + 85; int n, m; int a[N]; vector<int> vec[N]; pair<pair<int, int>, int> b[N]; int mapp[N]; int ans[N]; int seg[N << 2]; inline void add(int, int, int = 1, int = 0, int = N); inline int get(int, int = 1, int = 0, int = N); int main() { ios::sync_wi...
4
#include <bits/stdc++.h> using namespace std; vector<string> split(const string& s, char c) { vector<string> v; stringstream second(s); string x; while (getline(second, x, c)) v.emplace_back(x); return move(v); } template <typename T, typename... Args> inline string arrStr(T arr, int n) { stringstream s; ...
6
#include <bits/stdc++.h> using namespace std; const int oo = 1e9 + 7; string s[101]; int n; string t; vector<string> res; int main() { ios_base::sync_with_stdio(false); cin >> t; cin >> n; for (int i = 1; i <= n; ++i) cin >> s[i]; for (int i = 1; i <= n; ++i) { bool bl = true; for (int j = 0; j < t.si...
1
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; cout << s.substr(0, 4) + " " + s.substr(4) << endl; return 0; }
0
#include<cstdio> #include<algorithm> #define ll long long using namespace std; ll a[5010]; ll b[5010]; int main() { ll n, m; scanf("%lld %lld", &n, &m); for (int i = 0; i < n; i++) scanf("%lld", &a[i]); for (int i = 0; i < m; i++) { ll q, w, e; scanf("%lld %lld %lld", &q, &w, &e); ll ans = q - 1; for (int...
0