solution
stringlengths
52
181k
difficulty
int64
0
6
#include <bits/stdc++.h> using namespace std; const int MAXN = 2e5; vector<pair<int, int>> all; set<int> ugly; int getidx(int tp, int d) { int l = -1, r = all.size(); while (r - l > 1) { int c = (l + r) / 2; if (all[c].first != d) { if (all[c].first < d) l = c; else r = c; } ...
5
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 7; long long t[maxn]; long long n, m, a, d; long long cnt, ed, nt; int main() { cin >> n >> m >> a >> d; for (int i = 1; i <= m; ++i) scanf("%lld", &t[i]); int idx = 1; while (idx <= m) { long long k = ed / a; if (k >= n) ed = t[...
1
#include <bits/stdc++.h> using namespace std; const int MOD = (int)1e9 + 7; const int FFTMOD = 119 << 23 | 1; const int INF = (int)1e9 + 23111992; const long long LINF = (long long)1e18 + 23111992; const long double PI = acos((long double)-1); const long double EPS = 1e-9; inline long long gcd(long long a, long long b)...
2
#include <bits/stdc++.h> using namespace std; int n; int f, g, t, vf; int main() { cin.sync_with_stdio(false); cout.sync_with_stdio(false); cin >> n; for (int d = 2; d * d <= n; d++) if (n % d == 0) { f = d; g = n / d; for (int h1 = 1; h1 < min(f, 5000); h1++) { int h2 = n - 1 - h1...
6
#include <bits/stdc++.h> int m[1000]; int main() { int n, r; int ptr1 = -1, ptr2; int cnt = 0; scanf("%d %d", &n, &r); for (int i = 0; i < n; i++) scanf("%d", m + i); ptr2 = r - 1; while (ptr1 != ptr2) { if (m[ptr2] == 1) { cnt++; ptr1 = ptr2; if (ptr2 + r >= n) { printf("%d\...
2
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; if (n % 2 == 0) { long long cnt = 1; for (int i = 0; i < n / 2; i++) { cnt *= 2; } cout << cnt; } else { cout << 0; } }
1
#include <bits/stdc++.h> using namespace std; void solve() { string s; cin >> s; long long n = s.length(); long long sum = 0; for (long long i = 0; i < n; i++) { long long a = s[i] - '0'; if (a % 4 == 0) sum++; } for (long long i = n - 1; i >= 1; i--) { string g; g.push_back(s[i - 1]); ...
2
#include <bits/stdc++.h> using namespace std; long long a, b, c, g, x, y; inline long long fixMod(long long a, long long m) { return (a % m + m) % m; } inline long long floor(long long a, long long b) { return (a - fixMod(a, b)) / b; } void getNewTerm(long long& g0, long long& g1, long long q) { long long t = g0 - ...
3
#include <bits/stdc++.h> using namespace std; using ll = long long; const int N = 100010; const int mod = 1000000007; template <typename T> using mat = vector<vector<T>>; template <typename T> mat<T> mult(mat<T>& a, mat<T>& b) { assert(a[0].size() == b.size()); mat<T> c(a.size(), vector<T>(b[0].size(), 0)); for (...
5
#include <bits/stdc++.h> using namespace std; long long pre[2000005], a[2000005], cnt[2000005], visit[2000005]; int32_t main() { long long n, x, y; scanf("%lld%lld%lld", &n, &x, &y); for (long long i = 1; i <= n; i++) { scanf("%lld", &a[i]); pre[a[i]] += a[i]; cnt[a[i]]++; } long long p = x / y, a...
2
#include <bits/stdc++.h> using namespace std; const int MAXN = 2e6 + 5; int par[MAXN]; int n, m, q; int sz[MAXN]; int a[301][301]; int dx[5] = {-1, 0, 1, 0}; int dy[5] = {0, 1, 0, -1}; vector<pair<int, int>> del[MAXN]; vector<pair<int, int>> add[MAXN]; int diff[MAXN]; bool check(int x, int y) { return (x >= 1 && x <= n...
6
#include <bits/stdc++.h> using namespace std; int n, seq[30100], aux[30100]; int s1, s2, t1, t2, ds, dt, ls, lt; bool fill(int start) { bool ok = true; for (int i = start; i < n; i++) { if (seq[i] == seq[ls] + ds) { ls = i; aux[i] = 0; } else if (t1 < 0) { t1 = i; aux[i] = 1; } e...
4
#include <bits/stdc++.h> using namespace std; int a[105]; int main() { int n, x, i; scanf("%d", &n); for (i = 0; i < n; i++) { scanf("%d", &x); a[x]++; } int h = 0; for (i = 1; i <= 100; i++) { if (a[i] > 1) { h = h + a[i] / 2; } } printf("%d\n", h / 2); return 0; }
2
#include<bits/stdc++.h> #define FOR(i,a,b) for(int i=(a);i<(int)(b);i++) using namespace std; const int mod = 2011; vector<string> s; vector<int> inv(mod,1); inline int get_base(int l, int t, int b){ FOR(i,t,b)if(s[i][l]!='.')return i; return t; } int expr(int &l, int &t, int &r, int &b); int fraction(int &l, i...
0
#include <bits/stdc++.h> using namespace std; const int MAX = 1001; char l[MAX][10][10]; int g[MAX][MAX]; bool c[MAX]; struct edge { int w; int p; int n; edge(int w, int p, int n) { this->w = w; this->p = p; this->n = n; } edge(int p, int n) { this->p = p; this->n = n; this->w = g[p]...
3
#include <bits/stdc++.h> using namespace std; int main() { int n, x1, y1, x2, y2; cin >> n >> x1 >> y1 >> x2 >> y2; int xmin = x1, xmax = x2, ymin = y1, ymax = y2; int a = (xmin - xmax) * (ymin - ymax); for (int i = 1; i < n; i++) { cin >> x1 >> y1 >> x2 >> y2; a += ((x2 - x1) * (y2 - y1)); if (x1...
1
#include <bits/stdc++.h> using namespace std; vector<int> p; int a[100][100]; int find_set(int v) { if (p[v] == v) return v; return p[v] = find_set(p[v]); } void union_sets(int a, int b) { a = find_set(a); b = find_set(b); if (rand() & 1) swap(a, b); p[a] = b; } int main() { int n, m; scanf("%d%d", &n, ...
3
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 79; vector<vector<int> > w(maxn); vector<int> who(maxn, -1), when(maxn, -1), wait(maxn, -1), tin(maxn, -1), tout(maxn); int timer = 0; void dfs(int v) { tin[v] = timer++; for (int i : w[v]) { dfs(i); } tout[v] = timer - 1; } bool in_su...
4
#include <stdio.h> #include <algorithm> using namespace std; int main(){ while (1){ int i,m,n,sum=0; int L[1000]; scanf("%d %d",&n,&m); if (n==0 && m==0) return 0; for (i=0;i<n;i++){ scanf("%d",&L[i]); sum+=L[i]; } sort(L,L+n); for (i=n-m;i>=0;i-=m) sum-=L[i]; pr...
0
#include <bits/stdc++.h> using namespace std; void balance(string s, int n, int l) { long long int sum = 0; for (int i = 0; i < l; i++) { if (s[i] != '=' && i != n) { long long int p = s[i] - 48; sum += p * (n - i); } } if (sum == 0) cout << "balance"; else if (sum > 0) cout << "le...
1
#include <bits/stdc++.h> using namespace std; const int N = 100100; int difcol[N], difpos[N], num[N], last[N], pos[N], far[N], ans[N], can[N]; vector<int> gr[N], ys[N]; int n, m; int lowbit(int x) { return x & (-x); } void add(int a, int* pArr, int v) { while (a <= n) { (*(pArr + a)) += v; a += lowbit(a); }...
4
#include <bits/stdc++.h> #define int long long using namespace std; const int maxn = 200005; set<int> adj[maxn]; int sz[maxn]; set<pair<int,int>> s; void calcSizes(int u, int par) { sz[u] = 1; for (int v : adj[u]) { if (v == par) continue; calcSizes(v, u); sz[u] += sz[v]; } } pa...
5
#include <bits/stdc++.h> using namespace std; int main() { unsigned long long a, b; cin >> a >> b; while (1) { if (a == 0 || b == 0) break; else if (a >= (2 * b)) a = a % (2 * b); else if (b >= (2 * a)) b = b % (2 * a); else break; } cout << a << " " << b << endl; ret...
2
#include <bits/stdc++.h> using namespace std; const int N = 200005, mod = 1e9 + 7; int n, cnt, prime[N], phi[N], mu[N], a[N], id[N], c[N]; bool vis[N]; int Pow(int x, int k) { int ret = 1; while (k) { if (k & 1) ret = (long long)ret * x % mod; k >>= 1; x = (long long)x * x % mod; } return ret; } voi...
5
#include <bits/stdc++.h> using namespace std; const int MAXN = 2e5 + 5; const long long MOD = 998244353; int n; long long k; long long fac[MAXN]; long long inv[MAXN]; long long Pow(long long a, long long b) { long long result = 1; while (b) { if (b & 1) { result *= a; result %= MOD; } a *= a...
5
#include <bits/stdc++.h> using namespace std; #define ll long long #define F(i,a,b) for(int i=a;i<=b;++i) #define R(i,a,b) for(int i=a;i<b;++i) #define mem(a,b) memset(a,b,sizeof(a)) int n, k; int a[100100], b[100100]; ll ans, ret; int c; int main() { cin >> n >> k; F(i, 1, n) scanf("%d %d", a + i, b + i); ans = 0...
0
#include<bits/stdc++.h> #define fo(i,a,b)for(int i=a,_e=b;i<=_e;++i) using namespace std; const int N=2e5+5,inf=1e9; int n,p[N],q[N],b[N],b2[N],bs1,bs,ans; int la[N],ne[N*2],to[N*2],l[N*2],h[N],st[N],d[N],js; bool bz[N]; void link(int x,int y,int z){ // printf("%d %d\n",x,y); ne[++js]=la[x];la[x]=js;to[js]=y;l[js]=z;...
0
#include <bits/stdc++.h> using namespace std; long long binary(long long mid) { long long i = 2, possibilities = 0; while (i * i * i <= mid) { possibilities += mid / (i * i * i); i++; } return possibilities; } int main() { long long m, min, max; scanf("%I64d", &m); min = -1; max = 1e17; while ...
3
#include <bits/stdc++.h> using namespace std; long long merge(long long a[], long long l, long long mid, long long r) { long long cnt = 0; long long size_l = mid - l + 1, size_r = r - mid; long long left[size_l], right[size_r]; for (long long i = 0; i < size_l; i++) left[i] = a[l + i]; for (long long i = 0; i...
5
#include <bits/stdc++.h> using namespace std; const long long OO = 1e14; signed main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); long long t = 1, n, x; while (t--) { cin >> n; long long ans = 1; map<long long, long long> mp1, mp2; for (long long i = 1; i < n + 1; ++i) { cin >>...
2
#include <bits/stdc++.h> using namespace std; int parent[100010]; int sz[100010]; int Time, cnt; struct operation { int type, id, old, New, Time; operation() {} operation(int type, int id, int old, int New, int Time) : type(type), id(id), old(old), New(New), Time(Time) {} operation(const operation &op) ...
5
#include <bits/stdc++.h> using namespace std; void out(string s) { cout << s << endl; cout.flush(); } int getdist(string i) { out(i); int res; scanf("%d", &res); if (res == 0) exit(0); return res; } string gets(int pos, int length) { string s = ""; for (int i = (0); i < (length); i++) { if (i == p...
4
#include <bits/stdc++.h> using namespace std; long long const INF = 2e18 + 100; int const MAX = 3 * 1e5 + 10; long long l = (1LL << 62); unsigned long long m = (1LL << 63); vector<pair<int, int> > v; multiset<int> mset; multiset<int, greater<int> > ms; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)...
2
#include<bits/stdc++.h> using namespace std; #define rep(i,n) for(int i=0;i<n;i++) typedef long long ll; struct edge{int to,cost;}; typedef pair<int,int> P; int V; vector<edge> G[200001]; int mincost[200001],INF=1e9,used[200001]={0}; int prim(){ priority_queue<P,vector<P>,greater<P> > que; fill(mincost,mincost+...
0
#include "iostream" #include "climits" #include "list" #include "queue" #include "stack" #include "set" #include "functional" #include "algorithm" #include "string" #include "map" #include "unordered_map" #include "unordered_set" #include "iomanip" #include "cmath" #include "random" #include "bitset" #include "cstdio" ...
0
#include <bits/stdc++.h> using namespace std; int n,m,q,a1,b1,a2,b2,a[2005][2005],s1[2005][2005],s2[2005][2005],s3[2005][2005];char c[2005]; int gao1(int a1,int b1,int a2,int b2){return s1[a2][b2]-s1[a1-1][b2]-s1[a2][b1-1]+s1[a1-1][b1-1];} int gao2(int a1,int b1,int a2,int b2){return s2[a2][b2]-s2[a1-1][b2]-s2[a2][b1-1...
0
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; const long long linf = 1e18; const double pi = acos(-1.0); const int MAXN = 1e6 + 10; const int MAXM = 1e5 + 10; const double eps = 1e-8; char s[MAXN]; int m; deque<char> q; int main() { int n; scanf("%d", &n); scanf("%s", s); scanf("%d",...
3
#include <bits/stdc++.h> using namespace std; void build(long long v, long long tl, long long tr, long long st[], long long lz[], bool f[], long long a[]) { if (tl == tr) { st[v] = a[tl]; lz[v] = 0LL; f[v] = false; return; } build((v << 1), tl, ((tl + tr) >> 1), st, lz, f, a); build((...
2
#include<bits/stdc++.h> using namespace std; int main(){ int test; cin>>test; while(test--){ int a,b,c; cin>>a>>b>>c; int a1=a,b1=b; while(a1%2==0){ a1=a1/2; } while(b1%2==0){ b1=b1/2; } if(a*b/(a1*b1)>=c){ ...
1
#include <bits/stdc++.h> using namespace std; const long long MOD = 1000000007; const long long SIZE = 100000; const int INF = 0x3f3f3f3f; const long long ll_INF = 0x3f3f3f3f3f3f3f3f; const long double PI = acos(-1); const long long MAXN = numeric_limits<long long>::max(); const long long MAX = 2000000; void solve() { ...
2
#include <bits/stdc++.h> using namespace std; int main() { long long cnt[10010]; long long ans = 0; string s; int n,p; cin >> n >> p >> s; if(p == 2 || p == 5) { for(int i = 0;i < n;i++) if((s[i] - '0') % p == 0) ans += i + 1; } else ...
0
#include <bits/stdc++.h> using namespace std; bool hasCycle = false; int VISITED = 2; int UNVISITED = 0; int VISITING = 1; void dfs(int u, int p, vector<vector<int>>& g, vector<int>& vis) { if (hasCycle) return; vis[u] = VISITING; for (int e : g[u]) { if (e != p && vis[e] == VISITING) { hasCycle = true;...
3
#include <bits/stdc++.h> using namespace std; int n, m, num = 0, mx = 0, f[200010], fa[200010][20], st[200010][20], ans[200010], val[200010], h[200010], flag[200010], d[200010]; struct node { int x, y, z, id; } a[200010]; struct edge { int x, y, z, next; } mp[200010 << 1]; inline char gc() { static char...
6
#include <bits/stdc++.h> using namespace std; long long n, ans, x, y, c, d, a[1000000]; priority_queue<long long, vector<long long>, greater<long long> > pq; int main() { cin >> n >> x >> y; for (int i = 0; i < n; i++) cin >> a[i], pq.push(a[i]); if (x > y) cout << n; else { ans = 0; while (pq.size(...
3
#include <bits/stdc++.h> #define int long long #define fi first #define se second using namespace std; const int inf = 1e18; const int maxN = 2e5 + 10; int n, q, a, b, p, c, i; int st[2][maxN * 4], ans[maxN], tmp = 0, res = inf; void build(int l, int r, int id) { if (l == r) { st[0][id] = ans[l] - ...
0
#include <bits/stdc++.h> using namespace std; const int maxn = 4e5 + 5; int to[maxn][26]; int leaf[maxn]; int deg[maxn]; int h[maxn]; int iter = 0; int res = 0; int term[maxn]; void add_string(string &s) { vector<int> path; int raz = -1; res = 0; int z = -1; int v = 0; for (int i = 0; i < s.size(); ++i) { ...
4
#include <bits/stdc++.h> using namespace std; const int mn = INT_MIN; const int mx = INT_MAX; int a[505][505]; int kng = 0, k = 0; int n, m; bool vst[505][505]; void dfs(int i, int j) { vst[i][j] = 1; for (auto k = i - 1; k < int(i + 2); k++) for (auto l = j - 1; l < int(j + 2); l++) { if ((k == i || l ==...
1
#include <bits/stdc++.h> int main() { int n; scanf("%d", &n); int i = 1; while ((i * (i + 1) / 2) <= n) { if ((i * (i + 1) / 2) == n) { printf("YES"); return 0; } i++; } printf("NO"); }
1
#include <stdio.h> #include <string.h> #include <algorithm> #include <iostream> #include <math.h> #include <assert.h> #include <vector> #include <queue> #include <string> #include <map> #include <set> using namespace std; typedef long long ll; typedef unsigned int uint; typedef unsigned long long ull; static const dou...
0
#include<iostream> #include<algorithm> #include<cstring> #include<cstdio> #include<queue> #include<bitset> #include<complex> using namespace std; template<typename __T> inline void read(__T &x) { x=0; int f=1;char c=getchar(); while(!isdigit(c)){if(c=='-') f=-1;c=getchar();} while(isdigit(c)) {x=x*10+c-...
0
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long n, m; cin >> n >> m; vector<long long> a(m), b(m); vector<vector<long long>> stat(n); for (long long i = 0; i < m; i++) { cin >> a[i] >> b[i]; a[i]--, b[i]--; stat[a[i]...
1
#include <bits/stdc++.h> using namespace std; const int maxn = 3010; struct GG { int x, cnt; bool operator<(const GG& obj) const { return cnt > obj.cnt; } } p[maxn]; int vis[maxn][maxn]; long long group[maxn][maxn]; long long sum[maxn][maxn]; long long rest[maxn]; int n, m; int main() { scanf("%d %d", &n, &m); ...
1
#include <bits/stdc++.h> using namespace std; int main(void) { int N; cin >> N; int num; vector<int> P; for(int i=0;i<N;i++){ cin >> num; P.push_back(num-1); } vector<int> Q(N); for(int i=0;i<N;i++){ Q[P[i]] = i; } multiset<int> M = {-1,-1,N,N}; ...
0
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 100; const long long INF(0x3f3f3f3f3f3f3f3fll); const int inf(0x3f3f3f3f); long long pow_mod(long long x, long long n, long long mod) { long long res = 1; while (n) { if (n & 1) res = res * x % mod; x = x * x % mod; n >>= 1; } retu...
4
#include <bits/stdc++.h> using namespace std; long long int mod = 1e9 + 7; int a[15000200], t[15000200], b[15000200]; char c[6000]; int n, k, lst, dp; void build(int p, int v) { t[v]++; if (p == n) return; if (c[p] == 'a') { if (a[v] == 0) { a[v] = lst; lst++; } build(p + 1, a[v]); } els...
5
#include <stdio.h> int main(){ int arr[26]={0}, i; int c; while ((c=getc(stdin))!=EOF){ if (c>='A' && c<='Z') arr[c-65]++; else if (c>='a' && c<='z') arr[c-97]++; } for (i=0; i<26; i++) printf("%c : %d\n",i+97 , arr[i]); }
0
#include <bits/stdc++.h> using namespace std; long long n, m, S, ans; int a[3], b[3], s[3]; vector<long long> cc; map<int, int> sp, np; inline void trans_(map<int, int>::iterator x, long long sum) { if (sum > n) return; if (x == sp.end()) return ++ans, void(); long long now = 1; auto it = x; it++; for (int ...
3
// #define _CRT_SECURE_NO_WARNINGS #include <iostream> #include <cstdio> #include <algorithm> #include <string> #include <vector> #include <map> #include <set> #include <stack> #include <cmath> #include <cstdlib> #include <functional> #include <locale> #include <cctype> #include <sstream> using namespace std; typedef ...
0
#include <bits/stdc++.h> using namespace std; int main() { string a; cin>>a; for (int i=0;i<a.size();i++) cout<<"x"; return 0; }
0
#include <bits/stdc++.h> int main() { int i, n, m; scanf("%d%d", &n, &m); if (m == 3 && n >= 5) printf("-1\n"); else for (i = 0; i < n; ++i) printf("%d %d\n", i, (10000000 + i * i) * (i >= m ? -1 : 1)); return 0; }
2
#include <bits/stdc++.h> #pragma GCC target("sse,sse2,sse3,ssse3,sse4,abm,mmx,avx,avx2,popcnt,fma") #pragma GCC optimize("fast-math") using namespace std; const long long mod = 1e9 + 7, mod2 = 998244353; const long double eps = 1e-6; const long long inf = 1e18; const int base = 1e9; const long double PI = 3.14159265358...
3
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); int cl = 0, ha = 0, op = 0; string s, t; cin >> s; for (int i = 0; i < s.length(); i++) { if (s[i] == '(') { op++; } if (s[i] == ')') { cl++; } if (s[i] == '#') { ha++; } } ...
1
#include <iostream> #include <vector> #include <algorithm> #include <cstring> using namespace std; int h,w,n; char initField[51][51]; char field[51][51]; int cnt=0; bool del[51][51]; bool search(){ int sum=0; for(int i=0;i<h;i++)for(int j=0;j<w;j++)if(field[i][j]!='.')sum++; while(sum){ // —މºˆ— for(int j=...
0
#include <bits/stdc++.h> using namespace std; int knight[100000]; int is_possible(int t, int n) { vector<int> r(t, 1); for (int i = 0; i < n; i++) r[i % t] &= knight[i]; for (int i = 0; i < r.size(); i++) if (r[i]) return 1; return 0; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int...
3
#include <bits/stdc++.h> using namespace std; int main(){ int H, W, K; cin >> H >> W >> K; vector<string> table(H); int ans = 0; for (int i=0; i<H; i++){ cin >> table.at(i); } for (int i=0; i < (1<<H); i++){ for (int j=0; j < (1<<W); j++){ int cnt =0; for (int a=0; a<H; a++){ ...
0
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int sumPos = 0, sumNeg = 0; while (n > 0) { int temp; cin >> temp; if (temp > 0) sumPos += temp; else sumNeg += temp; n--; } cout << sumPos - sumNeg; return 0; }
1
#include <bits/stdc++.h> using namespace std; template <typename T> T inverse(T a, T m) { T u = 0, v = 1; while (a != 0) { T t = m / a; m -= t * a; swap(a, m); u -= t * v; swap(u, v); } assert(m == 1); return u; } template <typename T> class Modular { public: using Type = typename decay...
3
#include <bits/stdc++.h> #define rep(i,n) for(int (i)=0;(i)<(n);(i)++) using namespace std; const int vmax=110; const int inf=1023456789; int N,M; int S,T; struct node{int to,cap,rev;}; vector<node> graph[vmax]; bool used[vmax]; int dfs(int v,int t,int f){ if(v==t) return f; used[v]=true; for(auto &e:graph[v]){ ...
0
#include <bits/stdc++.h> using namespace std; void run(); int main() { ios::sync_with_stdio(0); run(); } void run() { int v[2]; cin >> v[0] >> v[1]; int best = 0; for (int i = 2; i--;) { int w[2] = {v[0], v[1]}; swap(v[0], v[1]); int got = -1; for (int j = 0, k = 0, t = 0; w[0] + w[1]; j++, ...
2
#include <bits/stdc++.h> using namespace std; int main() { int a,b,c; cin>>a>>b>>c; int ans=(a-b)%c; cout<<ans<<"\n"; }
0
#include<bits/stdc++.h> using namespace std; int main(){ int n; while(cin>>n,n){ int a[10000]; double s=0; for(int i=0;i<n;i++)cin>>a[i],s+=a[i]; int ans=0; for(int i=0;i<n;i++)ans+=s/n>=a[i]; cout<<ans<<endl; } return 0; }
0
#include <iostream> using namespace std; template <class T> void extgcd(T a, T b, T &x, T &y) { T r0 = a, r1 = b, r2; T a0 = 1, a1 = 0, a2; T b0 = 0, b1 = 1, b2; while (r1 > 0) { T q1 = r0 / r1; T r2 = r0 % r1; T a2 = a0 - q1 * a1; T b2 = b0 - q1 * b1; r0 = r1, r1 = r2; a0 = a1, a1 = a2; b0 = b1, b1 =...
0
#include<bits/stdc++.h> #define rep(i,n) for (int i=0; i<(n); i++) using namespace std; int main() { int n; string s; cin >> n >> s; int r = 0, ans = 0; rep(i,n) if (s[i] == 'R') r++; rep(i,r) if (s[i] == 'W') ans++; cout << ans << endl; }
0
#include <bits/stdc++.h> using namespace std; int main() { std::cin.tie(); std::ios::sync_with_stdio(false); int n; cin >> n; int ch[n + 1]; memset(ch, 0, sizeof ch); int a[n]; bool done[n + 1]; memset(done, 0, sizeof ch); for (int i = 0; i < n; i++) { cin >> a[i]; ch[a[i]]++; ; } qu...
4
#include <stdio.h> int main(){ int a,b,c; scanf("%d%d%d",&a,&b,&c); if(a>=c)printf("0\n"); else if(a+b<c)printf("NA\n"); else printf("%d\n",c-a); }
0
#include <bits/stdc++.h> using namespace std; long long a, b, c; const long long MOD = 998244353ll; const int MAXN = 5005; long long fans = 0; long long cx[MAXN][MAXN]; long long ax[MAXN]; long long solve(long long x, long long y) { long long ans = 0; long long mn = min(x, y); long long mx = max(x, y); ans += 1...
3
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; int n, k, Mod, des, A[N], M[N], Pw[N], Inv[N], H[N], sz[N], In[N], Out[N], up[N], dn[N]; long long tot; vector<int> Adj[N]; map<int, int> U, C, T; inline int Power(int a, int b) { int ret = 1; for (; b; b >>= 1, a = 1ll * a * a % Mod) if (...
5
#include <bits/stdc++.h> using namespace std; int main() { long long int n; cin >> n; string l = "312931303130313130313031"; string input = ""; string s = "312831303130313130313031"; string s1 = s + s + s; string s2 = l + s + s; string s3 = s + l + s; string s4 = s + s + l; long long int i; for (i...
2
#include <iostream> #include <cstdio> using namespace std; int main() { int A,B; cin>>A>>B; if (A*B%2) printf("Yes"); else printf("No"); }
0
#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 > 0) { if (y & 1) res = (res * x) % p; y = y >> 1; x = (x * x) % p; } return res; } long long int modInverse(long long int n, long long ...
3
#include <bits/stdc++.h> using namespace std; bool cmp(int a, int b) { return a > b; } int main() { int a[100005]; int n, n1, n2, i, j, t; long long sum1 = 0, sum2 = 0; scanf("%d%d%d", &n, &n1, &n2); for (i = 0; i < n; i++) scanf("%d", &a[i]); sort(a, a + n, cmp); if (n1 > n2) { t = n1; n1 = n2; ...
2
#include <bits/stdc++.h> using namespace std; int main() { int q; cin >> q; for (int l = 0; l < q; ++l) { int n; cin >> n; string a[n]; int ot; int i, j, kln = 0, norm = 0, kls = 0; for (i = 0; i < n; ++i) { int kl1 = 0, kl0 = 0; cin >> a[i]; if (a[i].size() % 2 != 0) kls...
2
#include <bits/stdc++.h> using namespace std; const int MAXN = 100020; int val[MAXN]; long long dp[MAXN]; int main() { int N, upper = 0; scanf("%d", &N); for (int i = 1; i <= N; i++) scanf("%d", &val[i]); while ((1 << (1 + upper)) <= N) ++upper; for (int i = 1; i < N; i++) { int pre = i; while (pre < ...
1
#include<iostream> #include<algorithm> #define ll long long using namespace std; const int maxn=2e5+10; int d[maxn],f[maxn]; int main(){ int n,a,b; cin>>n; for(int i=1;i<=n;i++){ cin>>a>>b; f[i]=a+b; d[i]=a-b; } sort(f+1,f+1+n); sort(d+1,d+1+n); ll x=max(f[n]-f[1],d[n]-d[1]); cout<<x<<endl; }
0
#include <bits/stdc++.h> using namespace std; int vis[209]; int q[4]; int main() { ios::sync_with_stdio(false); int t; cin >> t; while (t--) { int n, m; cin >> n >> m; memset(vis, 0, sizeof(vis)); for (int i = 0; i < m; i++) { int q; cin >> q; vis[q] = 1; } for (int i =...
1
#include <bits/stdc++.h> using namespace std; inline void srand() { srand(chrono::high_resolution_clock::now().time_since_epoch().count()); } template <class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& v) { os << "(" << v.first << "," << v.second << ")"; return os; } template <class T> ostream&...
6
#include<bits/stdc++.h> using namespace std; int main(){ int n,a,b; cin >> n >> a >> b; if(n==a+b||a==b+n||b==a+n){ cout << "Yes"; } else{ cout << "No"; } }
0
#include <bits/stdc++.h> using namespace std; int arr[150] = {0}; int main() { int i; string str; cin >> str; for (i = 0; i < str.length(); i++) arr[(int)str[i]]++; vector<int> v; v.push_back(arr[(int)'B']); v.push_back(arr[(int)'l']); v.push_back(arr[(int)'b']); v.push_back(arr[(int)'s']); v.push_b...
1
#include <bits/stdc++.h> using namespace std; unordered_map<long long, long long> cnt; int n, p, k; long long qpow(long long a, long long b, long long c) { long long ret = 1; for (; b; b >>= 1, (a *= a) %= c) if (b & 1) (ret *= a) %= p; return ret; } int main() { ios::sync_with_stdio(false); cin.tie(0); ...
2
#include <bits/stdc++.h> using namespace std; struct debugger { template <typename T> debugger& operator,(const T v) { cerr << v << " "; return *this; } } dbg; const double pi = acos(-1.0); const double eps = 1e-7; template <class TT> TT sqr(TT a) { return a * a; } template <class TT> TT abs(TT a) { i...
3
#include <bits/stdc++.h> using namespace std; const int N = 200010; const double e = 1e-11; double a[N]; int n; double miin, maax; double Min, Max; void Do(double t) { Min = 1e9; Max = -1e9; double sum = 0; double in = 0, ax = 0; for (int i = 0; i < n; ++i) { sum += a[i] + t; in = min(in, sum); ax...
3
#include <bits/stdc++.h> using namespace std; vector<int> vec; int flag[100001]; int degree[100001]; int pre[100001]; int trace[100001]; int cnt; int main() { int i, j; int n; while (scanf("%d", &n) != EOF) { vec.clear(); memset(degree, 0, sizeof(degree)); for (i = 1; i <= n; i++) { scanf("%d", ...
2
#include <bits/stdc++.h> using namespace std; double p[105]; int n; bool cmp(double a, double b) { return a > b; } int main() { int n; cin >> n; for (int i = 0; i < n; ++i) cin >> p[i]; sort(p, p + n, cmp); double ans = 0; double zero = 1, one = 0; for (int i = 0; i < n; ++i) { one = zero * p[i] + one...
2
#include <bits/stdc++.h> using namespace std; int n, m; long long ans, sum; struct ming { int price, size, num; } a[100005], b[100005]; bool cmp(ming a, ming b) { return a.price > b.price; } map<int, int> mp; vector<int> G[100005]; int p[100005]; bool dfs(int x) { int siz = G[x].size(); for (int i = 0; i < siz; i...
4
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; const int MAXN = N; const long long INF = 1e18 + 7; const long long Q = -(1ll << 60); struct line { long long m, p; mutable set<line>::iterator prev; }; set<line>::iterator null; bool operator<(const line& a, const line& b) { if (b.p != Q && a.p...
5
#include <bits/stdc++.h> using namespace std; int n, m; class Node { public: int n = 0; bool fixed = true; int cost = 0; int d = 0; Node() {} Node(int n, bool fixed) { this->n = n; this->fixed = fixed; } Node(int n, int d, int cost) { this->n = n; this->cost = cost; this->d = d; }...
5
#include <bits/stdc++.h> using namespace std; int main() { string s, t, u; cin >> s; cin >> t; u = ""; for (int i = 0; i < s.length(); i++) if (t[i] > s[i]) { cout << -1; return 0; } else if (t[i] == s[i]) u += "z"; else u += t[i]; cout << u; return 0; }
2
#include <bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<int, int>; const double PI = 4 * atan(1); const int INF = 0x3f3f3f3f; const ll LINF = 0x3f3f3f3f3f3f3f3f; const int MOD = 1e9 + 7; const int MAX_N = 2e6 + 10; int n, k; void solve() { const int len = (n - 1) / k; if ((n - 1) % k <=...
2
#include <bits/stdc++.h> using namespace std; set<int> s; int ansa, ansb; list<stack<int> > otro; void generarserie(int valor) { int inicial = ansb / valor; inicial *= valor; stack<int> algo; if (inicial < ansb) inicial += valor; while (inicial <= ansa) { algo.push(inicial); inicial += valor; } ot...
3
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const double eps = 1e-8; const double PI = acos(-1.0); const int MAXN = 1e5 + 5; const int MAXM = 2e6 + 5; const int MOD = 1e9 + 7; int sgn(double x) { if (fabs(x) < eps) return 0; if (x < 0) return -1; else return 1; } long long pw...
3