solution
stringlengths
52
181k
difficulty
int64
0
6
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); string s; int n; while (cin >> n) { cin >> s; int gold = 0, cnt = 0, prev = 0, ans = 0; for (auto ch : s) { if (ch == 'G') gold++, cnt++; else prev = cnt,...
2
//AOJ0338.cpp #include <iostream> using namespace std; int gcd(int m,int n){ if(n==0) return m; return gcd(n,m%n); } int main(){ int W, H, C; cin >> W >> H >> C; int g = gcd(W,H); cout << W/g*H/g*C <<endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; map<string, int> mp; set<string> st; int c = 1; int m = 0; while (n--) { string s; cin >> s; mp[s]++; m = max(m, mp[s]); } cout << m << endl; }
2
#include <bits/stdc++.h> using namespace std; int sol[123123]; int on[123123]; int matrix[142][142]; int matrix_2[142][142]; int main() { int n, m, h; cin >> n >> m >> h; for (int i = 1; i <= m; i++) cin >> on[i]; for (int i = 1; i <= n; i++) cin >> sol[i]; for (int i = 1; i <= n; i++) for (int j = 1; j <...
2
#include <bits/stdc++.h> using namespace std; string repeat(string s, int n) { string s1 = s; for (int i = 1; i < n; i++) s += s1; return s; } string getString(char x) { string s(1, x); return s; } void optimizeIO() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } class Graph { int...
5
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize("O3") long long gcd(long long x, long long y) { return y ? gcd(y, x % y) : x; } const int MAXN = 2e5 + 10; vector<int> idx; string s1, s2; template <class T> class string_hash { public: const T& s; vector<long long> hash, power; long long mod = 1...
4
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; string s; cin >> s; string ans = {s[0], s[1]}; int mx = 0; map<string, int> mp; for (int i = 0; i + 1 < n; ++i) mp[{s[i], s[i + 1]}]++; for (auto p : mp) if (p.second > mx) m...
2
#include <bits/stdc++.h> using namespace std; bool cmp_pair_F_2(pair<int, int> x, pair<int, int> y) { return x.first > y.first; } bool cmp_pair_S_2(pair<int, int> x, pair<int, int> y) { return x.second > y.second; } bool cmp_pair_S_1(pair<int, int> x, pair<int, int> y) { return x.second < y.second; } bool cmp(int...
4
#include <bits/stdc++.h> using namespace std; const int M = 200000 + 5; int a[M]; int b[M]; int c[M]; struct TREE { int l; int r; int minv; int s; int x; } tree[4 * M]; void build(int l, int r, int node) { tree[node].l = l; tree[node].r = r; tree[node].x = 0; if (l == r) { tree[node].minv = c[l]; ...
5
#include <iostream> #include <complex> #include <cmath> using namespace std; typedef complex<double> P; // real -> X // imag -> Y bool isIntersect(P p1, P p2, P p3, P p4){ return ( ((p1.real() - p2.real()) * (p3.imag() - p1.imag()) + (p1.imag() - p2.imag()) * (p1.real() - p3.real())) * ((p1.real() - p2.real())...
0
#include <bits/stdc++.h> using namespace std; int main() { int n, r; cin >> n >> r; double s = sin(3.14159265358979323846 / n); double R = (double)(r * s) / (1 - s); printf("%.6f\n", R); return 0; }
3
#include <bits/stdc++.h> using namespace std; int k1, k2, k3; int main() { cin >> k1 >> k2 >> k3; if (k1 == 1 || k2 == 1 || k3 == 1) { cout << "YES"; return 0; } if ((k1 == 2 && k2 == 2) || (k1 == 2 && k3 == 2) || (k2 == 2 && k3 == 2)) { cout << "YES"; return 0; } if (k1 == 3 && k2 == 3 && k...
3
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; const long long inf = 1e15 + 15; int n, m, q; int a[N], b[N], c[N]; vector<int> v[N]; long long pot[N]; long long dist[N]; priority_queue<pair<long long, int> > pq; bool visited[N]; void solve() { for (int i = 1; i <= n; ++i) { dist[i] = inf; ...
4
#include <bits/stdc++.h> using namespace std; vector<int> graph[5002]; vector<pair<long long, int> > v; int d[5002][5002], vis[5002], c[5002]; long long k[5002], p[5002]; void bfs(int src, int n) { int i, u, v; for (i = 1; i <= n; i++) d[src][i] = (int)1e9 + 7; ; d[src][src] = 0; memset(vis, 0, sizeof(vis)); ...
3
#include <bits/stdc++.h> using namespace std; int n, m, q, l, a[10005], b[10005]; bool cmp(int x, int y) { return x < y; } bool used[10005][10005]; bool can_do() { for (int i = 1; i <= l; i++) { int ans = -1, cx, cy, hans = -1; for (int j = 1; j <= n; j++) for (int k = 1; k <= m; k++) if (used[j...
1
#include <bits/stdc++.h> using namespace std; long long getMaximumEnergy(int n, int k, const vector<long long> a, const vector<long long> d) { if (k >= 2) { long long ret = max(0LL, a[n - 1] - d[n - 1]); long long lowestCost = d[0]; long long totalBenefit = a[n - 1]; for (in...
5
#include <bits/stdc++.h> using namespace std; const int mod = 1000000007; const int mxn = 600000; int n, q; long long a[mxn], b[mxn], d[mxn], first[mxn], p[mxn], it[mxn]; struct segTree { int l, r; segTree *tl, *tr; long long vl, lv, rv, second; segTree(int l, int r) : l(l), r(r) { vl = lv = rv = second = 0...
6
#include <algorithm> #include <iostream> #include <vector> #include <map> #include <bitset> using namespace std; int n; vector<vector<int>> g; vector<int> color; vector<int> parts; vector<pair<int, int>> ps; bool dfs(int u, int c) { color[u] = c; parts[c]++; for (int v: g[u]) { if (~color[v]) { ...
0
#include <bits/stdc++.h> using namespace std; long long int n, t; string s; int main() { cin >> n >> t >> s; for (int j = 0; j < t; j++) { for (int i = 0; i < n - 1; i++) { if (s[i] == 'B' && s[i + 1] == 'G') { swap(s[i], s[i + 1]); i++; } } } cout << s; return 0; }
2
#include <bits/stdc++.h> #pragma GCC optimize(1) #pragma GCC optimize(2) #pragma GCC optimize(3, "Ofast", "inline") inline int MAX(int x, int y) { return x > y ? x : y; } inline int MIN(int x, int y) { return x < y ? x : y; } using namespace std; template <typename T> T gcd(T a, T b) { while (b ^= a ^= b ^= a %= b) ...
2
#include <bits/stdc++.h> using namespace std; int main() { int n, m, temp1, temp2, ans = 0, parts[10000]; scanf("%d%d", &n, &m); for (int i = 1; i < n + 1; i++) scanf("%d", &parts[i]); for (int i = 0; i < m; i++) { scanf("%d%d", &temp1, &temp2); ans += min(parts[temp1], parts[temp2]); } printf("%d",...
1
#include <bits/stdc++.h> using namespace std; int main() { long long n, m, k, sum = 0; cin >> m >> n >> k; long long brea[m]; for (int i = 0; i < m; i++) { cin >> brea[i]; } long long a[m - 1]; for (int i = 0; i < m - 1; i++) { a[i] = brea[i + 1] - brea[i]; } sort(a, a + m - 1); long long i;...
2
#include <bits/stdc++.h> using namespace std; class Solution { public: int numOfShift(int n, int m) { vector<NumberOf> number(n); string s; int ans = 1000; for (int i = 0; i < n; ++i) { cin >> s; for (int j = 0; j < m; ++j) { int temp = min(j, m - j); number[i].data[type(s...
3
#include <cstdio> #include <vector> #include <algorithm> using namespace std; class Point { public: int x, y; Point(int a = 0, int b = 0) { int x = a; int y = b; }; bool operator <(const Point& p) const { return y < p.y || (y == p.y && x < p.x); } }; inline bool direct(...
0
#include <bits/stdc++.h> using namespace std; int main() { string s, s1; cin >> s >> s1; reverse(s.begin(), s.end()); if (s == s1) { cout << "YES"; return 0; } cout << "NO"; return 0; }
1
#include <bits/stdc++.h> int n, m, p, x, y; using namespace std; int main() { cin >> n >> m >> p; while (p--) { cin >> x >> y; if (x <= 5 || y <= 5 || n - x <= 4 || m - y <= 4) return puts("YES"), 0; } puts("NO"); return 0; }
3
#include<stdio.h> #include<algorithm> using namespace std; int p[30]; int q[30]; char str[8]; int main(){ int sz=0; int sz2=0; int a;scanf("%d",&a); int b;scanf("%d",&b); for(int i=0;i<b;i++){ int c;scanf("%s%d",str,&c); if(str[0]=='D')p[sz++]=-c; } int d;scanf("%d",&d); for(int i=0;i<d;i++){ int c;scanf(...
0
#include <bits/stdc++.h> using namespace std; template <typename A, typename B> string to_string(pair<A, B> p); template <typename A, typename B, typename C> string to_string(tuple<A, B, C> p); template <typename A, typename B, typename C, typename D> string to_string(tuple<A, B, C, D> p); string to_string(const string...
4
#include <bits/stdc++.h> using namespace std; const int N = 4 * 1e5 + 5; vector<int> g[N]; int n, dp[N], res[N]; int dfs(int i, int p = -1) { dp[i] = 1; for (auto j : g[i]) { if (j != p) { dp[i] += dfs(j, i); } } return dp[i]; } int dfs2(int i, int p = -1) { for (auto j : g[i]) { if (j != p ...
3
#include <bits/stdc++.h> using namespace std; const int inf = ~0U >> 1; const long long LINF = ~(((long long)0x1) << 63) / 2; template <class T> bool get_max(T &a, T &b) { return b > a ? a = b, 1 : 0; } template <class T> bool get_min(T &a, T &b) { return b < a ? a = b, 1 : 0; } const long long MOD = 1000000007LL; ...
4
#include<bits/stdc++.h> using namespace std; #define maxn 100000 int a[maxn+5]; int main(){ int n,k,q,x;scanf("%d%d%d",&n,&k,&q); k=q-k+1; for(int i=0;i<q;i++)scanf("%d",&x),a[x]++; for(int i=1;i<=n;i++)if(a[i]>=k)puts("Yes");else puts("No"); return 0; }
0
#include <bits/stdc++.h> using namespace std; int arr[3] = {0, 0, 0}; int find(int x) { for (int i = 0; i < 3; i++) if (arr[i] == x) return i; return -1; } int main() { string input; for (int i = 0; i < 3; i++) { cin >> input; if (input[1] == '>') arr[input[0] - 'A']++; else arr[inpu...
2
#include <bits/stdc++.h> using namespace std; int n, m, k, t, tr, a; int r[5005][2], c[5005][2]; int main() { cin >> n >> m >> k; for (int l = 0; l < k; l++) { scanf("%i%i%i", &t, &tr, &a); if (t == 1) { r[tr][0] = a; r[tr][1] = l + 1; } else { c[tr][0] = a; c[tr][1] = l + 1; ...
2
#include <stdio.h> #include <math.h> #define rep(i, n) for(int i=0; i<(int)(n); i++) typedef long long Int; int N, M, L, P[200], T[200], V[200]; double zp[200][200], zt[200][200]; Int C[100][100]; int main() { C[0][0] = 1; rep(i, 80) rep(j, 80) C[i+1][j]+=C[i][j], C[i+1][j+1]+=C[i][j]; scanf("%d%d%d", &...
0
#include <bits/stdc++.h> using namespace std; template <typename T> inline void R(T &x) { char ch = getchar(); x = 0; for (; ch < '0' || ch > '9'; ch = getchar()) ; for (; ch <= '9' && ch >= '0'; ch = getchar()) x = x * 10 + ch - '0'; } inline long long gcd(long long a, long long b) { if (b == 0) return a...
4
#include <iostream> #include <map> using namespace std; int main() { string s; cin >> s; map<char,int> m; for(int i=0; i<s.length(); i++){ m[s[i]]++; } int paircount = 0; long long div = 1; bool bOdd = false; for(map<char,int>::iterator p = m.begin(); p != m.end(); p++){ if((*p).second % 2 == ...
0
#include <bits/stdc++.h> #define r(i,n) for(int i=0;i<n;i++) using namespace std; struct Dinic{ const int INF=1<<28; struct edge { int to,cap,rev; edge(){} edge(int to,int cap,int rev):to(to),cap(cap),rev(rev){} }; int n; vector<vector<edge> > G; vector<map<int,int> > M; vector<int> level...
0
#include<bits/stdc++.h> using namespace std; typedef long long ll; int main () { ios::sync_with_stdio(0); cin.tie(0); string s; cin >> s; int n = s.length()+1, id = 0; vector<int> p(n), c(n), t(n), lcp(n-1); vector<vector<int>> cnt(n); for (int i=0; i<n; i++) { p[i]= i; } sort(begin(p), end(p), [&](const i...
0
#include <bits/stdc++.h> using namespace std; int bases[41], tails[41]; int minLen, maxLen; int log2(long long n) { if (n <= 1) return (int)n; return 1 + log2(n >> 1); } bool calc() { for (int i = 2; i <= 40; i++) { if (bases[i] > bases[i - 1]) { tails[i - 1] += bases[i] - bases[i - 1]; bases[i] =...
5
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int v[n]; bool possible = 1; bool tab[1000042] = {0}; int valMax = 0; for (int i = 0; i < n; i++) { cin >> v[i]; valMax = max(valMax, v[i]); if (v[i] > i + 1) { possible = 0; } tab[v[i]] = 1; } if (!p...
3
#include <bits/stdc++.h> const int N = 50 + 10; char a[N][N]; int n, m; void read() { scanf("%d%d", &n, &m); for (int i = 0; i < n; ++i) { scanf("%s", a[i]); } } bool been[N][N]; int px[] = {1, -1, 0, 0}; int py[] = {0, 0, 1, -1}; bool ok(int x, int y) { return x >= 0 && x < n && y >= 0 && y < m; } int dfs(in...
3
#include <bits/stdc++.h> using namespace std; long long arr[100100], n, ans, temp, l, r, m; int main() { cin >> n >> m; if (n <= m) cout << n << endl; else { ans = m; temp = ceil(sqrtl((n - m) * 8 + 1)); ans += ceil((temp - 1) / (double)2.0000); cout << ans << endl; } return 0; }
3
#include <bits/stdc++.h> using namespace std; int main() { vector<int> months(12); int k, count = 0; scanf("%d", &k); for (int i = 0; i < 12; i++) scanf("%d", &months[i]); sort(months.begin(), months.end()); for (int i = 11; i >= 0; i--) { if (k <= 0) { printf("%d\n", count); return 0; }...
1
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; int i = 0, h = 0; while (i < s.length()) { if (s[i] == '<' && s[i + 1] >= 'a' && s[i + 1] <= 'z') { for (int j = 0; j < h; j++) { cout << " "; } cout << '<' << s[i + 1] << '>' << endl; h += 2; ...
2
#include <bits/stdc++.h> using namespace std; bool isVowel(char s) { if (s == 'a' || s == 'e' || s == 'i' || s == 'o' || s == 'u') { return true; } return false; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); string s1, s2, s3; int vowel_count_in_s1 = 0, vowel_count_in_s2 = 0, vowel_c...
1
#include <bits/stdc++.h> using namespace std; constexpr int kInf = int(1E9 + 10); int dp[260][260][260]; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n, q, a = 0, b = 0, c = 0, k, nxt; vector<int> v[26]; string s, qs, sa, sb, sc; cin >> n >> q >> s; sa.resize(1000); sb.resize(1000); ...
2
#include <bits/stdc++.h> using namespace std; long long n, k; int askcnt = 0; bool ask(long long l, long long r) { askcnt++; assert(askcnt <= 4500); printf("%lld %lld\n", l, r); fflush(stdout); char s[5]; scanf("%s", s); if (s[0] == 'Y') { if (l == r) exit(0); return true; } if (s[0] == 'N') r...
4
#include <bits/stdc++.h> #pragma warning(disable : 4996) using namespace std; const long double PI = acos(-1.0); const long double EPS = 1e-10; const long long LINF = 1e15; const int INF = 1e9 + 7; struct Actor { int s, f, k, id; Actor(int s = 0, int f = 0, int k = 0, int id = 0) { this->s = s; this->f = f;...
3
#include <bits/stdc++.h> using namespace std; const int N = 4e5; vector<int> g[N + 100]; vector<pair<int, int> > ele; int subt[N + 100], center, n, ans[N + 100]; void dfs(int v, int par) { int mx = 0; subt[v] = 1; for (auto it : g[v]) { if (it != par) { dfs(it, v); subt[v] += subt[it]; mx = ...
3
#include <bits/stdc++.h> using namespace std; char m[3][3][3][5]; int main() { int cnt0 = 0, cnt1 = 0; for (int i = 0; i < 3; ++i) for (int j = 0; j < 3; ++j) for (int k = 0; k < 3; ++k) { scanf("%s", m[i][k][j]); } int x, y; scanf("%d %d", &x, &y); x = (x - 1) % 3; y = (y - 1) % 3; ...
2
#include<bits/stdc++.h> using namespace std; int main(){ int h1, m1, s1, h2, m2, s2, t[4]; for(int i = 0; i < 3;i++){ cin>>h1>>m1>>s1>>h2>>m2>>s2; t[i] = (h2 * 3600 + m2 * 60 + s2) - (h1 * 3600 + m1 * 60 + s1); } for(int i = 0; i < 3; i++){ cout<<(t[i]/3600)<<" "<<((t[i]%3600)/60)<<" "<<((t[i]%3600)%60)<<...
0
#include <bits/stdc++.h> using namespace std; using ll=long long; #define MAX 5000 #define MOD 1000000007 ll solve(ll level,ll X){ if(X==0){ return 0; } if(X==((1ull<<(level+2))-3)){ return (1ull<<(level+1))-1; } ll x=(1ull<<(level+1))-1; if(X<x){ return solve(level-1,X-1); }else if(X>x){ ...
0
#include <bits/stdc++.h> using namespace std; unsigned a[2001]; int main() { int n, k; unsigned res = 0; cin >> n >> k; for (int i = 0; i < n; i++) { cin >> a[i]; } sort(a, (a + n)); int i = n - 1; while (i >= 0) { res += (a[i] - 1) * 2; i -= k; } cout << res << endl; return 0; }
2
#include <bits/stdc++.h> using namespace std; double const pi = 3.1415926536; int main() { int n, x, y; cin >> n >> x >> y; if (x == n / 2 && y == n / 2) { cout << "NO"; return (0); ; } if (x == n / 2 + 1 && y == n / 2 + 1) { cout << "NO"; return (0); ; } if (x == n / 2 + 1 && y ==...
2
#include <bits/stdc++.h> using namespace std; vector<long long> par; long long find(long long u) { if (u == par[u]) return u; return par[u] = find(par[u]); } void tests() { long long n; cin >> n; par.assign(n, 0); for (long long i = 0; i < n; i++) par[i] = i; vector<pair<long long, long long> > a(n); fo...
3
#include <bits/stdc++.h> using namespace std; const int MAX_N = 1e5 + 10; int N, M, S[MAX_N]; vector<int> tours[MAX_N]; vector<int> end_with[2]; vector<int> parity_last[2][2]; void init() { char _S[MAX_N]; scanf("%s", _S + 1); N = strlen(_S + 1); for (int i = 1; i <= N; i++) S[i] = _S[i] == 'R'; } void partitio...
5
#include <bits/stdc++.h> using namespace std; const int64_t DESPACITO = 2e18; const int INF = 2e9, MOD = 1e9 + 7; const int N = 2e5 + 5; int indeg[N]; struct DSU { int n, components; vector<int> data, rootID, roots; DSU(int n) : n(n), components(n), data(vector<int>(n + 1, -1)), root...
2
#include <iostream> #include <vector> using namespace std; void show_vec(vector<string> &vec){ int N = vec.size(); for(int i=0; i<N; ++i){ cout << vec[i]; if(i < N-1){ cout << " "; } } cout << endl; } int main(){ string temp; int N; cin >> N; vector <string> data1(N), data2(N); vector<int> keep_...
0
#include <bits/stdc++.h> using namespace std; const long long MOD = 998244353; long long gcd(long long a, long long b, long long& x, long long& y) { if (a == 0) { x = 0, y = 1; return b; } long long x1, y1; long long d = gcd(b % a, a, x1, y1); x = y1 - (b / a) * x1; y = x1; return d; } long long i...
4
#include <bits/stdc++.h> using namespace std; int a[105]; int main() { int n; cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; long long ans = 100000000; for (int x = 1; x <= n; x++) { int elc = 0; for (int i = 1; i <= n; i++) { if (x >= i) elc += 4 * (x - 1) * a[i]; else ...
1
#include <bits/stdc++.h> using namespace std; int T, N; char S[300007], p[300007]; int End[300007], ans[300007], length[300007], num[300007]; vector<int> Spot[300007]; set<int> mch[300007]; queue<int> q; struct State { int next[26]; int fail, cnt; } Tree[300007]; struct Aho { int Size; void init() { Size = ...
4
#include <bits/stdc++.h> const int N = 1000005; int n, m, typ, o1, o2, h[N], nxt[N], adj[N], x[N], y[N], t, rd[N], q[N], sz[N]; bool tag[N]; inline void topo() { register int top, top1, top2; top1 = top2 = 0; for (register int i = 1; i <= n; ++i) if (!rd[i]) q[++top2] = i; while (top1 < top2) { top = q[...
6
#include <bits/stdc++.h> using namespace std; const int inf = 1e9; const long long Inf = 1e10; const int N = 100005; const int P = 1000000007; int IN() { int x = 0; int f = 0, ch = 0; for ((ch = getchar()); ch < 48 || ch > 57; (ch = getchar())) f = (ch == '-'); for (; ch >= 48 && ch <= 57; (ch = getchar())) ...
6
#include <bits/stdc++.h> using namespace std; int main() { int n,m; cin>>n>>m; int h=0; int g=1000000000; for(int i=0;i<m;i++){ int a,s; cin>>a>>s; h=max(h,a); g=min(g,s); } if(h>g){ cout<<0<<endl; } else{ cout<<g-h+1<<endl; } }
0
#include <bits/stdc++.h> using namespace std; typedef long long ll; int n, a[200005]; ll ans; int main() { cin >> n; for (int i=0; i<n; i++) cin >> a[i]; sort(a, a+n, greater<int>()); for (int i=0; i<n-1; i++) ans+=a[(i+1)/2]; cout << ans; }
0
#pragma GCC target ("avx2") #pragma GCC optimize ("O3") #pragma GCC optimize ("unroll-loops") #include <bits/stdc++.h> #include <math.h> using namespace std; void __print(bool x) {cerr << (x ? "true" : "false");}void __print(int x) {cerr << x;} void __print(long x) {cerr << x;} void __print(long long x) {cerr << x;} v...
2
#include <bits/stdc++.h> using namespace std; bool f[10000005]; int main() { int n; cin >> n; memset(f, true, sizeof(f)); f[1] = false; for (int i = 2; i * i <= 10000000; i++) { if (f[i] == false) continue; int j = i * i; while (j <= 10000000) { f[j] = false; j += i; } } for (i...
2
#include <bits/stdc++.h> using namespace std; int main() { int no_of_elements; scanf("%d", &no_of_elements); vector<int> element(no_of_elements); for (int i = 0; i < no_of_elements; i++) scanf("%d", &element[i]); sort((element).begin(), (element).end()); if (no_of_elements == 1) { printf("%d", element[0...
1
#include <bits/stdc++.h> using namespace std; const int INF = 1e9 + 10; namespace std { bool operator<(const complex<int> &c1, const complex<int> &c2) { if (c1.imag() == c2.imag()) { return c1.real() < c2.real(); } else { return c1.imag() < c2.imag(); } } } // namespace std double cross_product(complex...
0
#include <bits/stdc++.h> using namespace std; long long int Pow(long long int B, long long int P) { long long int R = 1; while (P > 0) { if (P % 2 == 1) R = (R * B); P /= 2; B = (B * B); } return R; } int BigMod(long long int B, long long int P, long long int M) { long long int R = 1; while (P >...
2
#include <bits/stdc++.h> using namespace std; const int N = 2e3 + 100; const int MOD = 998244353; string s; struct Graph { bool bipartite; int color[N]; int n; struct Edge { int u, v, same; Edge(int u = 0, int v = 0, int same = 0) : u(u), v(v), same(same){}; int nxt(int x) { return x ^ u ^ v; } };...
4
#include<iostream> #include<cstdio> #include<cstdlib> #include<cstring> #include<algorithm> using namespace std; const int mod=1000000007; int fpow(int x,int y) { if(y==0) return 1; int ret=fpow(x,y>>1); ret=(long long)ret*ret%mod; if(y&1) ret=(long long)ret*x%mod; return ret; } int q[10101],qn; int f[10101]; ...
0
#include <bits/stdc++.h> using namespace std; const int maxn = 5e5 + 10; int n, r; long long a[maxn], b[maxn], S; int base[70]; void Gauss() { for (int i = 1; i <= n; i++) { for (int j = 60; j >= 0; j--) { if (a[i] >> j & 1) { if (!base[j]) { base[j] = i; r++; break; ...
1
#include <iostream> using namespace std; int res[200000]; int main(){ int n,en; cin>>n; for(int i=1;i<n;i++){ cin>>en; en--; res[en]++; } for(int i=0;i<n;i++)cout<<res[i]<<endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; int main() { unsigned long long a, b, c, p, q; cin >> a; if (a == 1 || a == 2) { cout << -1; return 0; } if (a % 2 == 1) { b = (a * a - 1) / 2; c = b + 1; } else { p = a / 2; q = 1; b = p * p - q * q; c = p * p + q * q; } if (...
3
#include <bits/stdc++.h> int main() { char str[1000][1000], str1[] = "bcdfghjklmpqrstvwxyz"; int i, j, k, c = 0, s = 0; scanf("%s", str[0]); for (i = 0; i < strlen(str[0]); i++) { for (j = 0; j < strlen(str1); j++) { if (str[0][i] == str1[j]) { s = s + 1; if (str[0][i + 1] == 'a' || st...
1
#include <bits/stdc++.h> using namespace std; long long int modular_pow(long long int base, long long int exponent, int modulus) { long long int result = 1; while (exponent > 0) { if (exponent % 2 == 1) result = (result * base) % modulus; exponent = exponent >> 1; base = (base ...
4
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 5; const int lg = 21; int a[N]; int dp[N][lg]; int last[lg]; int n, q; bool query(int x, int y) { int r = 0; for (int k = 0; k < lg; k++) { if ((a[x] >> k) & 1) { r = max(r, dp[y][k]); } } return r >= x; } int main() { cin >> n >>...
3
#include <bits/stdc++.h> using namespace std; int main() { int m, n; cin >> m >> n; int a[m][n]; for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) { cin >> a[i][j]; } } bool possible = true; for (int i = m - 2; i > 0; i--) { for (int j = n - 2; j > 0; j--) { int amin = min(...
3
#include<iostream> using namespace std; int main() { int a,b; cin>>a>>b; b=b-1; a=a-1; if(b%a==0) cout<<b/a; else cout<<(b/a)+1; }
0
#include <bits/stdc++.h> using namespace std; int Set(int N, int pos) { return N = N | (1 << pos); } int reset(int N, int pos) { return N = N & ~(1 << pos); } bool check(int N, int pos) { return (bool)(N & (1 << pos)); } inline int addmod(int x, int y) { return (x % 1000000007 + y % 1000000007) % 1000000007; } inline...
4
#include <bits/stdc++.h> using namespace std; void oj() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); } void solve() { long long n; cin >> n; vector<long long> v(n); map<long long, long long> mp; long long maxi = -1, start = -1; for (long long i = 0; i < n; i++) { cin >> v[i]; mp[v[i]] =...
6
//#pragma GCC optimize(2) #include<cstdio> #define L 1<<23 #define C (c=*A++) #define ENS //__attribute__((optimize("-O2"))) #define NES //__attribute__((optimize("-O2"))) __inline__ __attribute__((always_inline)) #define N 1000001 int MAPLE,n,l[N],r[N],cnt,last,wt,ss[19];char fl[L],*A=fl,s[N],t[N];bool fg=true; NES v...
0
#include <bits/stdc++.h> using namespace std; long long powmod(long long a, long long p, long long m) { long long r = 1; while (p) { if (p & 1) r = r * a % m; p >>= 1; a = a * a % m; } return r; } const int MaxN = 5e3 + 555; const long long INF = 1e9 + 10; const long long MOD = 1e9 + 7; int n, a, b,...
3
#include <bits/stdc++.h> using namespace std; const int Maxn = 22, INF = INT_MAX >> 1; int n, m, a[Maxn][Maxn], d[1 << Maxn]; char s[Maxn][Maxn]; int findlowzero(int x) { int i; for (i = 0; i < Maxn; i++) if (!((x >> i) & 1)) return i; return 19; } int main(int argc, const char* argv[]) { ios::sync_with_std...
5
#include<iostream> using namespace std; int a,b,c; int main(){ cin>>a>>b>>c; cout<<(a-c)/(b+c)<<endl; }
0
#include <bits/stdc++.h> using namespace std; const int N = 200005; int n, m, k, a[N], deg[N], id[N], cnt, mi[N], mx[N], ans[N]; bool used[N]; vector<int> g[N], r[N]; vector<pair<int, int> > v[N]; queue<int> q; priority_queue<pair<int, int>, vector<pair<int, int> >, greater<pair<int, int> > > pq; int...
2
#include <bits/stdc++.h> using namespace std; int main() { long long int t, n, k; cin >> t; while (t--) { cin >> n >> k; long long int a[n], b[n]; for (long long int i = 0; i < n; i++) { cin >> a[i]; b[i] = a[i] + k; } long long int *mini = min_element(b, b + n); int flag = 0; ...
2
#include <bits/stdc++.h> using namespace std; int dfs(vector<vector<int> > &v, int node, vector<int> &val, vector<int> &a, int parent, int psum, int d) { int n = v[node].size(); if (d % 2 && a[node] < psum) return 0; else if (d % 2) val[node] = a[node] - psum; else { int minimum = INT_MAX; ...
1
#include <bits/stdc++.h> using namespace std; unsigned long long curr_b, curr_s, curr_c; unsigned long long b = 0, s = 0, c = 0; unsigned long long cost_b, cost_s, cost_c, money; bool solve(unsigned long long mid) { unsigned long long need_b = mid * b, need_c = mid * c, need_s = mid * s; unsigned long long temp_b =...
3
#include <bits/stdc++.h> using namespace std; int solve(int s, vector<int> ar) { int n = ar.size(); int times = 0; set<int> usados; for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) if (ar[i] + ar[j] == s && i != j && (usados.find(i) == usados.end()) && (usados.find(j) == usados.end())...
3
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c, d; cin >> a >> b >> c >> d; int m_score = max(3 * a / 10, a - a * c / 250); int v_score = max(3 * b / 10, b - b * d / 250); if (m_score == v_score) { cout << "Tie" << endl; } else if (m_score > v_score) { cout << "Misha" << endl...
1
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; int u = 0, l = 0, up[s.length()], lo[s.length()]; for (int i = 0; i < s.length(); i++) { if (s[i] > 92) l++; else u++; up[i] = u; lo[i] = l; } int ans = min(l, u); for (int i = 0; i < s.length() - 1;...
3
#include <bits/stdc++.h> using namespace std; const int INF = 1000000000; int n, k; int a[1005]; int mn[405][405]; int mx[405][405]; int s[405]; int dp[55][405][405]; int get(int l, int r) { int ret = s[r] - (l ? s[l - 1] : 0); return ret; } int main() { int n, k; cin >> n >> k; for (int(i) = (0); (i) < (n); ...
5
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ; int t = 1; cin >> t; while (t--) { long long int a = 0, b = 0, c = 0, d = 0, e = 0, p = 0, q = 0, r = 0; long long int ans = 0, res = 0, cnt = 0, sum = 0, diff = 0, mul = 1...
2
#include <bits/stdc++.h> using namespace std; using namespace std; template <typename T, typename U> std::istream& operator>>(std::istream& i, pair<T, U>& p) { i >> p.x >> p.y; return i; } template <typename T> std::istream& operator>>(std::istream& i, vector<T>& t) { for (auto& v : t) { i >> v; } return ...
2
#include <bits/stdc++.h> using namespace std; int main() { string a, b; cin >> a >> b; int l = b.size(); int st = a.size() - 1; int ar[l + 3]; memset(ar, -1, sizeof ar); ar[l] = st + 1; for (int i = l - 1; i >= 0; i--) { while (st >= 0 && a[st] != b[i]) { st--; } if (st >= 0) { a...
4
#include <bits/stdc++.h> using namespace std; int main() { int n, m, h; cin >> n >> m >> h; vector<int> front_view; vector<int> left_view; for (int i = 0; i < m; i++) { int input; cin >> input; front_view.push_back(input); } for (int i = 0; i < n; i++) { int input; cin >> input; le...
2
#include <iostream> using namespace std; int main(void){ int f, c; cin >> f; c = (f-30)>>1; cout << c << endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; int b[10000005]; int n, a; long long ans; int main() { cin >> a >> n; for (int i = 1; i * i <= 10 * 1000 * 1000; i++) { int cur = i * i; int j = 1; while (cur * j <= a + n - 1) b[cur * j] = j++; } for (int i = a; i <= a + n - 1; i++) ans += b[i]; cout ...
4