solution
stringlengths
52
181k
difficulty
int64
0
6
#include <bits/stdc++.h> #pragma comment(linker, "/stack:200000000") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #pragma GCC optimize("unroll-loops") using namespace std; template <typename T> constexpr long long infValue = std::is_same<T, int>::value ? 2000100007 : 860000000000000...
5
#include <bits/stdc++.h> using namespace std; const int MAXN = 105; const long long INF = (long long)1e18; int n, m, A[MAXN], X[MAXN], Y[MAXN]; set<int> S; int nodes, src, dst; int dist[MAXN], q[MAXN], work[MAXN]; struct edge { int to, rev; long long f, cap; }; vector<edge> g[MAXN]; void add_edge(int s, int t, long...
3
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; bool vis[1000000 + 10]; long long a[1000000 + 10]; int n; int ma; int k; int ans = 1; int hehe = 1; int f[100000 + 10]; long long gcd(long long a, long long b) { if (b == 0) return a; else return gcd(b, a % b); } void work(int tem) { ...
2
#include<iostream> #include<vector> using namespace std; int main(){ int n; cin>>n; vector<int> a(n), cnt(1000001); for(int i=0;i<n;i++){ cin>>a[i]; ++cnt[a[i]]; } for(int i=1000000;i>=1;i--){ for(int j=2*i;j<=1000000;j+=i){ cnt[j]+=cnt[i]; } } ...
0
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long n, s, d, cur, i; cin >> n; cin >> s >> d; cur = s; for (i = 1; i < n; ++i) { cin >> s >> d; cur = s + d * ((max(0LL, cur - s + 1) + d - 1) / d); } cout << cur...
1
#include <bits/stdc++.h> using namespace std; template <class T, class U> void maximize(T &x, U y) { if (x < y) x = y; } template <class T, class U> void minimize(T &x, U y) { if (x > y) x = y; } template <class T> T Abs(T x) { return (x < 0 ? -x : x); } template <class T> T safe_sqrt(T x) { return sqrt(max(x, ...
4
#include <iostream> using namespace std; int main(){ char S[100]; int a,b; while(1){ cin>>S; if(S[0]=='0') break; for(int i=1;S[i]!='\0';i++){ if(S[i]=='A') a++; if(S[i]=='B') b++; } if(a>b) a++; else b++; cout<<a<<' '<<b<<endl; a=0; b=0; } return 0; }
0
#include <bits/stdc++.h> using namespace std; void optimizeIO() { ios_base::sync_with_stdio(false); cin.tie(NULL); } int main() { optimizeIO(); int n, K, ans = INT_MIN; cin >> n >> K; vector<int> v(n); for (int i = 0; i < n; i++) cin >> v[i]; for (int i = 0; i < n; i++) for (int j = i; j < n; j++) {...
1
#include <bits/stdc++.h> using namespace std; int main() { int tests; int a, b; cin >> tests; while (tests--) { cin >> a >> b; if (((a > b * 2) || (a * 2 < b)) || ((a + b) % 3)) cout << "NO\n"; else cout << "YES\n"; } return 0; }
2
#include <bits/stdc++.h> using namespace std; int main() { int q, ct = 0; string old, nyu; map<string, string> child, par; map<string, bool> eee, der; cin >> q; for (int i = 0; i < q; i++) { cin >> old >> nyu; if (eee[old] == true) { child[par[old]] = nyu; par[nyu] = par[old]; eee[...
2
#include <bits/stdc++.h> using namespace std; int main() { long long n, m, k; cin >> n >> m >> k; map<long long, vector<pair<long long, long long>>> d1, d2; map<pair<long long, long long>, long long> pos; vector<long long> ans(k, -1); for (int i = 0; i < k; ++i) { long long a, b; cin >> a >> b; ...
3
#include <bits/stdc++.h> using namespace std; int n, m, ch, a[1005][105], ans[10000001][2], s = 0, i, j, k, temp; int main() { cin >> n >> m >> ch; for (i = 1; i <= n; i++) for (j = 1; j <= m; j++) cin >> a[i][j]; if (ch == 0) { for (i = 1; i <= m; i++) for (j = i + 1; j <= m; j++) { for (k ...
2
#include <bits/stdc++.h> using namespace std; int main() { int n; string s; cin >> n; cin >> s; for (int i = 0; i < (n); ++i) for (int j(1); j < (n); ++j) if (i + 4 * j < n) { bool ok = 1; for (int k = 0; k < (5); ++k) { if (s[i + k * j] != '*') { ok = 0; ...
1
#include <bits/stdc++.h> const int maxn = 2e5 + 3; int n, m, l[maxn], p[maxn], a[maxn]; bool check() { for (int i = 0; i < m; ++i) { if (n - l[i] < i) { return false; } } long long t = 0; for (int i = 0; i < m; ++i) { t += l[i]; } if (t < n) { return false; } return true; } int mai...
1
#include <bits/stdc++.h> using namespace std; long long int mod = 1e9 + 7; long long int fexpo(long long int a, long long int b) { if (b == 0) return 1LL; if (b == 1) return a; if (b == 2) return ((a) * (a)); if (b % 2 == 0) return fexpo(fexpo(a, b / 2), 2); else return ((a) * (fexpo(fexpo(a, (b - 1) ...
3
#include <bits/stdc++.h> using namespace std; int n, k; int grundy(int x) { if (k % 2 == 0) { if (x == 1) return 1; if (x == 2) return 2; return 1 - (x % 2); } if (x == 1 || x == 3) return 1; if (x % 2) return 0; int v1 = grundy(x / 2), v2 = grundy(x - 1); int yo1 = min(v1, v2), yo2 = max(v1, v2...
3
#include <bits/stdc++.h> using namespace std; int par1[100008]; int par2[100008]; vector<pair<int, int>> result; int find1(int r) { if (par1[r] == r) return r; else return par1[r] = find1(par1[r]); } int find2(int r) { if (par2[r] == r) return r; else return par2[r] = find2(par2[r]); } int main(...
4
#include <bits/stdc++.h> using namespace std; const int mod = 998244353; const int maxn = 10000 + 10; long long mypow(long long x, long long res) { if (res == 0) return 1; long long cur = mypow(x, res >> 1); cur = cur * cur % mod; if (res & 1) cur = cur * x % mod; return cur; } long long fac[maxn], rev[maxn];...
5
#include <bits/stdc++.h> using namespace std; #include <math.h> int main() { int A,B,C,D; cin>>A>>B>>C>>D; cout<<max(0,min(B,D)-max(A,C))<<endl; return 0;}
0
#include <bits/stdc++.h> using namespace std; int main() { int k_comp, k_player; cin >> k_comp >> k_player; int max_v[k_comp]; for (int i = 0; i < k_comp; i++) cin >> max_v[i]; int maxi_i, maxi; for (int i = 0; i < k_comp; i++) { maxi = 15; for (int j = i; j < k_comp; j++) { if (max_v[j] > max...
2
#include <bits/stdc++.h> using namespace std; const int maxn = 410; int cl[maxn * maxn]; int po[maxn * maxn]; int pre[maxn * maxn * 2]; int cnt[maxn * maxn * 2]; short cc[maxn * maxn * 2]; short F[maxn][maxn]; short g[maxn][maxn]; int a[maxn][maxn]; int b[maxn][maxn]; int pos[maxn][maxn]; int n, m; int find(int x) { re...
4
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") using namespace std; bool isprime(long long int n) { if (n <= 1) return false; for (long long int i = 2; i * i <= n; ++i) if (n % i == 0) return false; return true; } long long int expo(long long int a, long long int n) { if (n == 0) return 1; if (n =...
3
#include <bits/stdc++.h> using namespace std; const int Mo=1000000007; map <long long,int> f; inline int solve(long long n) { if(f.count(n)) return f[n]; return f[n]=((solve(n/2)+solve((n-1)/2))%Mo+solve((n-2)/2))%Mo; } int main() { f[0]=1,f[1]=2; long long n; cin>>n; cout<<solve(n); return ...
0
#include <bits/stdc++.h> using namespace std; const int N = 4e5 + 2; signed main() { ios::sync_with_stdio(false); cin.tie(0); srand(time(NULL)); int N; long long sa = 0, sb = 0; cin >> N; vector<int> A(N), B(N), ind(N); iota(ind.begin(), ind.end(), 0); for (int i = 0; i < N; ++i) { cin >> A[i]; ...
4
#include <bits/stdc++.h> using namespace std; int f[200003]; int find(int x) { if (x != f[x]) f[x] = find(f[x]); return f[x]; } void Union(int x, int y) { int fx = find(x), fy = find(y); if (fx != fy) f[fx] = fy; } struct edge { int to, next; } e[200003 << 1]; int head[200003], cnte; void add(int u, int v) { ...
5
#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 r = 1; x = x % p; while (y) { if (y & 1) r = r * x % p; y = y >> 1; x = x * x % p; } return r; } const int N = 5e3 + 99; vector<int> z_function(string &s) { int n ...
6
#include <bits/stdc++.h> using namespace std; const int maxn = 2005; const unsigned long long lmx = (1ull << 63) - 1 + (1ull << 63); int n, m, i, j, t, k, s, N, head[maxn], Head[maxn], col[maxn], tot; int tp, stk[maxn], dfn[maxn], low[maxn], ti, f[maxn], ct[maxn], siz[maxn], g[maxn], fa[maxn]; bool flg; struct BTST...
5
#include <bits/stdc++.h> using namespace std; mt19937 rnd(23049809); class node { public: int ch[2], val, key, add, ans, cnt; } t[200010]; inline void pushnow_add(int p, int v) { if (!p) return; t[p].add += v; t[p].val += v; } inline void pushnow_cnt(int p, int v) { if (!p) return; t[p].cnt += v; t[p].an...
6
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int MAXN = 1e5; int N, M, K; vector<int> adj[MAXN+10]; unordered_map<string, int> MM; bool cyc=false; int vis[MAXN+10]; vector<int> S; void dfs(int now) { vis[now]=1; for(int nxt : adj[...
5
#include<bits/stdc++.h> using namespace std; long long n,m,p,ans; int main() { scanf("%lld%lld%lld",&n,&m,&p); ans=m/p-n/p; if(n%p==0)ans++; printf("%lld",ans); }
0
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); long long t, n, i, zero = 0, j, flag = 0, temp, minus = 0, plus = 0, m, k, sz, sm, res = 0; long long mn, mx; long long l, r; long long x, y, z; long long c, ...
2
#include <bits/stdc++.h> using namespace std; int max1(int arr[], int); int min1(int arr[], int); int main() { long int n, m; cin >> n >> m; int A, B; int u[m], v[m], i, j; if (m == 0) { cout << n - 1; } else { for (i = 0; i < m; i++) { cin >> u[i] >> v[i]; if (u[i] > v[i]) { j =...
2
#include<iostream> using namespace std; int main(){ int n; cin>>n; int i=1; do{ int x=i; if(x%3==0)cout<<" "<<i; else { while(x){if(x%10==3){cout<<" "<<i;break;}x/=10;} }}while(++i<=n); cout<<endl; }
0
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; const int N = 4e5 + 10; const long long mod = 998244353; long long a[N], dp[N]; void ex_gcd(long long a, long long b, long long &x, long long &y) { if (!b) { x = 1, y = 0; return; } ex_gcd(b, a % b, x, y); long long t = x; x = y...
5
#include <bits/stdc++.h> using namespace std; const long long inf = INT_MAX / 2, infl = LLONG_MAX / 2; const int N = ((int)2e5 + 10), K = 10000 - 1, mod = int(1e9) + 7; const double eps = 1e-9; inline void in() { ios_base::sync_with_stdio(0); cin.tie(0); } template <class T> T modexp(T a, T b, T c) { T ans = 1; ...
2
#include <bits/stdc++.h> using namespace std; struct Point { int x, y; }; Point sq[2][5]; bool onSegment(Point p, Point q, Point r) { if (q.x <= max(p.x, r.x) && q.x >= min(p.x, r.x) && q.y <= max(p.y, r.y) && q.y >= min(p.y, r.y)) return true; return false; } int orientation(Point p, Point q, Point r) ...
3
#include <bits/stdc++.h> using namespace std; bool exitInput = false; int ntest = 1, itest = 1; const int dx[4] = {-1, 0, 1, 0}; const int dy[4] = {0, 1, 0, -1}; const long long Mod = 1000000007LL; const int maxn = 500 + 5; const int maxv = 500 + 5; const int maxe = 10000 + 5; int n, a[maxn][maxn]; int x[maxn], vert[ma...
4
#include <bits/stdc++.h> using namespace std; int n, q; int nrt[3]; int forme[200010]; int ti[3][2] = {{1, 2}, {2, 0}, {0, 1}}; set<int> p[3]; int arbi[3][200010]; int nsb(int nr) { return (nr ^ (nr & (nr - 1))); } void update_arb(int tip, int pos, int incr) { for (; pos <= n; pos += nsb(pos)) arbi[tip][pos] += incr;...
4
#include<iostream> #include<algorithm> using namespace std; int main(){ int data[100],cnt=0,n; cin >> n; for(int i=0;i<n;i++) cin >> data[i]; for(int i=0;i<n;i++){ for(int j=n-1;j>i;j--){ if(data[j]<data[j-1]){ swap(data[j],data[j-1]); cnt++; } } } for(int i=0;i<n;i++){ cout << (i!...
0
#include <bits/stdc++.h> using namespace std; int n; int ar[105]; int main() { while (~scanf("%d", &n)) { int sum = 0; for (int i = 0; i < n; i++) { int tmp; scanf("%d", &tmp); sum += tmp; } int ans = 0; for (int i = 1; i <= 5; i++) { if ((sum + i) % (n + 1) != 1) ans++; ...
1
#include <bits/stdc++.h> using namespace std; const string CLASES[] = {"weapon", "armor", "orb"}; const string BICHOS[] = {"gladiator", "sentry", "physician"}; int n, m, clase[104], skill[3][104], sup[104], libre[104]; map<string, int> name, bicho; map<int, string> inv; set<pair<int, string> > monst[3]; int main() { ...
3
#include <bits/stdc++.h> #pragma GCC optimize("O3") const long long MOD = 1e9 + 7; using namespace std; long long n_bits(long long n) { long long x = __builtin_popcount(n); return x; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long t = 1; cin >> t; while (t--) { lo...
1
#include <bits/stdc++.h> #define fi first #define se second #define mkp std::make_pair typedef std::pair <int, int> pii; const int kN = 1e5 + 5; int n, fa[kN]; std::queue <pii> que; std::set <int> E[kN]; std::map <int, int> cnt[kN]; int Find(int x) { return fa[x] == x ? x : fa[x] = Find(fa[x]); } bool Merge(int u, ...
0
#include <iostream> #include <cmath> using namespace std; int n, k; int *w, maxw = 0, sumw = 0; bool load(int p) { int truck = 1; int sum = 0; for (int i = 0; i < n; i++) { if (sum + w[i] > p) { sum = w[i]; truck++; } else { sum += w[i]; } } return truck <= k; } int main() { cin >> n >> k; w =...
0
#include <bits/stdc++.h> using namespace std; vector<int> pset[3]; void initSet(int N, int ind) { pset[ind].assign(N, 0); for (int i = 0; i < N; i++) pset[ind][i] = i; } int findSet(int i, int ind) { return (pset[ind][i] == i) ? i : (pset[ind][i] = findSet(pset[ind][i], ind)); } bool isSameSet(int i, int j, int i...
3
#include <cstdio> #include <cstdint> #include <cassert> #include <cctype> #include <vector> #include <string> #include <algorithm> int parse(const std::string &s, size_t &i) { assert(s[i] == '['); ++i; if (isdigit(s[i])) { int res=s[i]-'0'; while (++i < s.length() && isdigit(s[i])) { res = res*10 +...
0
#include <bits/stdc++.h> using namespace std; int main() { char str[100]; int count0 = 0, count1 = 0, i = 0, flag = 0; cin >> str; while (str[i] != '\0') { if (str[i] == '0') { count0++; count1 = 0; if (count0 == 7) { cout << "YES"; flag = 1; break; } } el...
1
#include <bits/stdc++.h> using namespace std; int main() { int q; cin >> q; while (q--) { int n; cin >> n; string s; cin >> s; string t; cin >> t; unordered_map<char, int> found; unordered_map<char, int> found2; bool match = false; for (int i = 0; i < (int)(n); i++) { ...
6
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long int q, i, j, k, x, y, z, v, u, w, a; cin >> q; map<long long int, long long int> mt; for (i = 0; i < q; i++) { cin >> a; if (a == 1) { cin >> x >> y >> w; v = max(x, y); ...
3
#include <bits/stdc++.h> using namespace std; int n; string in[100005]; struct ha { int last, len, id; } a[1000005]; bool cmp(const ha &aa, const ha &bb) { if (aa.len != bb.len) return aa.len < bb.len; return aa.last < bb.last; } queue<int> lq; queue<int> nq; int m; queue<int> an; queue<int> lins; queue<int> lins...
3
#include <bits/stdc++.h> using namespace std; int main() { int n, flag; string name; string name2[] = {"vaporeon", "jolteon", "flareon", "espeon", "umbreon", "leafeon", "glaceon", "sylveon"}; cin >> n >> name; for (int i = 0; i < 8; i++) { flag = 0; if (n == name2[i].size()) { ...
1
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr); long long int t; cin >> t; while (t--) { string s; cin >> s; if (s.size() == 1) { cout << 0 << endl; continue; } map<char, int> m; int i; int ...
2
#include <bits/stdc++.h> using namespace std; int main() { int a,b,s=0; cin>>a>>b; for(int i=a; i<=b; i++){ if(i%10==i/10000 && (i- (i/10000)*10000)/1000==(i%100-i%10)/10){ s+=1; } } cout<<s; }
0
#include <cstdio> #include <vector> #include <algorithm> using namespace std; inline int calcDiff(int limit, int n, int a, int b){ int result = a - b; if(result < 0){ result += n; } if(result > limit){ result = n - result; } return result; } int main(){ while(true){ int n; scanf("%d", &n); if(n == 0){ bre...
0
#include <bits/stdc++.h> using namespace std; int main() { long long n, m; cin >> n >> m; while (n >= 2 * m || m >= 2 * n) { if (n == 0 || m == 0) { cout << n << " " << m; return 0; } if (n != 0 && m >= 2 * n) { m %= (2 * n); } if (m != 0 && n >= 2 * m) { n %= (2 * m); ...
2
#include <bits/stdc++.h> using namespace std; bool dp[601][601], vis[601][601]; int L[601], R[601], n; bool solve(int l, int r) { if (l > r) return 1; if (vis[l][r]) return dp[l][r]; vis[l][r] = 1; for (int pos = L[l]; pos <= R[l]; pos++) { if ((pos - 1 & 1)) continue; if ((r - l + 1) * 2 < pos) break; ...
5
#include <bits/stdc++.h> using namespace std; int main() { int a; cin >> a; if (a % 5 == 0) { cout << (a / 5); } else cout << (a / 5) + 1; return 0; }
1
#include <bits/stdc++.h> using namespace std; char a[4][128]; int main() { int n; cin >> n; for (int i = 0; i + 1 < n; i += 2) { a[0][i] = a[0][i + 1] = 'a' + i % 4; a[1][i] = a[1][i + 1] = 'b' + i % 4; } if (n & 1) a[0][n - 1] = a[1][n - 1] = 'e'; a[2][0] = a[3][0] = 'f'; for (int i = 1; i + 1 < ...
1
#include<cstdio> #include<string> #include<list> using namespace std; list<int>L; int main() { int N; int d; char command[20]; scanf("%d",&N); for(int i=0;i<N;i++){ scanf("%s",command); if(command[0]=='i'){ scanf("%d",&d); L.push_front(d); } else if(command[6]=='F'){ L.pop_front(); ...
0
#include<iostream> #include<string> using namespace std; int sht[1000][1000]; int main(){ string t;//原文 string b;//呪文 long long int i,j,k,ans=0; for(i=0;i<1000;i++){ for(j=0;j<1000;j++){ sht[i][j]=0; } } cin>>t>>b; //1行目 for(i=0;i<t.size();i++){ if(b[0]==t[i]){ sht[i][0]=1; }else{ sht[i][0]=0; ...
0
#include <bits/stdc++.h> using namespace std; int main() { int a, b, x, y; cin >> a >> b; x = min(a, b); y = ((max(a, b) - x) / 2); cout << x << " " << y; return 0; }
1
#include <bits/stdc++.h> using namespace std; long int n; long int l = 0; vector<long int> ans; vector<pair<long int, long int> > c; void process(long int i) { l++; if (l == n) return; if (c[i].second == c[c[i].first].first || c[i].second == c[c[i].first].second) { ans.push_back(c[i].first); if (l =...
4
#include <bits/stdc++.h> using namespace std; int main() { string s, t; cin >> s >> t; int i = s.length() - 1; while (s[i] == 'z' && i > 0) { s[i] = 'a'; --i; } ++s[i]; if (t > s) { cout << s << endl; } else { cout << "No such string" << endl; } return 0; }
1
#include <bits/stdc++.h> using namespace std; int main() { int k, n, w, money = 0; cin >> k >> n >> w; for (int i = 1; i <= w; i++) { money += k * i; } if (money <= n) { cout << 0; } else { cout << money - n; } return 0; }
1
#include <bits/stdc++.h> using namespace std; long long m, n, k; void nhap() { cin >> n >> m >> k; } bool kt(long long x) { long long s = 0; for (int i = 1; i <= n; i++) s += min(m, x / i); return s >= k; } void xuli() { long long l = 0; long long r = m * n; while (r - l > 1) { long long x = (r + l) / 2...
4
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t; cin >> t; while (t--) { unsigned long long int n, k, b1, b2; cin >> n >> k; string str(n, 'a'); b1 = ceil((sqrt(1 + 8 * k) - 1) / 2); b2 = k - b1 * (b1 - 1) / 2 - 1; str[n...
2
#include <bits/stdc++.h> using namespace std; int t, n, a, b, c, d; int main() { scanf("%d", &t); while (t--) { scanf("%d%d%d%d%d", &n, &a, &b, &c, &d); puts(max(n * (a - b), c - d) <= min(n * (a + b), c + d) ? "Yes" : "No"); } }
1
#include <bits/stdc++.h> using namespace std; struct Move { int x, y, step; string mv; }; int d[8][2] = {-1, 0, 1, 0, 0, -1, 0, 1, -1, -1, -1, 1, 1, 1, 1, -1}; string dirs[8] = {"L\n", "R\n", "D\n", "U\n", "LD\n", "LU\n", "RU\n", "RD\n"}; int main() { int sx, ex, sy, ey; string s, e; cin >> s >> e; sx = s[0...
1
#include <bits/stdc++.h> using namespace std; const double EPS = 1e-9; const double PI = acos(-1); const int INF = (int)1e9 + 7; const int MAXN = (int)2e6 + 7; int a, b, c; int sz; int id[111][111][111]; char first[111][111][111]; vector<int> g[MAXN]; vector<int> g_rev[MAXN]; bool bad[MAXN]; int ans; int common(vector<...
4
#include <bits/stdc++.h> using namespace std; template <class T> int sgn(T x) { return (x > 0) - (x < 0); } template<class T> struct Point { typedef Point P; T x, y; explicit Point(T x_=0, T y_=0) : x(x_), y(y_) {} bool operator<(P p) const { return tie(x,y) < tie(p.x,p.y); } bool operator==(P p) const { return t...
6
#include <bits/stdc++.h> using namespace std; int main() { int d, n; cin >> d >> n; int ans = 0; for (int i = 0; i < n - 1; i++) { int x; cin >> x; ans += d - x; } cout << ans << "\n"; return 0; }
2
#include <bits/stdc++.h> using namespace std; int main() { list<unsigned int> posled; unsigned int n; unsigned int pred_numb = 0; string res = ""; unsigned int line_ = 0; cin >> n; for (unsigned int i = 0; i <= n - 1; i++) { unsigned int k; cin >> k; posled.push_back(k); } for (unsigned in...
3
#include <bits/stdc++.h> using namespace std; int m, tot; long long n; int head[100010], to[300010], net[300010]; long long val[300010], mod = 1000000007; void add(int x, int y, int c) { net[++tot] = head[x], head[x] = tot, to[tot] = y, val[tot] = c; } int deep[100010], son[100010], fa[100010], top[100010]; struct yo...
4
//Grey Area #include<bits/stdc++.h> using namespace std; int n, w; int num[20]; int main(){ while(cin>>n>>w, !(n==0&&w==0)){ int num_d=0, max_h=0; memset(num, 0, sizeof(num)); while(n--){ int tmp; cin>>tmp; num[tmp/w]++; if(max_h<num[tmp/w])max_h=num[tmp/w]; if(num_d<tmp/w+...
0
#include <bits/stdc++.h> using namespace std; void Get(int &T) { char C; bool F = 0; for (; C = getchar(), C < '0' || C > '9';) if (C == '-') F = 1; for (T = C - '0'; C = getchar(), C >= '0' && C <= '9'; T = T * 10 + C - '0') ; F && (T = -T); } pair<int, int> A[1000005]; int N; void Init() { Get(N);...
4
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 9; const long long mod = 1e9 + 7; int sum[N], sum2[N]; void Set(int p, int val) { for (int i = p; i < N; i += ((i) & (-i))) sum[i] += val; } int Get(int p) { int res = 0; for (int i = p; i; i ^= ((i) & (-i))) res += sum[i]; return res; } void Set...
5
#include <bits/stdc++.h> using namespace std; template <typename Arg1> void __f(const char *name, Arg1 &&arg1) { cerr << name << " : " << arg1 << "\n"; } template <typename Arg1, typename... Args> void __f(const char *names, Arg1 &&arg1, Args &&...args) { const char *comma = strchr(names + 1, ','); cerr.write(nam...
3
#include <bits/stdc++.h> using namespace std; int main() { iostream::sync_with_stdio(0); cin.tie(0), cout.tie(0); string t; cin >> t; for (int i = 0; i < t.length(); i++) if (isalpha(t[i])) t[i] = tolower(t[i]); int q; cin >> q; while (q--) { string s; cin >> s; if (s.length() != t.lengt...
1
/** * @author : Luis Miguel Baez <es.luismiguelbaez@gmail.com> * @created : November 24, 2020 */ #include <bits/stdc++.h> using namespace std; #define endl '\n' #define finally(value) {cout << (value) << '\n'; return;} using int64 = int64_t; template<typename T, typename U> T fastpow(T a, U b) { T a...
4
#include <bits/stdc++.h> using namespace std; using ll = long long; ll GetN(ll x) { ll res = sqrt(x / 3); while (3 * res * (res + 1) < x) { res++; } return res; } int dx[] = {-1, -2, -1, 1, 2, 1}; int dy[] = {2, 0, -2, -2, 0, 2}; int main() { ll n; while (cin >> n) { if (n == 0) { printf("0 0\...
5
#include <bits/stdc++.h> using namespace std; signed main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long T = 1; while (T--) { long long n, m; cin >> n >> m; vector<long long> fac[n + 1]; for (long long i = 2; i <= n; i++) { for (long long j = i; j <= n; j += i) fac[j].pu...
2
#include <bits/stdc++.h> using namespace std; const int maxn = 101; struct Data { int id; long long val; void in(int i) { id = i; scanf("%I64d", &val); } bool operator<(struct Data tmp) { if (val != tmp.val) return val < tmp.val; else return id < tmp.id; } }; struct F { Data a[...
6
#include <bits/stdc++.h> using namespace std; int main(int argc, char const *argv[]) { int n; cin>>n; int a[n],b[n]; for (int i = 0; i < n; ++i) { cin>>a[i]; b[i]=a[i]; } sort(b,b+n); for (int i = 0; i < n; ++i) { if (a[i]<=b[n/2-1]) { cout<<b[n/2]<<endl; } else { cout<<b[n/2-1]<<endl; }...
0
#include <bits/stdc++.h> using namespace std; int n, m, nq, a[5010]; bool use[10000010]; void read() { cin >> n >> m; for (int i = 1; i <= n; ++i) { cin >> a[i]; use[a[i]] = true; } } void work() { cin >> nq; for (int i = 1, x; i <= nq; ++i) { cin >> x; int ans = 1 << 30; for (int j = 1; j...
5
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; if (n % 2 == 0) { cout << "4" << " " << n - 4 << endl; } else { cout << "9" << " " << n - 9 << endl; } return 0; }
1
#include <bits/stdc++.h> #define rep(i,n) for (int i = 0; i < (int)n; i++) using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> pi; typedef pair<pi, pi> pp; typedef pair<ll, ll> pl; const double EPS = 1e-9; const ll MOD = 1000000007; const int inf = 1 << 30; const ll linf = ...
0
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long int n; cin >> n; long long int arr[n - 1]; for (long long int i = 0; i < n - 1; i++) { cin >> arr[i]; } long long int a, b; cin >> a >> b; long long int aditi = 0; for (long lo...
1
#include <bits/stdc++.h> using namespace std; bool vis[100001]; int main() { int n; cin >> n; char a[2 * n]; int b[n]; int p = 0; for (int i = 0; i < 2 * n; i++) { char c, k = '+'; cin >> c; if (c == '+') { a[i] = c; } else { a[i] = '-'; cin >> b[p]; p++; } } ...
4
#include <bits/stdc++.h> using namespace std; const int maxn = 1e4 + 10; 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; } retur...
2
#include <bits/stdc++.h> using namespace std; int n, k, a[200009], c[200009]; vector<int> v[200009]; set<pair<int, int> > s; int main() { cin.tie(0); cout.tie(0); ios::sync_with_stdio(0); ios_base::sync_with_stdio(0); cin >> n >> k; for (int i = 0, x; i < n; i++) { cin >> x; x--; a[x]++; } f...
4
#include<bits/stdc++.h> using namespace std; constexpr int64_t MOD = 1e9+7; int main() { int64_t n, m; cin >> n >> m; vector<int64_t> x(n), y(m); for (auto& e : x) cin >> e; for (auto& e : y) cin >> e; int64_t accx = 0, accy = 0; for (int64_t i = 0; i+1 < n; i++) accx = (accx + (x[i+1] - x...
0
#include <bits/stdc++.h> using namespace std; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long n, k, h; cin >> n >> k >> h; long long i, j; pair<long long, pair<long long, long long>> p[n]; for (i = 0; i < n; i++) { cin >> p[i].first; } for (i = 0; i < ...
2
#include <bits/stdc++.h> using namespace std; int main() { string cards; cin >> cards; int cc0 = 0, cc1 = 0, ccq = 0, last0 = -1, last1 = -1; int n = cards.size(); for (int i = 0; i < n; i++) { if (cards[i] == '0') { cc0++; last0 = i; } else if (cards[i] == '1') { cc1++; last1 ...
5
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; (n % 2 == 0) ? cout << "Mahmoud" : cout << "Ehab"; return 0; }
1
#include <iostream> #include <cstdio> #include <cstdlib> #include <vector> #include <algorithm> using namespace std; typedef long long ll; typedef pair<int, ll> pil; #define mp make_pair const ll INF = (ll)1e18; const int N = 200200; int n, m; vector<pil> g[N]; bool used[N]; ll min1, min2; ll val[N]; void read() { ...
0
#include <bits/stdc++.h> using namespace std; int main() { long long x, y, n, i = 0, sum = 0; vector<int> v, vec; cin >> x >> y; while (x--) { i++; cin >> n; int a[n], c = 0; for (int j = 0; j < n; j++) { cin >> a[j]; if (a[j] < y) { c++; } } if (c) { sum+...
1
#include <bits/stdc++.h> using namespace std; long long a[1000005], f[1000005]; int main() { int n; cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; f[0] = 0; for (int i = 1; i <= n; i++) { f[i] = f[i - 1] ^ i; } long long ans = 0; for (int i = 1; i <= n; i++) { if ((n / i) % 2 == 0) { ...
3
#include <bits/stdc++.h> std::string ans[12] = {"x^y^z", "x^z^y", "(x^y)^z", "(x^z)^y", "y^x^z", "y^z^x", "(y^x)^z", "(y^z)^x", "z^x^y", "z^y^x", "(z^x)^y", "(z^y)^x"}; const double EPS = 1e-10; long double best; int id; bool better(long double val) { if (best < val) { ...
4
#include <bits/stdc++.h> using namespace std; void solve() { const int m = 5000 * 1000; vector<int> lp(m + 1); vector<int> pr; for (int i = 2; i <= m; ++i) { if (lp[i] == 0) { pr.push_back(i); lp[i] = i; } for (int j = 0; j < (int)pr.size() && i * pr[j] <= m && pr[j] <= lp[i]; +...
3
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 7; int a[N], b[N], n, m, k; int main() { scanf("%d%d%d", &n, &m, &k); for (int i = 0; i < n; i++) scanf("%d", &a[i]); sort(a, a + n); int ans = 0; for (int i = 0, j = 0; i < n; i++) { b[j] = a[i]; if (i < k - 1 || b[j] - b[j - k + 1] >=...
4