solution
stringlengths
52
181k
difficulty
int64
0
6
#include <bits/stdc++.h> using namespace std; const double PI = 3.14159265358979; const long long INF = 1e15 + 7; const long long MOD = 998244353; const long long nax = 200005; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int tc = 1; cin >> tc; while (tc--) { long long n, ans = 0; cin...
3
#include <bits/stdc++.h> using namespace std; int mod; long long powmod(long long a, long long b) { long long res = 1; a %= mod; for (; b; b >>= 1) { if (b & 1) res = res * a % mod; a = a * a % mod; } return res; } long long gcd(long long x, long long y) { while (y) { long long t = x % y; x ...
6
#include <bits/stdc++.h> using namespace std; bool cmp(pair<pair<long long int, long long int>, long long int> a, pair<pair<long long int, long long int>, long long int> b) { return a.second < b.second; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long int k, j = 1; cin >> k; ...
3
#include<bits/stdc++.h> using namespace std; string s,t,s1; int main(){ cin>>s>>t; s1+=s; s1+=s; if(s1.find(t)==s1.npos){ cout<<"No"; return 0; } cout<<"Yes"<<endl; }
0
#include <iostream> #include <algorithm> #include<cmath> #include<cstring> #include<cstdio> #include<cstdlib> #include<vector> #include<iomanip> #define sqr(x) (x)*(x) using namespace std; int n,m,i,j,mx,smi=1e9,num[100005],ans; int main() { cin>>n>>m; for (i=1;i<=n;i++) cin>>num[i]; for (i=1;i<=n;i++) { if (num[...
0
#include <bits/stdc++.h> #pragma GCC optimize("O3") using namespace std; using ll = long long; using vi = vector<int>; using pii = pair<int, int>; using ld = long double; const int N = 1 << 21; int h, g, n, m; int a[N]; int wh[N]; vi guys; vi ans; vi path; bool can(int v) { path.push_back(v); if (a[v << 1] == 0 && ...
3
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t; cin >> t; while (t--) { string s; cin >> s; vector<int> rpos; rpos.emplace_back(0); for (int i = 0; i < s.length(); i++) { if (s[i] == 'R') { rpos.emplace_back(i...
3
#include <bits/stdc++.h> using namespace std; const int maxN = 100022; struct edge { edge(int a, int b, int i) { this->a = a; this->b = b; this->i = i; } int a, b, i; }; vector<edge> E[10 * maxN]; int Baba[maxN], R[maxN]; pair<int, vector<edge>> C[maxN]; int getBaba(int v) { return Baba[v] < 0 ? v : B...
4
#include <iostream> #include <functional> #include <algorithm> using namespace std; int main(){ int n,i,p[100],t,j,a; while(cin >> n && n){ for(i=0;i<n;i++){ t = 0; for(j=0;j<5;j++){ cin >> a; t += a; } p[i] = t; } sort(p,p+n,greater<int>()); cout << p[0] << " " << p[n-1] << endl; for(i...
0
#include <bits/stdc++.h> using namespace std; int a[2 * 100000 + 100]; int p[2 * 100000 + 100]; int n, m; int li, ri, xi; int main() { while (scanf("%d%d", &n, &m) != EOF) { for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); if (a[i] == a[i - 1]) p[i] = p[i - 1]; else p[i] = i - ...
3
#include <bits/stdc++.h> using namespace std; int n, m, a[100010], pos[100010], f[100010], b; int main() { bool yes = true; cin >> n >> m; for (int i = 1; i < n + 1; i++) { cin >> f[i]; if (pos[f[i]]) { pos[f[i]] = -1; } else { pos[f[i]] = i; } } for (int i = 0; i < m; i++) { c...
2
#include<bits/stdc++.h> using namespace std; typedef long long ll; #define pb push_back #define fi first #define se second typedef pair<ll,ll> P; using VP = vector<P>; using VVP = vector<VP>; using VI = vector<int>; using VVI = vector<VI>; using VVVI = vector<VVI>; const int inf=1e9+7; const ll INF=1LL<<60; const ll mo...
0
#include <bits/stdc++.h> using namespace std; using ll = long long; using vi = vector<int>; using ii = pair<int, int>; template <class A, class B> ostream& operator<<(ostream& os, pair<A, B> p) { return os << p.first << " " << p.second; } template <class A, class B> istream& operator>>(istream& is, pair<A, B>& p) { ...
4
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; vector<int> k(n); for (int i = 0; i < n; i++) cin >> k[i]; int ans = 0; sort(k.begin(), k.end()); for (int i = 1; i < n; i++) { ans += ((k[i] - k[i - 1]) - 1); } cout <<...
1
#include <bits/stdc++.h> using namespace std; const int MAXN = 500005; vector<int> v[MAXN]; int st[MAXN], et[MAXN], lazy[4 * MAXN]; int c[MAXN], order[MAXN]; long long seg[4 * MAXN]; int n, m, cnt = 0; void DFS(int i, int p) { order[cnt] = i; st[i] = cnt++; for (int j = 0; j < v[i].size(); j++) { if (v[i][j] ...
5
#include <bits/stdc++.h> using namespace std; struct scientist { long long k, a, x, y, m, current_index; bool change; }; struct h { long long value; int index; }; int N; vector<scientist> scientists; long long k, a, x, y, m; long long answer = 0; vector<h> heap1; vector<h> heap2; h prev_result; vector<h> result...
1
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 100; int n, m, k; struct Edge { int u, v; Edge(int _u = 0, int _v = 0) : u(_u), v(_v) {} } road[maxn]; bool vis[maxn]; int dis[maxn]; int f[maxn]; vector<int> edge[maxn]; vector<int> p[maxn]; vector<string> path; void bfs() { queue<int> Q; Q.p...
6
#include <bits/stdc++.h> using namespace std; vector<long long int> fact(501), in(501); long long int v1[110][110], v2[110][110]; long long int powy(long long int a, long long int b) { if (b == 0) return 1; long long int c = powy(a, b / 2); if (b & 1) return (c * ((c * a) % 998244353) % 998244353); else ...
3
#include<bits/stdc++.h> using namespace std; const int MOD = 1e9+7; int r1, r2, c1, c2; long long ksm(long long x,long long y) { x %= MOD; long long rt = 1LL; while ( y ) { if ( y & 1 ) rt = rt * x % MOD; x = x * x % MOD; y >>= 1; } return rt; } int C(int n,int m) { if ( n < m ) return 0; long lo...
0
#include<iostream> using namespace std; struct point{ double x; double y; bool operator != ( point& p ) { return ( x != p.x || y != p.y ); } bool operator == ( point& p ) { return ( x == p.x && y == p.y ); } }; point getLeftPoint( int n , point *points ); double getCrossProduct( const point& a , const p...
0
#include<cstring> #include<cstdlib> #include<cstdio> #include<cmath> #include<iostream> #define N 110000 #define LL long long using namespace std; struct node{int y,nex,o;}a[2*N]; int n,m,len,fir[N],c[N]; LL ans,d[5],cnt,tmp; bool v[N],bo; void ins(int x,int y) { a[++len].y=y;a[len].o=1;a[len].nex=fir[x];fir[x]=len; ...
0
#include <bits/stdc++.h> using namespace std; int main() { long long int t, n, i, j, x, y, z, c, d; cin >> t; for (i = 1; i <= t; i++) { cin >> n; x = 10e10; y = 10e10; z = 0; int a[n], b[n]; for (j = 0; j < n; j++) { cin >> a[j]; if (a[j] < x) x = a[j]; } for (j = 0; j...
2
#include <bits/stdc++.h> int getsum(int a) { int d = 0; while (a) { d = d + a % 10; a /= 10; } return d; } int main() { int a; scanf("%d", &a); while (getsum(a) % 4 != 0) a++; printf("%d", a); }
1
#include <bits/stdc++.h> using namespace std; long long c0, c1, n; long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } long long lls[31]; long long comb(long long a, long long b) { long long s = 1, x, g; for (long long i = 0; ++i <= b; lls[i] = i) ; for (long long i = -1; ++i < b;) { ...
2
#include <bits/stdc++.h> using namespace std; template <typename T> T gcd(T a, T b) { if (!b) return a; return gcd(b, a % b); } template <typename T> T lcm(T a, T b) { return a * b / gcd(a, b); } long long modpow(long long a, long long b, long long mod) { long long x = 1, y = a; while (b > 0) { if (b % 2 ...
1
#include <bits/stdc++.h> using namespace std; long long n, m, ans, x, i, j, s; double a[100], b[100]; map<double, pair<long long, long long> > mp; map<double, pair<long long, long long> >::iterator it, it2; long long num(long long x) { s = 0; while (x) { s++; x -= x & -x; } return s; } int main() { ci...
5
#include <bits/stdc++.h> using namespace std; #define MAX 210 #define INF 1e9 const int diff = 105; struct State{ int n,x,y,t; bool operator < (const State &s)const{ return n > s.n; } }; int sx,sy,gx,gy,lx,ly; bool can[MAX][MAX]; int dist[MAX][MAX][6]; const int dx[7] = {0,1,1,0,-1,-1,0}; const int...
0
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 5; const int ff = 0x3f3f3f3f; struct node { int x; int y; int p; int step; node(int x = 0, int y = 0, int p = 0, int step = 0) { this->x = x; this->y = y; this->p = p; this->step = step; }; }; char mp[52][10][10]; int ed[52...
1
#include <bits/stdc++.h> using namespace std; template <typename T> T sqr(T x) { return x * x; } template <typename T> T abs(T x) { return x < 0 ? -x : x; } template <typename T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; } template <typename T> bool chmin(T& x, const T& y) { if (x > y) { x = y; re...
2
#include<iostream> #include<cstdio> #include<string> #include<cmath> #include<algorithm> using namespace std; int n,t; double arr[10005],m,r,sum; int main() { while(scanf("%d",&n)!=EOF&&n!=0) { sum=0,m=0; for(int i =0;i<n;i++) { cin>>t,m+=t,arr[i]=t; } m=m/n; for(int i =0;i<n;i++) { sum+=pow(arr[...
0
#include <bits/stdc++.h> using namespace std; int nearestPowerOfTwo(int n) { int ans = 1; while (ans < n) ans <<= 1; return ans; } int inverse(int a, int n) { int r0 = a, r1 = n, ri, s0 = 1, s1 = 0, si; while (r1) { si = s0 - s1 * (r0 / r1), s0 = s1, s1 = si; ri = r0 % r1, r0 = r1, r1 = ri; } if (...
5
#include <bits/stdc++.h> using namespace std; const int N = 200010; const int inf = 2147483647; long long read() { long long x = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') x = x * 10ll + ch - '0', ch = getchar()...
4
#include <bits/stdc++.h> using namespace std; long long n, k, nk, a, b, x = 1e18, y = 0; set<long long> first, second; long long calc(long long x) { int res = (x + n * k) % (n * k); return res ? res : nk; } long long gcd(long long a, long long b) { if (!b) return a; return gcd(b, a % b); } long long get_step(lo...
4
#include <bits/stdc++.h> using namespace std; const int maxn = 200011; vector<int> e[maxn]; int n, a[maxn], b[maxn], w[maxn], s[maxn]; void init() { scanf("%d", &n); for (int i = 1, c, d; i < n; ++i) { scanf("%d%d%d%d", a + i, b + i, &c, &d); e[a[i]].push_back(b[i]); w[b[i]] = c; s[b[i]] = d; } } ...
5
#include <bits/stdc++.h> using namespace std; vector<long long> dpF[100000 + 1]; vector<long long> dpB[100000 + 1]; long long maxS[100000 + 1]; long long res(long long x) { if (x < 10) return x; long long last = x % 10; long long k = 9 + (x - 10) / 10; while (x > 9) x /= 10; if (last >= x) k++; return k; } ...
4
#include <bits/stdc++.h> using namespace std; void solve() { int n; cin >> n; priority_queue<pair<int, int> > pq; for (int i = 0; i < n; ++i) { int cnt; cin >> cnt; if (cnt != 0) pq.push({cnt, i}); } vector<pair<int, int> > ans; while (pq.size() >= 2) { pair<int, int> a = pq.top(); pq....
4
#include <bits/stdc++.h> #define ADD(a, b) a = (a + ll(b)) % mod #define MUL(a, b) a = (a * ll(b)) % mod #define MAX(a, b) a = max(a, b) #define MIN(a, b) a = min(a, b) #define rep(i, a, b) for(int i = (a); i < (b); i++) #define rer(i, a, b) for(int i = (a) - 1; i >= (b); i--) #define all(a) (a).begin(), (a).end() #def...
0
#pragma GCC optimize("-Ofast","-funroll-all-loops") #include<bits/stdc++.h> #define int long long #define lowbit(x) (x &(-x)) #define endl '\n' using namespace std; const int INF=0x3f3f3f3f; const int dir[4][2]={-1,0,1,0,0,-1,0,1}; const double PI=acos(-1.0); const double e=exp(1.0); const double eps=1e-10; const int M...
5
#include <bits/stdc++.h> using namespace std; const int M = 1e9 + 7; void add(int &a, int b) { a += b; if (a >= M) a -= M; } int mypow(int x, int t) { int ans = 1, res = x; while (t) { if (t & 1) ans = (long long)ans * res % M; res = (long long)res * res % M, t >>= 1; } return ans; } int n; int fac[...
5
#include "bits/stdc++.h" #include<unordered_map> #include<unordered_set> #pragma warning(disable:4996) using namespace std; using ld = long double; template<class T> using Table = vector<vector<T>>; const ld eps=1e-9; //// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt" > "D:\D_Downloa...
0
#include<iostream> #include<algorithm> #include<vector> #include<math.h> typedef long long int ll; using namespace std; ll S(ll n){ ll cnt=0; while(n>0){ cnt+=n%10; n/=10; } return cnt; } int main(){ ll k; cin >>k; ll cnt=0; ll digit=1; for(ll i=0;i<k;i++){ cnt+=digit; cout << cnt << endl; if((double...
0
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; if(n > m) swap(n, m); if(m == 1) cout << "1" << endl; else if(n == 1) cout << m - 2 << endl; else cout << 1ll * n * m - n * 2 - m * 2 + 4 << endl; return 0; }
0
#include<bits/stdc++.h> using namespace std; int main(){ long long N,u,c; cin>>N; for(long long h=1;h<=3500;h++){ for(long long n=1;n<=3500;n++){ u=h*n*N; c=h*(4*n-N)-n*N; if(c!=0){ if(u%c==0&&u/c>0){ cout<<h<<" "<<n<<" "<<u/c<<endl; return 0; } } } } }
0
#include <iostream> #include <string> #include <cassert> #include <cstdio> #include <cctype> namespace { bool can_assign_zero(const std::string& str) { return (str.size() <= 1) || (str[0] != 'X'); } int assign_digit(const std::string& str, int x) { int value = 0; for (size_t i = 0; i < str.size(); ++i) { ...
0
#include <bits/stdc++.h> using namespace std; long long ans[19999]; int main() { map<long long, long long> pos; vector<long long> kos; int n, k; cin >> n >> k; for (int i = 1; i <= n; i++) { cin >> ans[i]; if (!pos[ans[i]]) { pos[ans[i]]++; if (kos.size() == k) continue; kos.push_bac...
1
#include <bits/stdc++.h> using namespace std; int a[100010]; int main() { int t; scanf("%d", &t); while (t--) { int n; scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d", a + i); sort(a + 1, a + 1 + n); int ans = 0; for (int i = 1; i <= n; i++) { int s = lower_bound(a + 1, a + ...
1
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { string s; int n, m, z, i, j, k, l, r, x, y, bugi = 0, chigi = 0, moga = 0; cin >> n; s = string(100, 'a'); for (i = 0; i < n; i++) { cin >> x; if (i == 0) cout << s << endl; if (s[x] < '...
1
// coded by whx1003 #include<cmath> #include<cstdio> #include<vector> #include<algorithm> typedef long long ll; typedef std::vector<ll> vec; const ll mod = 998244353, gen = 3; const ll inv2 = (mod + 1) / 2; const int maxn = 1E+5 + 5; namespace IObuf { const int LEN = 1 << 20; char ibuf[LEN + 5], *p1 = ibuf, *p2 =...
6
#include <bits/stdc++.h> using namespace std; struct custom_hash { static uint64_t splitmix64(uint64_t x) { x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31); } size_t operator()(uint64_t x) const { static const ui...
4
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n, k; cin >> n >> k; vector<long long> v(n); vector<int> p(n + 1); for (auto& a : v) { cin >> a; } p[0] = 0; for (int i = 1; i < n + 1; ++i) { p[i] += p[i - 1]; if (i >= ...
2
#include <bits/stdc++.h> using namespace std; int main() { string cad; cin >> cad; string n_string = ""; for (int i = 0; i < (int)cad.size(); ++i) { if (cad[i] != 'a') { n_string += cad[i]; } } if (n_string.size() % 2 == 0) { string a, b; for (int i = 0; i < (int)n_string.size() / 2; +...
2
#include <bits/stdc++.h> using namespace std; char cken[65]; int r, c, k; char mp[105][105]; char ans[105][105]; int main() { for (int i = 0; i < 62; i++) { if (0 <= i && i < 26) cken[i] = 'a' + i; else if (26 <= i && i < 52) cken[i] = 'A' + i - 26; else if (52 <= i) cken[i] = '0' + i - ...
4
#include <iostream> int main() { int D, L; std::cin >> D >> L; std::cout << D / L + std::max(0, D - D / L * L) << std::endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; int if_men(vector<int> &v1, vector<int> &v2) { for (int i = v1.size() - 1; i >= 0; --i) { if (v1[i] < v2[i]) { return 1; } if (v1[i] > v2[i]) { return 0; } } return 0; } int main() { long long n; string k; cin >> n >> k; vector<int>...
4
#include <bits/stdc++.h> int a[100]; int main() { int n; std::cin >> n; for (int i = 0; i < n; ++i) { std::cin >> a[i]; } std::sort(a, a + n); for (int i = 0; i < n; ++i) { std::cout << a[i] << ' '; } return 0; }
1
#include <bits/stdc++.h> using namespace std; int T; int n, x; struct Node { int a, b; } t[110]; bool flag; int de, ma; int main() { cin >> T; while (T--) { cin >> n >> x; flag = de = ma = 0; for (int i = 1; i <= n; i++) { cin >> t[i].a >> t[i].b; if (t[i].a > t[i].b) flag = true; de...
2
#include<bits/stdc++.h> using namespace std; typedef pair<int,int>P; string dp[51][51],s; string MAX(string &a,string &b){ if(a=="invalid")return b; if(b=="invalid")return a; if(a.size()>b.size())return a; else if(a.size()<b.size())return b; else return a<b?b:a; } string get_num(int l,int r){ st...
0
#include<bits/stdc++.h> using namespace std; int main(){ int n,total=0; cin>>n; while(n){ total += n%10; n = n/10; } if(total==1) cout<<10<<endl; else cout<<total<<endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; long long dp[100000 + 25]; struct node { int iz, der; long long tiempo; node() {} node(long long t, int i, int d) { tiempo = t; iz = i; der = d; } }; struct otro { int proct, pos; long long tiemp; otro() {} otro(int ps, long long time, int timp...
2
#include <bits/stdc++.h> #pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #pragma comment(linker, "/STACK:16777216") using namespace std; using matrix = vector<vector<long long>>; void FAST_IO() { ios_base::sync_with_...
4
#include <bits/stdc++.h> using namespace std; struct debugger { template <typename T> debugger& operator,(const T& v) { cerr << v << " "; return *this; } } dbg; long long mod = 1000000007; long long mod_v(long long nn) { return nn % mod; } template <class T> T fast_pow(T n, T p) { if (p == 0) return 1; ...
3
#include <bits/stdc++.h> using namespace std; int n; long long modv = 1e9 + 7; long long p; char str[10]; set<long long> s; long long lo = -1e9, hi = 1e9; long long ans = 1; int main() { scanf("%lld", &n); s.insert(lo); s.insert(hi); for (long long i = 1; i <= n; i++) { scanf("%s %lld", str, &p); if (st...
4
#include <bits/stdc++.h> using namespace std; string mat[600]; vector<pair<pair<int, int>, int> > operations; int visited[600][600]; int dx[] = {-1, 0, 1, 0}; int dy[] = {0, -1, 0, 1}; int n, m; void dfs(pair<int, int> u, int root = 1) { if (visited[u.first][u.second]) return; visited[u.first][u.second] = 1; oper...
4
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n, a, b; cin >> n >> a >> b; int ans = 6; if (4 * a + 2 * b <= n) { ans = min(ans, 1); } if (2 * a + b <= n) { ans = min(ans, 2); } if (3 * a <= n) { if (4 * ...
2
#include <iostream> #include <string> #include <algorithm> #include <functional> #include <vector> #include <utility> #include <cstring> #include <iomanip> #include <numeric> #include <cmath> #include <queue> #include <list> using namespace std; typedef long long ll; const int INF = 1<<30; const int MOD = 1e9 + 7; con...
0
#include <bits/stdc++.h> using namespace std; const double eps = 1e-8; const double inf = 1e20; long long a, b, c; pair<double, double> S, T; double dis1(pair<double, double> a, pair<double, double> b) { return abs(a.first - b.first) + abs(a.second - b.second); } double dis2(pair<double, double> a, pair<double, doubl...
1
#include <bits/stdc++.h> using namespace std; const int N = 100010; long long val[100010], cha[N]; int f[N][21][2], sz[N]; vector<int> mp[N]; int n; inline int read() { int x = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch...
5
#include <bits/stdc++.h> using namespace std; int n, m, i, j, k, ans, total, temp; char mat[5011][5011]; int dp[5011][5011], cnt[5011]; int main() { scanf("%d%d", &n, &m); for (i = 1; i <= n; i++) scanf("%s", &mat[i][1]); memset(dp, 0, sizeof(dp)); for (i = 1; i <= n; i++) { for (j = m; j >= 1; j--) { ...
2
#include <bits/stdc++.h> using namespace std; const int tope = 1 << 20; const int primero = 1 << 19; complex<double> d[tope]; complex<double> r[tope]; int n, m; void propaga(int pos) { while (pos > 1) { pos /= 2; d[pos] = d[2 * pos] + r[2 * pos] * d[2 * pos + 1]; r[pos] = r[2 * pos] * r[2 * pos + 1]; } ...
5
#include <bits/stdc++.h> using namespace std; const int N = 100000; int n, m, k; int alice[N], bob[N]; int main() { while (scanf("%d%d%d", &n, &m, &k) != EOF) { for (int i = 0; i < n; i++) { scanf("%d", &alice[i]); } for (int i = 0; i < m; i++) { scanf("%d", &bob[i]); } sort(alice, ali...
4
#include <bits/stdc++.h> using namespace std; int a[200000 + 5], ma[200000 + 5]; void work() { int n, m, p, s, maxa = 0, maxp = 0; scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%d", a + i), ma[i] = 0, maxa = max(maxa, a[i]); ma[n] = 0; scanf("%d", &m); for (int i = 0; i < m; i++) scanf("%d%d",...
4
#include <bits/stdc++.h> using namespace std; const int Inf = 0x3f3f3f3f; const int NMAX = 100005; double e[NMAX], es[NMAX], p[NMAX]; int main() { long long n; cin >> n; for (int i = 1; i <= n; ++i) cin >> p[i]; for (int i = 1; i <= n; ++i) { e[i] = e[i - 1] + 2 * es[i - 1] * p[i] + p[i]; es[i] = (es[i ...
2
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; const long long infll = 0x3f3f3f3f3f3f3f3fLL; inline long long read() { long long x = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { x ...
3
#include <bits/stdc++.h> const int N = 3e5 + 1; char s[N], c[N]; std::set<int> f[N]; int i, k, l, r, q, n, b[N], h[N], L[N], P = 1e9 + 7; int main() { for (b[0] = i = 1; i < 300001; ++i) b[i] = 27ll * b[i - 1] % P; for (scanf("%d", &q); q--;) { scanf("%d%s", &k, s + 1); for (l = 1; s[l]; ++l) h[l] = (27ll *...
6
#include <bits/stdc++.h> using namespace std; double an, n, m; int main() { cin >> m >> n; an = m; for (int(i) = 1; i <= (m - 1); i++) an -= pow(i / m, n); printf("%.10lf", (an)); }
3
#include <bits/stdc++.h> const long long inf = 1ll << 60; inline int read() { int X = 0, w = 1; char ch = 0; while (ch < '0' || ch > '9') { if (ch == '-') w = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') X = (X << 3) + (X << 1) + ch - '0', ch = getchar(); return X * w; } using namespace ...
4
#include <iostream> using namespace std; int main() { int a, b, i, m; char c; while (1) { m = 0; for (i = 0; i < 5; i++) { cin >> a >> b; if (a == 0 && b == 0) return 0; if (a+b > m) { m = a+b; c = 'A' + i; } } cout << c << " " << m << endl; } }
0
#include <bits/stdc++.h> using namespace std; int main() { long long a[5], sum = 0; for (int i = 0; i < 5; i++) { cin >> a[i]; sum += a[i]; } if (sum == 0) { cout << -1; } else if (sum % 5 == 0) { cout << sum / 5; } else { cout << -1; } }
1
#include <bits/stdc++.h> using namespace std; long long ap(long long longest, long long d) { long long an = longest; if (an <= 0) return 0; long long a1 = 1 + (d == 2 && an % 2 == 0); long long n = (an - a1) / d + 1; return (a1 + an) * n / 2; } long long ways(int a, int b, int c, int l) { long long A = a - ...
1
#include <bits/stdc++.h> using namespace std; #define int long long const int MOD = 1000000007; signed main() { cin.tie(0); ios::sync_with_stdio(false); int N; cin >> N; vector<int> A(N); vector<int> B(N); int INF = (int)1 << 60; int res = INF; for (int i = 0; i < N; i++) { cin >> A[i]; } for (int i = 0;...
0
#include<bits/stdc++.h> typedef long long int ll; typedef unsigned long long int ull; #define BIG_NUM 2000000000 #define HUGE_NUM 99999999999999999 #define MOD 1000000007 #define EPS 0.000000001 using namespace std; #define NUM 1005 char buf[NUM]; int main(){ scanf("%s",buf); int num = 0,ans = 0; for(int i =...
0
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; int n, a[N]; long long sum[N]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n; int ans = 0; for (int i = 0; i < n; i++) { cin >> a[i]; if (i) sum[i] = sum[i - 1] + a[i]; } for (int i = 0; i < n - 2; i++) { in...
5
#include <bits/stdc++.h> using namespace std; const int LIMIT = 5e5 + 7; const int INF = 1e9 + 7; long long n, dp[LIMIT]; string s; int main() { cin >> s; n = s.size(); for (int i = 1; i < n; i++) { if (s[i] > s[dp[i - 1]]) { dp[i] = dp[i - 1]; } else { dp[i] = i; } } for (int i = 0; i...
3
#include <bits/stdc++.h> #define REP(i, s, e) for(int i = (int)(s); i < (int)(e); ++i) #define rep(i, n) REP(i, 0, n) using namespace std; using ll = long long int; int main() { int n, m; while(cin >> n >> m) { if(n == 0 && m == 0) break; vector<ll> x(n), y(m); rep(i, n) cin >> x[i]; rep(i, m) cin >...
0
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, k, x = 0, ans = 0; cin >> n; vector<int> v; for (int i = 0; i < n; ++i) { cin >> k; v.push_back(k); } vector<int> w; sort(v.begin(), v.end()); while ((int)(w).size() < n / 2) { w.p...
1
#include <bits/stdc++.h> using namespace std; const int MOD = 998244353; long long POW(long long a, long long b, long long MMM = MOD) { long long ret = 1; for (; b; b >>= 1, a = (a * a) % MMM) if (b & 1) ret = (ret * a) % MMM; return ret; } long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : ...
3
#include <bits/stdc++.h> using namespace std; long long modpow(long long base, long long exponent, long long modulus) { if (base == 0 && exponent == 0) return 0; long long result = 1; while (exponent > 0) { if (exponent % 2 == 1) result = (result * base) % modulus; exponent = exponent >> 1; base = (ba...
4
#include <bits/stdc++.h> using namespace std; using ll = long long; using Line = pair<int, ll>; const int N = 2e5 + 5; const ll INF = 0x3f3f3f3f3f3f3f3fLL; int n, a[N], second[N], rt[N], tot; ll f[N]; struct Tree { int l, r; Line s; } t[N * 25]; basic_string<int> G[N]; ll Y(Line l, int x) { return 1LL * l.first * x...
6
#include <bits/stdc++.h> using namespace std; const int maxn = 100 + 5; inline int read() { char ch = getchar(); int r = 0, s = 1; while (ch > 57 || ch < 48) s = ch == 45 ? 0 : s, ch = getchar(); while (ch >= 48 && ch <= 57) r = (r << 1) + (r << 3) + (ch ^ 48), ch = getchar(); return s ? r : -r; } int n; ...
3
#include <bits/stdc++.h> using namespace std; const int MAXN = 5 * 100010; set<long long int> s; set<long long int>::iterator itlow, itup; long long int data[4 * MAXN], ind[4 * MAXN], a[MAXN]; const long long int INF = 10000000000000; void build(int s = 0, int e = 5e5 + 1, int id = 1) { if (e - s < 2) { data[id] ...
5
#include <bits/stdc++.h> using namespace std; void IOS() { ios::sync_with_stdio(false); cout.precision(10); cout << fixed; } const long long MOD = 1e9 + 7; const long long mx = 1e5 + 2; long long i, j, k; struct dsu { long long n; vector<long long> sizes, marks, cols; vector<vector<pair<long long, long long...
4
#include <bits/stdc++.h> #define pb push_back #define mp make_pair #define f first #define s second #define MOD 1000000007 #define fo(i, a, n) for(int i=a; i<n; ++i) #define len(x) x.size() #define min3(a, b, c) min(a, min(b, c)) #define max3(a, b, c) max(a, max(b, c)) #define all(v) v.begin(), v.end() #define alla(...
3
#include <bits/stdc++.h> using namespace std; int n; string A; vector<string> W; int p; void czyt() { cin >> n; cin >> A; } char znak(int d) { string z = "0123456789"; return (z[d]); } void suma(int sr) { int p1, p2, d; bool carry = false; string s = ""; p1 = sr - 1; p2 = n - 1; while (p1 >= 0 && p2...
2
#include <bits/stdc++.h> using namespace std; int main() { long int n, m, i, j; char a[1000][1000]; cin >> n >> m; for (i = 1; i <= n; i++) { for (j = 1; j <= m; j++) { cin >> a[i][j]; } } for (i = 1; i <= n; i++) { for (j = 1; j <= m; j++) { if (a[i][j] == 'C' || a[i][j] == 'M' || a...
1
#include <bits/stdc++.h> using namespace std; template <typename T> void pr(vector<T> &v) { for (int i = 0; i < (int)(v).size(); i++) cout << v[i] << " "; cout << '\n'; ; } template <typename T> void pr(vector<vector<T>> &v) { for (int i = 0; i < (int)(v).size(); i++) { pr(v[i]); } } template <typename T>...
5
#include <bits/stdc++.h> using namespace std; int flag; vector<int> v[500005]; vector<int> w; int vis[500005] = {0}; void dfs(int node) { vis[node] = 1; for (int i = 0; i < v[node].size(); i++) { if (vis[v[node][i]] != 1) { if (w[v[node][i]] == w[node]) { flag = 1; } dfs(v[node][i]); ...
4
#include <bits/stdc++.h> using namespace std; mt19937 rng(static_cast<unsigned int>( chrono::steady_clock::now().time_since_epoch().count())); template <typename num_t> inline void add_mod(num_t& a, const long long& b, const num_t& m) { a = (a + b) % m; if (a < 0) a += m; } template <typename num_t> inline bool...
2
#include <bits/stdc++.h> using namespace std; long long int inf = 1000005; long long int a[1000005], sz[1000005]; int main() { long long int n, p, l, r; cin >> n >> p; double ans = 0.0; for (long long int i = 0; i < n; i++) { cin >> l >> r; sz[i] = (r - l) + 1; a[i] = r / p - (l - 1) / p; } a[n]...
3
#include <bits/stdc++.h> using namespace std; void fun(long long int n) { int count = 0; while (n) { if (n % 10 == 7 || n % 10 == 4) count++; n = n / 10; } if (count == 0) { cout << "NO"; return; } while (count) { int r = count % 10; if (r != 7 && r != 4) { cout << "NO"; ...
1
#include <bits/stdc++.h> using namespace std; const int sz = 1000005; int fen[sz]; map<int, int> cnt, cnt2; void add(int idx, int val) { for (int i = idx; i <= sz; i += (i & -i)) { fen[i] += val; } } int query(int idx) { int ans = 0; for (int i = idx; i > 0; i -= (i & -i)) ans += fen[i]; return ans; } int...
4