solution
stringlengths
52
181k
difficulty
int64
0
6
#include <bits/stdc++.h> using namespace std; const int MaxN = 200005; const long long Mod = 1000000007; int n, m, k; pair<int, int> a[MaxN]; long long dp[MaxN]; long long fct[MaxN], ifct[MaxN]; long long Power(long long a, long long b) { long long Resuft = 1; while (b) { if (b & 1) { Resuft = Resuft * a ...
3
#include <bits/stdc++.h> using namespace std; int main() { long long int n; cin >> n; long long int m = n; for (long long int i = 2; i * i <= n; i++) { if (n % i == 0) { while (n % i == 0) n /= i; if (n != 1) cout << "1"; else cout << i; break; } } if (n == m)...
1
#include <iostream> #include <algorithm> using namespace std; int main(){ int a[5]; char t; while(cin >> a[0] >> t >> a[1] >> t >> a[2] >> t >> a[3] >> t >> a[4]){ sort(a,a+5); if(a[0] == a[3] || a[1] == a[4]){ cout << "four card" << endl; } else if((a[0] == a[1] && a[2] == a[4]) || (a[0] == a[2] && a[3]...
0
#include <bits/stdc++.h> using namespace std; int ccost(int h, int a, int b) { h = h % (a + b); if (h == 0) { return (a + b) / (a) + ((a + b) % (a) != 0) - 1; } else if (h <= a) return 0; else { return (h) / (a) + ((h) % (a) != 0) - 1; } } int main() { int n, a, b, k; cin >> n >> a >> b >> k; ...
4
#include <bits/stdc++.h> #define ll long long using namespace std; const int maxn = 1000100; const int base = 1e9+7; int n; ll fac[maxn],ifac[maxn]; ll pw(int a,int n) { if (n==0) return 1ll; if (n==1) return a; ll tg = pw(a,n/2); tg = (tg*tg) % base; if (n%2) return (tg*a)%base; return tg; ...
0
#include<iostream> #include<vector> #include<algorithm> #include<map> #include<math.h> #include<complex> #include<queue> #include<iomanip> using namespace std; #define rep(i,n) for(int i = 0 ; i < n ; ++i) using ll = long long; using ld = long double; using Point = complex<ld>; const ld eps = 1e-9; bool eq(ld a, ld b...
0
#include <bits/stdc++.h> using namespace std; map<string, string> st; char a[1000]; char b[1000]; char br[1000]; char k; int main() { long long int n, m, i, j; cin >> n >> m; for (i = 0; i < n; i++) { cin >> a >> b; st[b] = a; } for (i = 0; i < m; i++) { cin >> a; cin >> b; for (j = 0; b[j...
2
#include <bits/stdc++.h> using namespace std; int a[10000000]; int l[10000000]; int r[10000000]; int x[10000000]; int z[10000000]; int main() { int n, m; cin >> n >> m; for (int i = 0; i < n; i++) scanf("%d", &a[i]); for (int i = 0; i < m; i++) { scanf("%d%d%d", &l[i], &r[i], &x[i]); l[i]--; r[i]--;...
3
#include <bits/stdc++.h> using namespace std; long long n, m, num[100100], cnt[100100], qzc[100100], qzs[100100]; namespace Get { long long g[100100][20]; inline long long gcd(long long u, long long v) { for (; u && v && u != v;) { swap(u, v); u %= v; } return max(u, v); } void work() { long long i, j, ...
5
#include <bits/stdc++.h> using namespace std; int main() { string S; cin >> S; long long a = 0, b = 0, c = 0; for (int i = 0; i < S.size(); ++i) { if (S[i] == 'o') { b += a; } else if (i > 0 && S[i - 1] == 'v') { a++; c += b; } } cout << c << endl; }
2
#include <bits/stdc++.h> using namespace std; const int mxn = 2006; int n; int a[mxn]; int ans; vector<pair<int, int>> sol; void Swap(int x, int y) { sol.push_back({x, y}); swap(a[x], a[y]); ans += abs(x - y); } void Output() { printf("%d\n", ans); printf("%d\n", int(sol.size())); for (auto &i : sol) printf...
5
#include <bits/stdc++.h> using namespace std; int find(vector<int> &V, int x){ if(V[x]==x) return x; else{ int ret = find(V,V[x]); V[x] = ret; return ret; } } int main(){ int N,M; cin >> N >> M; vector<int> V(N); for(int i=0;i<N;i++) V[i] = i; for(int i=0;i<M;i++){ int a,b; cin ...
0
#include<bits/stdc++.h> using namespace std; int main() { int A,B;cin>>A>>B; cout<<max(0,A-2*B); return 0; }
0
#include <bits/stdc++.h> using namespace std; int main() { int n; scanf("%d", &n); int a[n]; for (int i = 0; i < n; i++) scanf("%d", &a[i]); sort(a, a + n); int ans = 0; for (int i = 1; i < n; i++) { ans += a[i] - a[i - 1] - 1; } cout << ans; return 0; }
1
#include <bits/stdc++.h> using namespace std; int n; int a[1000]; bool check() { for (int i = 0; i < n; i++) { if (a[i] != i) return false; } return true; } int main() { ios_base::sync_with_stdio(0); cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n; i++) { if (check()) { ...
2
#include <bits/stdc++.h> using namespace std; using lint = long long; template <typename T> using vc = std::vector<T>; void solve(istream& cin, ostream& cout) { if (rand() % 2) { cout << "red"; } else { cout << "black"; } } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); so...
4
#include <cstdio> #include <cstring> int main() { int h, w; char s[6]; scanf("%d%d", &h, &w); for (int i = 0; i < h; ++i) { for (int j = 0; j < w; ++j) { scanf("%s", s); if (memcmp(s, "snuke", 5) == 0) { printf("%c%d\n", j + 'A', i + 1); return 0; } } ...
0
#include<bits/stdc++.h> #define pi 3.1415926535897932384626 using namespace std; struct P{ int x,y; bool operator < (const P &a )const{ //if(y!=a.y) return y>a.y; }; }; int a,b,c,d,i,k,n,m,e,dx[10]={1,0,-1,0,1,1,-1,-1},dy[10]={0,1,0,-1,1,-1,1,-1}; long double o[613],x; int l[610]; int j[302]; lon...
0
#include <bits/stdc++.h> using namespace std; double maxi[100005], mini[100005], prefixA[100005], prefixB[100005], diceA[100005], diceB[100005], A, B, C, discriminant; int main() { int i, j, t, n, m, k, l, r, temp, flag, result, cnt; scanf("%d", &n); for (i = 1; i <= n; i++) scanf("%lf", &maxi[i]); for (i =...
4
#include<bits/stdc++.h> using namespace std; using P = pair<int, int>; const int M = 1000000007; int main() { int w, h, n; cin >> w >> h >> n; vector<P> p(n + 2); for (int i = 0; i < n; ++i) { cin >> p[i].first >> p[i].second; } int S = n, T = n + 1; p[S] = P(1, 1); p[T] = P(w,...
0
#include <bits/stdc++.h> using namespace std; int main() { int n, l, i, k, go = 0, j; string x; cin >> n >> x; char a[n]; for (i = 0, k = 0, j = 0; j < n; j++) { if (n % 2 != 0) { l = n / 2; if (j % 2 == 0) { a[l - i + k] = x[j]; } else { a[l - i] = x[j]; go++; ...
2
#include <bits/stdc++.h> struct point { long long x, y; } a[400001]; long long n, i, k, ans; bool comp1(point x, point y) { return x.x < y.x || x.x == y.x && x.y < y.y; } bool comp2(point x, point y) { return x.y < y.y || x.y == y.y && x.x < y.x; } int main() { scanf("%I64d\n", &n); for (i = 1; i <= n; ++i) scanf...
3
#include <bits/stdc++.h> using namespace std; int main() { int t, temp; float f_angle; int i_angle; cin >> t; for (int i = 0; i < t; i++) { cin >> temp; f_angle = 360.0 / (180 - temp); i_angle = 360 / (180 - temp); if (i_angle == f_angle) cout << "YES" << endl; else cout << "NO...
1
#include <bits/stdc++.h> using namespace std; const int maxn = 1000010; const int mod = 1000000007; const int N = 1000000; int p[maxn], inv[maxn]; int n, m, ans; int pow(int a, int b) { int ret = 1; for (; b; b >>= 1) { if (b & 1) ret = 1ll * ret * a % mod; a = 1ll * a * a % mod; } return ret; } int C(i...
4
#include <bits/stdc++.h> using namespace std; using ll = long long; void solve() { ll n, fl = 0; cin >> n; char ar[n][n]; unordered_map<char, ll> mp; for (ll i = 0; i < n; i++) { for (ll j = 0; j < n; j++) { cin >> ar[i][j]; mp[ar[i][j]]++; } } if (mp.size() != 2) { cout << "NO" <<...
1
#include <bits/stdc++.h> using namespace std; #define REP(i,a,b) for (int i = (a); i <= (b); ++i) #define REPD(i,a,b) for (int i = (a); i >= (b); --i) #define FORI(i,n) REP(i,1,n) #define FOR(i,n) REP(i,0,int(n)-1) #define mp make_pair #define pb push_back #define pii pair<int,int> #define vi vector<int> #define ll lon...
0
#include <bits/stdc++.h> #define ll long long #define rep(i,n) for(int i=0;i<n;i++) using namespace std; typedef pair<ll, ll>P; ll gcd(ll x, ll y) { if (y == 0)return x; return gcd(y, x % y); } ll lcm(ll x, ll y) { return x * y / gcd(x, y); } ll basic[33333]; signed main(){ ll n,memo=0,ans=0; cin>>n; for(int i=1;...
0
#include <bits/stdc++.h> using namespace std; #define forn(i, n) for(int i=0; i<(n); i++) #define readVec(v) forn(i, v.size()){cin >> v[i];} #define printArr(arr, n) forn(i, n){if (i) cout << " "; cout << arr[i];} cout << endl; #define pb push_back #define mp make_pair #define MOD 1000000007 #define f first #define s ...
6
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; int n; long long sum[N], ans[N], cur; long long seg[1 << 20]; set<int> nw; void update(int i, int v, int ni = 0, int ns = 0, int ne = n) { if (ns > i || ne < i || ns > ne) return; if (ns == ne && ns == i) { seg[ni] += v; return; } if (...
4
#include <bits/stdc++.h> using namespace std; const int N = 2003; const long long mod = 998244353; int n, m, k; long long F[N][N]; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> m >> k; for (int i = 1; i <= n; ++i) { F[i][0] = m; for (int t = 1; t <= k; ++t) F[i][t] =...
3
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false), cin.tie(nullptr); int fret[6]; for (int i = 0; i < 6; i++) cin >> fret[i]; sort(fret, fret + 6); int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; i++) cin >> a[i]; sort(a.begin(), a.end()); set<tuple<int...
1
#include"bits/stdc++.h" int main(){long long h;std::cin>>h;printf("%lld\n",(1ll<<(int)std::ceil(std::log2(h+1)))-1);}
0
#include<iostream> #include<algorithm> using namespace std; #define MAX 256 #define INF 1000000 struct edge { int money; int time; }; int main(){ int n, m; int count; edge G[120][120]; while(cin >> n >> m, n || m){ for(int i=0; i < 120; i++){ for(int j=0; j < 120; j++){ G[i][j].money = INF; G[i][...
0
#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]; int amin = a[0], oppV = a[0]; for (int i = 1; i < n; i++) { if (amin < a[i]) amin = a[i]; oppV = oppV + a[i]; } long int totalV, k; for (int j = amin; j < 10000; j++) ...
1
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 5; int N, M, K; long long ans; map<int, int> A[maxn << 1], B[maxn << 1]; map<pair<int, int>, int> S; int GO(int X, int Y, int D) { int Sx(X), Sy(Y), Sd(D); (S.insert(make_pair(pair<int, int>(X, Y), 0)).first->second |= (0)); A[((X) + (Y))].inser...
5
#include<bits/stdc++.h> using namespace std; int n, m, q, dot[100001] = {}, maxp[100001] = {}; vector<int> g[100001]; int v[100001], d[100001], c[100001]; void dfs(int col, int step, int f) { if (dot[f] == 0) dot[f] = col; if (maxp[f] >= step) return; maxp[f] = step; int length = g[f].size(); for (int i = 0; ...
0
#include <bits/stdc++.h> using namespace std; long long t, a, b, q, l, r, l0, r0, mi, ma, tot, ans, x[40005]; long long calc2(long long r) { int pos = lower_bound(x + 1, x + tot + 1, r) - x; return x[pos] == r ? pos : pos - 1; } long long calc1(long long l) { return tot + 1 - (lower_bound(x + 1, x + tot + 1, l) -...
3
#include <bits/stdc++.h> using namespace std; int main() { int n; long long L; cin >> n >> L; vector<long long> a(n); for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 1; i < n; i++) { a[i] = min(2 * a[i - 1], a[i]); } long long ans = 1e18, sum = 0; for (int i = n - 1; i >= 0; i--) { int a...
3
#define _USE_MATH_DEFINES #define INF 100000000 #include <iostream> #include <sstream> #include <cmath> #include <cstdlib> #include <algorithm> #include <queue> #include <stack> #include <limits> #include <map> #include <string> #include <cstring> #include <set> #include <deque> #include <bitset> #include <list> #incl...
0
#include <iostream> using namespace std; int main() { long long n,m,l,sum; cin>>n>>m>>l; int a[n][m], b[m][l]; for (int i=0; i<n; i++) for (int j=0; j<m; j++) cin>>a[i][j]; for (int i=0; i<m; i++) for (int j=0; j<l; j++) cin>>b[i][j]; for (int i=0; i<n; i++) { for (int j=0; j<l; j+...
0
#include <bits/stdc++.h> using namespace std; const long long gg = 0x7fffffff; struct node { int p, e; } per[230001]; int n, k, ks; long long ans; bool u[230001]; bool cmp1(node a, node b) { return a.p > b.p; } bool cmp2(node a, node b) { return a.e < b.e; } long long work(int p) { long long ret = 0; memset(u, 0,...
3
#include <bits/stdc++.h> using namespace std; char solve(long long n, long long k, long long x) { if (k == 0) return '.'; if (n % 2 == 0) { if (k <= n / 2) { if (x % 2 == 1 || x / 2 + k <= n / 2) return '.'; else return 'X'; } else { if (x % 2 == 0 || x / 2 + k >= n) ...
3
#include <bits/stdc++.h> using namespace std; int main() { int r, c, ans[10][10], tabler[10], tablec[10], cakes = 0, i, j, ch; char in[10][10]; for (i = 0; i < 10; i++) tabler[i] = tablec[i] = 0; cin >> r >> c; for (i = 0; i < r; i++) { ch = getchar(); for (j = 0; j < c; j++) { cin >> in[i][j]; ...
1
#include <bits/stdc++.h> using namespace std; void flash() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } const long long N = 1e4 + 10; long long sm[N + 5]; void pre() { sm[0] = 0; for (long long i = 1; i < N; i++) { sm[i] = (sm[i - 1] + i); } } long long glob, endsum, stsum; vecto...
1
#include<iostream> using namespace std; long long n,k,w[100001],ma=0; int fp(long long p){ long long sum=0,v=0; for(int i=0;i<k;i++){ sum=0; while(sum+w[v]<=p){ sum+=w[v]; v++; if(v==n)return v; } } return v; } int main(){ cin>>n>>k; for(int i=0;i<n;i++)cin>>w[i]; long lon...
0
#include <bits/stdc++.h> using namespace std; int main() { int t, n, a, b, ans; cin >> n; while (n--) { cin >> a >> b; ans = ((24 - a) * 60) - (b); cout << ans << endl; } return 0; }
1
#include <bits/stdc++.h> using namespace std; long long modpow(long long a, long long n, long long temp) { long long res = 1; while (n > 0) { if (n & 1) res = (res * a) % temp; a = (a * a) % temp; n >>= 1; } return res % temp; } int main() { int n; scanf("%d", &n); int a; int i; map<int, i...
3
#include <bits/stdc++.h> using namespace std; int dp[5000 + 10][5000 + 10], csum[5000 + 10]; int my_abs(int a, int b) { return a > b ? a - b : b - a; } int main() { int n, st, nvr, k, flr, mv, df, l, r, i, j; scanf("%d %d", &n, &st); scanf("%d %d", &nvr, &k); for (mv = 0; mv <= k; mv++) { for (flr = 1; flr ...
3
#include <iostream> #include <vector> #include <string> #include <map> #include <algorithm> #define REP(i,n) for(int i=0;i<(int)(n);i++) using namespace std; int main() { int n; cin>>n; vector<int> t(n-1); REP(i,n-1) cin>>t[i]; vector<int> dpa(n+2,100000000); vector<int> dpb(n+2,100000000); dpa[1] = 0;...
0
#include <bits/stdc++.h> using namespace std; int main() { short base = 0, c = 0, car; int a, b, t, sum; scanf("%d%d", &a, &b); t = a; while (t) { base = (base > t % 10) ? base : t % 10; t /= 10; } t = b; while (t) { base = (base > t % 10) ? base : t % 10; t /= 10; } base++; car = ...
2
#include <bits/stdc++.h> #define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define ll long long #define en cin.close();return 0; #define INF ((ll)(2e18)) #define pb push_back #define fi first//printf("%lli\n",cur); #define se second//scanf("%lli",&n); using namespace std; const ll N = 3e5+5; ll ans[N], m...
3
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; int k; cin >> k; for (int i = 0; i < s.size(); ++i) { int d = (26 - (s[i] - 'a')) % 26; if (d == 0) continue; if (d <= k) { s[i] = 'a'; k -= d; } } if (k > 0) s.back() = 'a' + (s.back() -...
0
#include <bits/stdc++.h> using namespace std; int main() { int k, l, res = -1; cin >> k >> l; while (l % k == 0) { l /= k; res += 1; } if (res >= 0 && l == 1) { cout << "YES" << "\n" << res; } else { cout << "NO"; } }
1
#include <bits/stdc++.h> using namespace std; int main(){ int a,b,c,d; cin>>a>>b>>c>>d; cout<<(a!=c? 1:0)<<endl; }
0
#include <bits/stdc++.h> using namespace std; long long a[100500]; int main() { map<long long, long long> mp; int n; cin >> n; long long i = 0, x = 0, y, r = 0; while (i++ < n) { cin >> y; r = max(r, ++mp[x += y]); } cout << n - r << endl; }
3
#include <bits/stdc++.h> using namespace std; int main() { int t; string str[105]; string temp; cin >> t; for (int i = 0; i < t; i++) { cin >> str[i]; } for (int i = 1; i < t; i++) { for (int j = 1; j < t; j++) { if (str[j - 1].length() > str[j].length()) { temp = str[j]; str...
2
#include <bits/stdc++.h> using namespace std; int main() { long long int n; cin >> n; long long int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } sort(a, a + n); int c = 1; for (int i = 0; i < n; i++) { if (a[i] >= c) { c++; } } cout << c << endl; }
2
#include <bits/stdc++.h> using namespace std; const int N = 110; int dx[] = {1, 0, -1, 0}; int dy[] = {0, 1, 0, -1}; char pan[N][N]; int prv[N][N], vis[N][N]; pair<int, int> que[N * N]; inline pair<int, int> ask(char c) { cout << c << endl; cout.flush(); int x, y; cin >> x >> y; return make_pair(x, y); } int ...
4
#include <bits/stdc++.h> using namespace std; const long long MAXN = 1e2 + 10; const long long MAXK = 22; const long long Mod = 1e9 + 7; vector<long long> vertex[MAXN]; long long dp[MAXN][MAXK][MAXK]; long long tmp[MAXK][MAXK]; bool check[MAXN]; long long k; void dfs(long long v) { check[v] = true; dp[v][k + 1][1] ...
5
#include<iostream> using namespace std; int main(){ int p; int n[1000000]; while(cin >> p, p){ int ans = 0; for(int i=0; i < p; i++){ cin >> n[i]; } for(int i=0; i < p; i++){ for(int j = 0; j < p-i-1; j++){ if(n[j] > n[j+1]){ swap(n[j], n[j+1]); ans++; } } } cout << ans << en...
0
#include <bits/stdc++.h> using namespace std; map<long long, long long> mp; vector<long long> Lis; int main() { long long a, b, n; cin >> n >> a >> b; int sw = 0; if (a > b) { sw = 1; swap(a, b); } for (int i = 0; i < n; i++) { int val; scanf("%d", &val); Lis.push_back(val); mp[val] ...
2
#include <bits/stdc++.h> using namespace std; long long a[1005]; signed main() { long long n, k; scanf("%lld%lld", &n, &k); long long ans = 0; for (long long i = 1; i <= n; i++) scanf("%lld", &a[i]); sort(a + 1, a + 1 + n); for (long long i = 1; i <= n; k = max(k, a[i]), i++) while (a[i] > k * 2) { ...
3
#include <bits/stdc++.h> using namespace std; struct node { int s, f, c, r; }; vector<node> vec[420]; pair<int, int> st[420]; int f[420][420]; int n, m, a[420], tops, mx[420][420]; long long ans; int main() { scanf("%d %d", &n, &m); for (register int i = 1; i <= n; i++) scanf("%d", &a[i]); for (register int i =...
6
#include <bits/stdc++.h> int main() { char S[100001], s[31]; int i, r = 0; scanf("%s", S); scanf("%s", s); int len = strlen(s); int Len = strlen(S); for (i = 0; i < Len; i++) { if (!strncmp(S + i, s, len)) { i += len - 1; r++; } } printf("%d\n", r); }
2
#include <bits/stdc++.h> using namespace std; class Init { public: Init() noexcept try { ios_base::sync_with_stdio(false); cin.tie(nullptr); } catch (...) { cerr << "Init constructor threw an exception" << endl; terminate(); } } __init __attribute__((unused)); using ll = long long; using ld = lon...
1
#include <bits/stdc++.h> #define rep(i,n) for(int i=0;i<(int)(n);i++) #define rep1(i,n) for(int i=1;i<=(int)(n);i++) #define all(c) c.begin(),c.end() #define pb push_back #define fs first #define sc second #define show(x) cout << #x << " = " << x << endl #define chmin(x,y) x=min(x,y) #define chmax(x,y) x=max(x,y) using...
0
#include <bits/stdc++.h> using namespace std; bool bst; int i, j, k, l, n, m, s, an, tot, len, L, P; class arr { public: int d, m, r, son, fa; bool f1, f2, f3; } a[4]; bool ff[47][47][47][8][8]; void dfs(int n1, int n2) { if (ff[a[1].d][a[2].d][a[3].d][n1][n2]) return; for (int i = 1; i <= 3; i++) if (a[i]...
5
#include <bits/stdc++.h> using namespace std; const int Max = 2000; int n, k; int a[Max]; int b[Max]; bool cal(int c) { int t = k; for (int i = 0; i < n; i++) { if (a[i] * c > b[i]) t = t - a[i] * c + b[i]; if (t < 0) { return false; } } return true; } int main() { cin >> n >> k; for (int ...
4
#include <bits/stdc++.h> using namespace std; const int V = 1101000; const int P = 1000000007; long long rev[30][2]; int a[V]; int tr[V], N; void update(int k, int v) { while (k <= N) { tr[k] += v; k += k & -k; } } int read(int k) { int ret = 0; while (k > 0) { ret += tr[k]; k -= k & -k; } r...
3
#include <bits/stdc++.h> using namespace std; int n; int a[105]; int f = 10, ny = 360, e = 720; int c, sh; int main() { cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); for (int i = 0; i < n; i++) { f += a[i]; if (f > e) break; c++; if (f > ny) sh += f - ny; } cout << c << ...
4
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") const long long MOD = 1e9 + 7; const long long MAXN = 1e5 + 7; const long long INF = 2e9; const long long BIG_INF = 2e18; const long long LOG = 20; const double eps = 1e-7; mt19937 engine(chrono::system_cloc...
5
#include <bits/stdc++.h> using namespace std; const int Maxn = 100005; const int Maxt = 300005; long long t[7][12][Maxt]; int a[Maxn]; void modify(int t1, int t2, int l, int r, int p, int k, long long val) { if (l == r) { t[t1][t2][p] = val; return; } int m = (l + r) / 2; if (k <= m) { modify(t1, t2...
4
#include <bits/stdc++.h> using namespace std; int i, n; int main() { scanf("%d", &n); for (i = 1; i <= 4; i++) { int s1, c1, s2, c2, c = 0; scanf("%d %d %d %d", &s1, &c1, &s2, &c2); c = min(s1, c1); if (c + min(s2, c2) <= n) { printf("%d %d %d", i, min(s1, c1), n - min(s1, c1)); return 0...
1
#include <bits/stdc++.h> using namespace std; int32_t main() { long long t; cin >> t; while (t--) { long long n; cin >> n; vector<long long> v(n), ans; set<long long> s; for (long long i = 1; i <= n; i++) s.insert(i); for (auto &i : v) cin >> i; ans.push_back(v[0]); s.erase(v[0]); ...
2
#include <bits/stdc++.h> using namespace std; struct node { int x, y; } a[105], b[105]; int sum1[105], sum2[105]; bool cmp(struct node a, struct node b) { return a.y > b.y; } int main() { int n; int count1 = 0, count2 = 0; cin >> n; for (int i = 0; i < n; i++) { int x, y; cin >> x >> y; if (x == 1...
2
#include <bits/stdc++.h> using namespace std; map<char, int> A; int main() { int n; string a; cin >> n >> a; sort(a.begin(), a.end()); cout << a << endl; }
1
#include <bits/stdc++.h> using namespace std; inline int read() { int s = 0, w = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') w = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { s = s * 10 + ch - '0'; ch = getchar(); } return s * w; } vector<int> v; pair<int...
3
#include <bits/stdc++.h> using namespace std; template <typename T, typename V> ostream &operator<<(ostream &os, const pair<T, V> pai) { return os << pai.first << ' ' << pai.second; } template <typename T> ostream &operator<<(ostream &os, const vector<T> v) { for (int i = 0, _i = (((int)(v).size())); i < _i; i++) c...
5
#include <bits/stdc++.h> std::vector<int> ans; std::vector<int> in; std::vector<int> out; int n, m; void transform(int now, int m) { for (int i = 0; i < m; i++) { if (i & 1) out[i / 2] = in[i]; else out[i / 2 + m / 2] = in[i]; } if (now & 1) return; if (m & 1) { for (auto i = 1; i < m; i...
2
#include <bits/stdc++.h> using namespace std; #define int long long #define all(v) (v).begin(), (v).end() #define resz(v, ...) (v).clear(), (v).resize(__VA_ARGS__) #define reps(i, m, n) for(int i = (int)(m); i < (int)(n); i++) #define rep(i, n) reps(i, 0, n) template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>...
0
#include <bits/stdc++.h> using namespace std; const int MAXSIZE = 10000020; int bufpos; char buf[MAXSIZE]; void init() { buf[fread(buf, 1, MAXSIZE, stdin)] = '\0'; bufpos = 0; } int readint() { int val = 0; for (; !isdigit(buf[bufpos]); bufpos++) ; for (; isdigit(buf[bufpos]); bufpos++) val = val * 10 + b...
6
#include <bits/stdc++.h> using namespace std; const int maxn = 3e5 + 10; long long sum; int n, k, cnt = 1, w[maxn], ans[maxn]; priority_queue<pair<int, int> > q; int main() { scanf("%d %d", &n, &k); for (int i = 1; i <= n; i++) { scanf("%d", w + i); } for (int i = k + 1; i <= k + n; i++) { for (; cnt <=...
3
#include <bits/stdc++.h> using namespace std; int N, M, A, B; int Fact[1000005], Inv[1000005]; const int MOD = 1000000007; int power(int n, int p) { int sol = 1; while (p) { if (p & 1) sol = (1LL * sol * n) % MOD; p /= 2; n = (1LL * n * n) % MOD; } return sol; } void precalcFact() { Fact[0] = 1; ...
4
#include <bits/stdc++.h> using namespace std; int main() { int x,n,p,i,f,c,d,a=0; map<int,int> mp; cin>>x>>n; for(i=0;i<n;i++) { cin>>p; mp[p]++; } c=1; d=1; f=x; while(1) { if(!mp[f]) {cout<<f; break;} a++; if(a%2!=0) {f=x-c; c++;} else {f=x+d; d++;} } ret...
0
#include <bits/stdc++.h> using namespace std; long long sum[600006]; int main() { long long a, b, c, l, ans = 0; cin >> a >> b >> c >> l; for (long long i = 0; i <= l; i++) { ans += ((i + 1) * (i + 2)) / 2; } sum[0] = 1; for (long long i = 1; i <= l; i++) { sum[i] = sum[i - 1] + i + 1; } long lo...
3
#include <iostream> #include <queue> #include <vector> #include <algorithm> #include <set> #include <cmath> #include <tuple> #include <cstring> #include <map> #include <iomanip> #include <ctime> #include <complex> #include <cassert> #include <climits> using namespace std; typedef long long ll; typedef unsigned long lon...
0
#include <bits/stdc++.h> const int MN = 1e5 + 44; const int NONE = -1; int per[MN]; int u[MN]; int find(int x) { if (u[x] == x) return x; else return u[x] = find(u[x]); } void unite(int a, int b) { u[find(a)] = find(b); } int main() { int n; scanf("%d", &n); if (n % 2 == 1) { int in = 0; for (...
5
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); srand(chrono::high_resolution_clock::now().time_since_epoch().count()); int n; cin >> n; string s; vector<int> a(n); vector<int> b(n); cin >> s; for (int i = 0; i < n; i++) { int x = s...
2
#include <iostream> #include <cmath> using namespace std; int main() { int n; while (cin >> n) { for (int i = 0; i < n; ++i) { double xa, ya, ra, xb, yb, rb; cin >> xa >> ya >> ra >> xb >> yb >> rb; double d = sqrt((xa-xb)*(xa-xb) + (ya-yb)*(ya-yb)); if (d > ra+rb) cout <...
0
#include <bits/stdc++.h> using namespace std; const int maxn = 220; int a[maxn]; int sum; int num; int ma = -11111; int main() { ios::sync_with_stdio(false); int n; cin >> n; for (int i = 0; i < n * 2 - 1; ++i) cin >> a[i]; for (int i = 0; i < n * 2 - 1; ++i) { sum += abs(a[i]); if (a[i] <= 0) { ...
1
#include <bits/stdc++.h> using namespace std; int a[200001]; int main() { int N, M, i; scanf("%d%d", &N, &M); int sum1 = 0, sum2 = 0; for (i = 1; i <= N; i++) { scanf("%d", &a[i]); if (a[i] == 1) sum1++; else sum2++; } while (M--) { int l, r; scanf("%d%d", &l, &r); int co...
1
#include <bits/stdc++.h> using namespace std; int main() { long long int digits, answer = 0; cin >> digits; for (int i = 1; i <= digits; i++) { if ((i % 2) == 0) { answer += (pow(2, i / 2) * pow(2, i / 2)); } else { answer += (pow(2, i / 2) * pow(2, 1 + (i / 2))); } } cout << answer; ...
3
#include <bits/stdc++.h> using namespace std; pair<int, int> getVal(string a) { string s = "23456789TJQKA"; string t = "SDHC"; return {s.find(a[0]), t.find(a[1])}; } bool can(pair<int, int> a, pair<int, int> b) { return a.first == b.first || a.second == b.second; } int main() { ios_base::sync_with_stdio(false...
2
#include <bits/stdc++.h> using namespace std; int a, b, c, d, n, k; int main() { cin >> n >> k >> a >> b >> c >> d; if (k < n + 1 || n <= 4) cout << -1; else { cout << a << ' ' << c << ' '; for (int i = 1; i <= n; i++) if (i != a && i != b && i != c && i != d) cout << i << ' '; cout << d << ...
4
#include <bits/stdc++.h> using namespace std; int n, k; int c[1005]; int dp[1005][1005]; int ans = 0; int main() { cin >> n >> k; for (int i = 1; i <= n; i++) cin >> c[i]; dp[0][0] = 1; for (int i = 1; i <= n; i++) for (int j = k; j >= c[i]; j--) for (int l = 0; l <= k - c[i]; l++) if (dp[j - ...
3
#include <bits/stdc++.h> using namespace std; inline int rin(int &r) { int b = 1, c = getchar(); r = 0; while (c < '0' || '9' < c) b = c == '-' ? -1 : b, c = getchar(); while ('0' <= c && c <= '9') r = (r * 10) + (c ^ '0'), c = getchar(); return r *= b; } const int N = 5e5 + 10; int ncas, n, lseg, rseg; int n...
5
#include <bits/stdc++.h> using namespace std; const int maxn = 3e5 + 10, mod = 1e9 + 7, INF = 0x3f3f3f3f; char s[maxn]; int main() { int n; cin >> n; scanf("%s", s + 1); int res = 1; for (int i = 2; i <= n; ++i) res += s[i] != s[i - 1]; int ans = res; int cnt2 = 0, cnt3 = 0; for (int i = 1, j = 1; i <= ...
1
#include <bits/stdc++.h> using namespace std; int main() { char n[4]; cin >> n; cout << (n[1] == n[2] && (n[0] == n[1] || n[2] == n[3]) ? "Yes" : "No"); }
0
#include <bits/stdc++.h> using namespace std; int N, M; vector<int> adj[5001]; vector<int> adj2[5001]; int idx[5001]; int low[5001]; int now; vector<int> S; bool onS[5001]; int comp[5001]; int ncomp; bool good[5001]; vector<int> elem[5001]; int dist[5001]; int Q[5001], head, tail; void dfs(int u) { idx[u] = ++now; ...
5
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 5; struct key_tree { int size; char key[MAXN]; int num[MAXN]; int head[MAXN]; int next[MAXN]; int ans1, ans2; key_tree() { clear(); }; void clear() { size = 0; key[0] = '#'; memset(head, -1, sizeof(head)); memset(num, 0...
3