solution
stringlengths
11
983k
difficulty
int64
0
21
language
stringclasses
2 values
#include <bits/stdc++.h> using namespace std; set<int> trip; set<int> vec[200010]; struct node { int u, v; } mf[200010]; int n, m, k; int ans[200010]; void remove(int x) { set<int>::iterator it; if (vec[x].size() < k && trip.count(x)) { trip.erase(x); for (it = vec[x].begin(); it != vec[x].end(); it++) { int i = *it; vec[i].erase(x); remove(i); } } } int main() { scanf("%d%d%d", &n, &m, &k); for (int i = 1; i <= m; i++) { int u, v; scanf("%d%d", &u, &v); vec[u].insert(v); vec[v].insert(u); mf[i] = node{u, v}; } for (int i = 1; i <= n; i++) trip.insert(i); for (int i = 1; i <= n; i++) remove(i); for (int i = m; i > 0; i--) { ans[i] = trip.size(); int u = mf[i].u, v = mf[i].v; vec[u].erase(v); vec[v].erase(u); remove(u); remove(v); } for (int i = 1; i <= m; i++) { printf("%d\n", ans[i]); } return 0; }
11
CPP
#include <bits/stdc++.h> using namespace std; int n, m, k; int a[200005]; int b[200005]; vector<int> adj[200005]; bool removed[200005]; int nc[200005]; int ans[200005]; set<pair<int, int>> remedges; int main() { ios::sync_with_stdio(false); scanf("%d %d %d", &n, &m, &k); for (int i = 0; i < m; i++) { scanf("%d %d", &a[i], &b[i]); } for (int i = 0; i < m; i++) { adj[a[i]].push_back(b[i]); adj[b[i]].push_back(a[i]); nc[a[i]]++; nc[b[i]]++; } int cans = n; for (int i = 1; i <= n; i++) { if (!removed[i]) { if (nc[i] < k) { removed[i] = true; cans--; queue<int> q; q.push(i); while (!q.empty()) { int cur = q.front(); q.pop(); for (int j = 0; j < adj[cur].size(); j++) { int x = adj[cur][j]; if (!removed[x]) { nc[x]--; if (nc[x] < k) { removed[x] = true; cans--; q.push(x); } } } } } } } ans[m - 1] = cans; for (int cm = m - 1; cm >= 0; cm--) { int ca = a[cm]; int cb = b[cm]; if (!removed[ca] && !removed[cb]) { nc[ca]--; nc[cb]--; remedges.insert(make_pair(ca, cb)); remedges.insert(make_pair(cb, ca)); if (nc[ca] < k) { removed[ca] = true; cans--; queue<int> q; q.push(ca); while (!q.empty()) { int cur = q.front(); q.pop(); for (int j = 0; j < adj[cur].size(); j++) { int x = adj[cur][j]; if (remedges.find(make_pair(cur, x)) != remedges.end()) { continue; } if (!removed[x]) { nc[x]--; if (nc[x] < k) { removed[x] = true; cans--; q.push(x); } } } } } if (nc[cb] < k && !removed[cb]) { removed[cb] = true; cans--; queue<int> q; q.push(cb); while (!q.empty()) { int cur = q.front(); q.pop(); for (int j = 0; j < adj[cur].size(); j++) { int x = adj[cur][j]; if (remedges.find(make_pair(cur, x)) != remedges.end()) { continue; } if (!removed[x]) { nc[x]--; if (nc[x] < k) { removed[x] = true; cans--; q.push(x); } } } } } } if (cm > 0) { ans[cm - 1] = cans; } } for (int i = 0; i < m; i++) { printf("%d\n", ans[i]); } }
11
CPP
#include <bits/stdc++.h> using namespace std; const int M = 1e9 + 7; long long powmod(long long a, long long b, long long mod) { long long res = 1; a %= mod; assert(b >= 0); for (; b; b >>= 1) { if (b & 1) res = res * a % mod; a = a * a % mod; } return res % mod; } const int N = 2e5 + 10; int degree[N]; vector<pair<int, int> > v[N]; bool mark[N]; set<pair<int, int> > s; int main() { memset(mark, 1, sizeof mark); int n, m, k; cin >> n >> m >> k; vector<pair<int, int> > edges(m); for (int i = 0; i < m; ++i) { int a, b; scanf("%d %d", &a, &b); a--, b--; edges[i].first = a; edges[i].second = b; degree[a]++; degree[b]++; v[a].push_back(make_pair(b, i)); v[b].push_back(make_pair(a, i)); } for (int i = 0; i < n; ++i) { s.insert(make_pair(degree[i], i)); } while (!s.empty() && s.begin()->first < k) { int u = s.begin()->second; for (int i = 0; i < v[u].size(); ++i) { int ch = v[u][i].first; if (mark[ch]) { s.erase(make_pair(degree[ch], ch)); degree[ch]--; s.insert(make_pair(degree[ch], ch)); } } s.erase(make_pair(degree[u], u)); mark[u] = 0; } vector<int> ans; for (int i = m - 1; i >= 0; --i) { ans.push_back(s.size()); int a = edges[i].first, b = edges[i].second; if (mark[a] && mark[b]) { s.erase(make_pair(degree[a], a)); degree[a]--; s.insert(make_pair(degree[a], a)); s.erase(make_pair(degree[b], b)); degree[b]--; s.insert(make_pair(degree[b], b)); while (!s.empty() && (s.begin()->first < k)) { int u = s.begin()->second; for (int j = 0; j < v[u].size(); ++j) { int ch = v[u][j].first, id = v[u][j].second; if (id >= i) continue; if (mark[ch]) { s.erase(make_pair(degree[ch], ch)); degree[ch]--; s.insert(make_pair(degree[ch], ch)); } } s.erase(make_pair(degree[u], u)); mark[u] = 0; } } } for (int i = ans.size() - 1; i >= 0; --i) { printf("%d\n", ans[i]); } return 0; }
11
CPP
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; string to_string(string s) { return '"' + s + '"'; } string to_string(char s) { return string(1, s); } string to_string(const char *s) { return to_string((string)s); } string to_string(bool b) { return (b ? "true" : "false"); } template <typename A> string to_string(A); template <typename A, typename B> string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; } template <typename A> string to_string(A v) { bool f = 1; string r = "{"; for (const auto &x : v) { if (!f) r += ", "; f = 0; r += to_string(x); } return r + "}"; } void debug_out() { cout << endl; } template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cout << " " << to_string(H); debug_out(T...); } inline int add(int a, int b) { a += b; if (a >= MOD) a -= MOD; return a; } inline int sub(int a, int b) { a -= b; if (a < 0) a += MOD; return a; } inline int mul(int a, int b) { return (int)((long long)a * b % MOD); } inline int binpow(int a, int b) { int res = 1; while (b > 0) { if (b & 1) res = mul(res, a); a = mul(a, a); b /= 2; } return res; } inline int inv(int a) { return binpow(a, MOD - 2); } int gcd(int a, int b, int &x, int &y) { if (a == 0) { x = 0, y = 1; return b; } int x1, y1; int d = gcd(b % a, a, x1, y1); x = y1 - (b / a) * x1; y = x1; return d; } const int N = 2e5 + 5; int n, m, k, deg[N], ans[N]; vector<pair<int, int> > edges; set<int> g[N]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> m >> k; for (int i = 0; i < m; ++i) { int x, y; cin >> x >> y; edges.push_back({x, y}); deg[x]++; deg[y]++; g[x].insert(y); g[y].insert(x); } int rem = n; queue<int> q; for (int i = 1; i <= n; ++i) if (deg[i] < k) { q.push(i); rem--; } for (int i = m - 1; i >= 0; --i) { while (!q.empty()) { int v = q.front(); q.pop(); for (int u : g[v]) { deg[u]--; g[u].erase(v); if (deg[u] == k - 1) { q.push(u); rem--; } } deg[v] = 0; g[v].clear(); } ans[i] = rem; int x = edges[i].first, y = edges[i].second; if (!g[x].count(y)) continue; deg[x]--; deg[y]--; g[x].erase(y); g[y].erase(x); if (deg[x] == k - 1) { q.push(x); rem--; } if (deg[y] == k - 1) { q.push(y); rem--; } } for (int i = 0; i < m; ++i) cout << ans[i] << "\n"; return 0; }
11
CPP
#include <bits/stdc++.h> using namespace std; const int mxN = 2e5; int n, m, k, eu[mxN], ev[mxN], ans[mxN]; set<int> adj[mxN]; bool a[mxN]; vector<int> tp; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> m >> k; for (int i = 0; i < m; ++i) { cin >> eu[i] >> ev[i], --eu[i], --ev[i]; adj[eu[i]].insert(i); adj[ev[i]].insert(i); a[i] = 1; } for (int i = 0; i < n; ++i) if (adj[i].size() < k) tp.push_back(i); for (int i = m - 1; i >= 0; --i) { ans[i] = i < m - 1 ? ans[i + 1] : n; for (int j = 0; j < tp.size(); ++j) { for (int e : adj[tp[j]]) { adj[eu[e] ^ ev[e] ^ tp[j]].erase(e); if (adj[eu[e] ^ ev[e] ^ tp[j]].size() == k - 1) tp.push_back(eu[e] ^ ev[e] ^ tp[j]); a[e] = 0; } adj[tp[j]].clear(); --ans[i]; } tp.clear(); if (a[i]) { adj[eu[i]].erase(i); if (adj[eu[i]].size() < k) tp.push_back(eu[i]); adj[ev[i]].erase(i); if (adj[ev[i]].size() < k) tp.push_back(ev[i]); a[i] = 0; } } for (int i = 0; i < m; ++i) cout << ans[i] << "\n"; }
11
CPP
#include <bits/stdc++.h> using namespace std; int n, m, d[200005], k, res, vs[200005], ans[200005], pa; map<int, int> cnt[200005]; vector<int> ke[200005]; pair<int, int> a[200005]; void dfs(int u) { d[u]--; res--; vs[u] = 1; for (int v : ke[u]) if (vs[v] == 0) { cnt[u][v] = cnt[v][u] = 1; d[v]--; if (d[v] < k) { d[v]++; dfs(v); } } } int main() { ios_base::sync_with_stdio(0); cin.tie(0), cout.tie(0); cin >> n >> m >> k; res = n; for (int i = 1; i <= m; i++) { cin >> a[i].first >> a[i].second; d[a[i].first]++; d[a[i].second]++; ke[a[i].first].push_back(a[i].second); ke[a[i].second].push_back(a[i].first); } for (int i = 1; i <= n; i++) if (d[i] < k && vs[i] == 0) dfs(i); for (int i = m; i >= 1; i--) { ans[i] = res; ke[a[i].first].pop_back(); ke[a[i].second].pop_back(); if (cnt[a[i].first][a[i].second] == 1) continue; if (vs[a[i].first] == 0) { d[a[i].first]--; if (d[a[i].first] < k) { d[a[i].first]++; dfs(a[i].first); } } if (vs[a[i].second] == 0) { d[a[i].second]--; if (d[a[i].second] < k) { d[a[i].second]++; dfs(a[i].second); } } } for (int i = 1; i <= m; i++) cout << ans[i] << '\n'; }
11
CPP
#include <bits/stdc++.h> using namespace std; const int MAXN = 2e5; set<int> g[MAXN]; int n, m, k; int result = 0; bool removed[MAXN]; int c[MAXN]; int edges[MAXN][2]; queue<int> q; void remove_item(int m) { result--; q.push(m); removed[m] = true; } void clear_queue() { while (!q.empty()) { auto to = q.front(); q.pop(); for (auto u : g[to]) { c[u]--; if (c[u] < k && !removed[u]) remove_item(u); } } } void remove_edge(int a, int b) { g[a].erase(b); g[b].erase(a); } int main() { scanf("%d %d %d", &n, &m, &k); for (int i = 0; i < m; i++) { int a, b; scanf("%d %d", &a, &b); a--; b--; edges[i][0] = a; edges[i][1] = b; g[a].insert(b); g[b].insert(a); c[a]++; c[b]++; } for (int i = 0; i < n; i++) { if (c[i] < k) remove_item(i); } clear_queue(); vector<int> result_reversed; result_reversed.push_back(n + result); for (int i = m - 1; i > 0; i--) { int a = edges[i][0]; int b = edges[i][1]; if (removed[a] || removed[b]) { result_reversed.push_back(n + result); continue; } c[a]--; c[b]--; g[a].erase(b); g[b].erase(a); if (c[a] < k) remove_item(a); if (c[b] < k && !removed[b]) remove_item(b); clear_queue(); result_reversed.push_back(n + result); } for (int i = m - 1; i >= 0; i--) { printf("%d\n", result_reversed[i]); } return 0; }
11
CPP
#include <bits/stdc++.h> using namespace std; int deg[200010]; vector<vector<int> > graph(200010); map<pair<int, int>, int> edgeNum; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int tt = 1; while (tt--) { int n, m, k; cin >> n >> m >> k; int x[m], y[m]; for (int i = 0; i < m; i++) { cin >> x[i] >> y[i]; edgeNum[{x[i], y[i]}] = i; edgeNum[{y[i], x[i]}] = i; graph[x[i]].push_back(y[i]); graph[y[i]].push_back(x[i]); deg[x[i]]++; deg[y[i]]++; } set<pair<int, int> > s; for (int i = 1; i <= n; i++) { s.insert({deg[i], i}); } set<int> removed; while (!s.empty()) { pair<int, int> tmp = *s.begin(); s.erase(tmp); int ver = tmp.second; if (tmp.first >= k) { s.insert(tmp); break; } for (int i = 0; i < graph[ver].size(); i++) { if (removed.count(edgeNum[{graph[ver][i], ver}]) == 1) continue; removed.insert(edgeNum[{graph[ver][i], ver}]); s.erase({deg[graph[ver][i]], graph[ver][i]}); deg[graph[ver][i]]--; s.insert({deg[graph[ver][i]], graph[ver][i]}); } } int ans[m]; for (int ii = m - 1; ii >= 0; --ii) { ans[ii] = s.size(); if (s.count({deg[x[ii]], x[ii]}) == 0 || s.count({deg[y[ii]], y[ii]}) == 0) continue; s.erase({deg[x[ii]], x[ii]}); s.erase({deg[y[ii]], y[ii]}); deg[x[ii]]--; deg[y[ii]]--; removed.insert(edgeNum[{x[ii], y[ii]}]); s.insert({deg[x[ii]], x[ii]}); s.insert({deg[y[ii]], y[ii]}); while (!s.empty() && ((*s.begin()).first) < k) { pair<int, int> tmp = *s.begin(); s.erase(tmp); int ver = tmp.second; if (tmp.first >= k) { s.insert(tmp); break; } for (int i = 0; i < graph[ver].size(); i++) { if (removed.count(edgeNum[{graph[ver][i], ver}]) == 1) continue; s.erase({deg[graph[ver][i]], graph[ver][i]}); removed.insert(edgeNum[{graph[ver][i], ver}]); deg[graph[ver][i]]--; s.insert({deg[graph[ver][i]], graph[ver][i]}); } } } for (int i = 0; i < m; i++) { cout << ans[i] << '\n'; } } }
11
CPP
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 10; const int maxm = 2e5 + 10; const int INF = 0x3f3f3f3f; struct Edge { int v, next, id; } edge[maxm * 2]; int n, m, k, res; int U[maxn], V[maxn], du[maxn], Ans[maxn]; int head[maxn], cnt; queue<int> q; bool vis[maxn]; bool ok[maxn]; void add(int u, int v, int id) { edge[cnt].next = head[u]; edge[cnt].v = v; edge[cnt].id = id; head[u] = cnt++; } void Bfs(int zz) { while (!q.empty()) { int x = q.front(); q.pop(); for (int i = head[x]; i != -1; i = edge[i].next) { int v = edge[i].v; if (vis[edge[i].id]) continue; du[v]--; vis[edge[i].id] = 1; if (du[v] < k) { if (!ok[v]) { q.push(v); Ans[zz]--; ok[v] = 1; } } } } } int main() { while (scanf("%d%d%d", &n, &m, &k) != EOF) { memset(du, 0, sizeof(du)); memset(ok, 0, sizeof(ok)); memset(vis, 0, sizeof(vis)); memset(head, -1, sizeof(head)); cnt = 0; while (!q.empty()) q.pop(); for (int i = 1; i <= m; i++) { scanf("%d%d", U + i, V + i); du[U[i]]++; du[V[i]]++; add(U[i], V[i], i); add(V[i], U[i], i); } for (int i = 1; i <= n; i++) { if (du[i] < k) { q.push(i); ok[i] = 1; } } Bfs(m); Ans[m] = 0; for (int i = 1; i <= n; i++) if (!ok[i]) Ans[m]++; for (int i = m; i >= 1; i--) { Ans[i - 1] = Ans[i]; if (vis[i]) { continue; } du[U[i]]--; du[V[i]]--; vis[i] = 1; if (du[U[i]] < k) { if (!ok[U[i]]) { q.push(U[i]); Ans[i - 1]--; ok[U[i]] = 1; } } if (du[V[i]] < k) { if (!ok[V[i]]) { q.push(V[i]); Ans[i - 1]--; ok[V[i]] = 1; } } Bfs(i - 1); } for (int i = 1; i <= m; i++) printf("%d\n", Ans[i]); } return 0; }
11
CPP
n = int(input()) s = input() k = s.count("8") l = n - k if k <= l//10: print(k) else: while k > l//10: k -= 1 l += 1 print(min(k, l//10))
7
PYTHON3
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const long long int LINF = 0x3f3f3f3f3f3f3f3fll; int t, n, a, b, cnt1, cnt2; string s; int main() { cin >> n; cin >> s; cnt1 = n / 11; for (int i = 0; i < s.size(); i++) { if (s[i] == '8') cnt2++; } cout << min(cnt1, cnt2) << endl; return 0; }
7
CPP
n=int(input()) s=str(input()) p=s.count("8") q=n//11 f=min(p,q) print(f)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { char c; int n, cnt = 0; cin >> n; for (int i = 0; i < n; i++) { cin >> c; if (c == '8') cnt++; } cout << min(cnt, n / 11) << endl; }
7
CPP
a=int(input()) y=input() x=y.count('8') print(min(a//11,x))
7
PYTHON3
n=int(input()) s=input() i=0 nb_8=0 if n>10: while(i<n)&((n-(nb_8*11))>10): if s[i]=='8': nb_8+=1 i+=1 print(nb_8)
7
PYTHON3
n = int(input()) eights = 0 others = 0 for elem in input(): if int(elem) == 8: eights += 1 else: others += 1 answer = 0 while True: if eights == 0: break else: eights -= 1 if others >= 10: others -= 10 answer += 1 else: if eights - (10 - others) >= 0: eights -= (10 - others) others = 0 answer += 1 else: break print(answer)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { int n, count = 0; cin >> n; string s; cin >> s; char c = '8'; for (int i = 0; i < n; i++) { if (s[i] == c) count++; } cout << min(count, n / 11); }
7
CPP
import os import sys import math import heapq from decimal import * from io import BytesIO, IOBase from collections import defaultdict, deque def r(): return int(input()) def rm(): return map(int,input().split()) def rl(): return list(map(int,input().split())) n = r() a = input() num = defaultdict(int) for i in range(n): num[int(a[i])]+=1 if num[8]==0: print(0) else: tot=n-num[8] strips=tot//10 rem=tot%10 if num[8]<=strips: print(num[8]) else: ans=strips num[8]-=strips ans+=num[8]//11 num[8]%=11 ans+=(1 if (rem+num[8]-1)>=10 else 0) print(ans)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { int n, temp = 0, temp1 = 0; cin >> n; string s; cin >> s; for (int i = 0; i < s.length(); i++) { if (s[i] == '8') temp++; } for (int i = 1; i <= temp; i++) { int r = (n - i) / 10; if (r >= i) { temp1++; } else break; } cout << temp1; return 0; }
7
CPP
n=int(input()) a=list(input()) k=a.count('8') s=0 while k>0 and n>10: s+=1 n-=11 k-=1 print(s)
7
PYTHON3
n=int(input()) s=input() a=s.count('8') b=n//11 print(min(a,b))
7
PYTHON3
n=int(input()) s=input() c=s.count('8') x=n//11 if c>=x: print(n//11) elif c < x: print(c) else: print(0)
7
PYTHON3
N=int(input()) s=input() count=0 for i in s: if i=='8': count=count+1 if count !=0: p=N/11 if p>count: print(count) else: print(int(p)) else: print(0)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); int n; cin >> n; int arr[10] = {}; for (int i = 0; i < n; i++) { char c; cin >> c; arr[c - '0']++; } cout << min(n / 11, arr[8]); return 0; }
7
CPP
def phone_numbers(s, n): return min(s.count('8'), n // 11) m = int(input()) t = input() print(phone_numbers(t, m))
7
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { int n, max = 0; string str; cin >> n; cin >> str; for (int i = 0; i < n; i++) { if (str[i] == '8') { max++; } } if (max > n / 11) { max = n / 11; } if (n % 11 != 0 && max > n / 11) { max = n / 11; } cout << max; }
7
CPP
def solution(l1): i=0 while i<len(l1): if l1[i]==8: l1[i]=1 else: l1[i]=0 i+=1 l1.sort() i=0 #print(l1) while len(l1)>10 and 1 in l1: l1.remove(1) for x in range (0,10): l1.remove(l1[0]) i+=1 return i def answer(): a = int(input()) l1 = [int(x) for x in list(input())] print(solution(l1)) answer()
7
PYTHON3
def find_number(cards, n): if n < 11: return 0 max_by_len = n // 11 count_of_eight = 0 for c in cards: if c == '8': count_of_eight += 1 if count_of_eight >= max_by_len: break return count_of_eight def stand_input(): n = int(input()) cards = input() count_of_nums = find_number(cards, n) print(count_of_nums) stand_input()
7
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { int eig = 0, oth = 0, num = 0; int n; cin >> n; char tab[n]; string cards; cin >> cards; for (int i = 0; i < n; i++) tab[i] = cards.at(i); for (int i = 0; i < n; i++) { if (tab[i] == '8') eig++; } oth = n; while ((oth > 10) && (eig > 0)) { num++; eig--; oth -= 11; } cout << num; }
7
CPP
n = int(input()) s = input() print(min(s.count("8"), n//11))
7
PYTHON3
n = int(input()) s = input() count1 = 0 for i in range(n): if s[i] == "8": count1 += 1 if count1 == 0: print(0) else: tam = n//11 if tam <= count1: print(tam) else: print(count1)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; long long powmod(long long a, long long b, long long mod) { if (b == 0 || a == 1) { if (mod == 1) return 0; else return 1; } if (b % 2 == 0) { long long k = powmod(a, b / 2, mod); return (k * k) % mod; } else { long long k = powmod(a, b / 2, mod); return ((k * k) % mod * a) % mod; } } long long gcd(long long a, long long b) { if (a == 0) return b; if (b == 0) return a; if (a > b) return gcd(a % b, b); else return gcd(b % a, a); } int prime(int p) { for (int i = 2; i * i <= p; i++) { if (p % i == 0 && i < p) return i; } return 1; } long long sqr(long long i) { return i * i; } void r(long long &a) { cin >> a; } void r(long long &a, long long &b) { cin >> a >> b; } void r(long long &a, long long &b, long long &c) { cin >> a >> b >> c; } void r(long long &a, long long &b, long long &c, long long &d) { cin >> a >> b >> c >> d; } void r(long long &a, long long &b, long long &c, long long &d, long long &e) { cin >> a >> b >> c >> d >> e; } void r(long long &a, long long &b, long long &c, long long &d, long long &e, long long &f) { cin >> a >> b >> c >> d >> e >> f; } void r(vector<long long> &a) { for (int i = 0; i < a.size(); i++) r(a[i]); } void r(vector<vector<long long>> &a) { for (int i = 0; i < a.size(); i++) r(a[i]); } void w(long long a) { cout << a << "\n"; } void w(char a) { cout << a; } void w(long long a, long long b) { cout << a << " " << b << "\n"; } void w(long long a, long long b, long long c) { cout << a << " " << b << " " << c << "\n"; } void w(long long a, long long b, long long c, long long d) { cout << a << " " << b << " " << c << " " << d << "\n"; } void w(vector<long long> a) { for (int i = 0; i < a.size(); i++) cout << a[i] << " "; cout << "\n"; } void w(vector<vector<long long>> a) { for (int i = 0; i < a.size(); i++) w(a[i]); cout << "\n"; } void r(pair<long long, long long> &a) { cin >> a.first >> a.second; } void w(pair<long long, long long> a) { cout << a.first << " " << a.second << "\n"; } void r(vector<pair<long long, long long>> &a) { for (int i = 0; i < a.size(); i++) r(a); } void w(vector<pair<long long, long long>> a) { for (int i = 0; i < a.size(); i++) w(a[i]); cout << "\n"; } void r(string &a) { cin >> a; } void r(char &a) { cin >> a; } void w(string a) { cout << a << "\n"; } void sort(vector<long long> &a) { sort(a.begin(), a.end()); } void sort(vector<pair<long long, long long>> &a) { sort(a.begin(), a.end()); } void rev(vector<long long> &a) { reverse(a.begin(), a.end()); } void rev(vector<pair<long long, long long>> &a) { reverse(a.begin(), a.end()); } void rev(string &a) { reverse(a.begin(), a.end()); } void solve(int ppppppppp = 1) { long long a; string s; r(a); r(s); long long num = 0; for (int i = 0; i < a; i++) num += s[i] == '8'; w(min(num, a / 11)); return; } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int tututu; tututu = 1; for (int qwerty = 0; qwerty < tututu; qwerty++) solve(); return 0; }
7
CPP
# 1060A => Phone Numbers # https://codeforces.com/problemset/problem/1060/A n = int(input()) digits = input() if digits.count("8") == 0: print(0) else: ans = 0 temp = digits.count("8") for _ in range(temp): if n == 0 or n - 11 < 0: break n -= 11 ans += 1 print(ans)
7
PYTHON3
l=int(input()) s=input() e=s.count('8') m=(l)//11 print(min(e,m))
7
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string s; cin >> s; int cnt = 0, count = 0; for (int i = 0; i < n; i++) { if (s[i] == '8') cnt++; } while (cnt) { n = n - 1; cnt = cnt - 1; if (n / 10 > 0) { count++; n = n - 10; } } cout << count; }
7
CPP
n = int(input()) s = input() c = 0 for i in range(len(s)): if s[i] == "8": c += 1 print(min(c, len(s) // 11))
7
PYTHON3
from math import * n = int(input()) s = [int(i) for i in input()][:n] # print(s) ctr = 0 for i in s: ctr += 1 if i == 8 else 0 print(min(ctr,len(s)//11))
7
PYTHON3
n = int(input()) s = input() a = s.count("8") print(min(n//11,a))
7
PYTHON3
def main(): n = int(input()) s = input() print(solver(s)) def solver(s): eights = s.count('8') return min(len(s) // 11, eights) #print(solver('00000000008')) #print(solver('0011223344556677889988')) #print(solver('31415926535')) main()
7
PYTHON3
a=int(input()) l=input();c=0 m=len(l);flag=0 for i in l: if i=='8': flag=1 c+=1 n=m//11 if flag==1: print(min(n,c)) else: print(0)
7
PYTHON3
length=int(input()) num=input() p=0 for i in range(length): if num[i]=='8': p+=1 #Counts the number of '8' in string if length>=11: if p>=(length//11): print(length//11) else: print(p) #what if there are '8' enuf to create a number? then the no. of numbers created will be p as '8' is required to make a number else: print(0)
7
PYTHON3
#include <bits/stdc++.h> int c[10]; using namespace std; int main() { int n; scanf("%d", &n); int a[n], i; string s; cin >> s; for (i = 0; i < n; i++) { c[s[i] - '0']++; } int ans = 0; for (i = 1; i <= c[8]; i++) { if ((n - i) >= 10 * i) ans = i; } cout << ans; return 0; }
7
CPP
x = int(input()) y = input() a = x // 11 m = [d for d in y] t = m.count("8") if m.count("8") >= a: print(a) elif t <= a and len(y) >= (11* t) and t !=0 : print(t) else: print("0")
7
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { int i, n, cnt = 0, temp; scanf("%d", &n); for (i = 1; i <= n; i++) { scanf("%01d", &temp); if (temp == 8) cnt++; } printf("%d\n", min(cnt, n / 11)); }
7
CPP
#include <bits/stdc++.h> using namespace std; int main() { int n, countOfEight = 0, alongNums = 0; string input; cin >> n >> input; for (int i = 0; i < n; i++) { char cha = input[i]; if (cha == '8') countOfEight++; } alongNums = n - countOfEight; while (alongNums / 10 < countOfEight) { alongNums++; countOfEight--; } if (alongNums < 10 || countOfEight == 0) cout << 0; else { alongNums /= 10; if (alongNums >= countOfEight) cout << countOfEight; else { cout << alongNums; } } }
7
CPP
def main(): d = int(input()) c = input() ec = len([v for v in c if v=='8']) mv = 0 for i in range(ec+1): ne = (len(c) - i) // 10 mv = max(min(ne, i), mv) print(mv) if __name__ == "__main__": main()
7
PYTHON3
n=int(input()) s=input() p=s.count('8') r=n//11 print(min(r,p))
7
PYTHON3
n=int(input()) s=str(input()) k=0 for i in range (n) : if int(s[i])==8 : k=k+1 l=n/11 if (k > 0 and l>0): if (l>k): p=k else : p=l else: p=0 p=int(p) print(p)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; const int MAX_N = 110; int main(int argc, char const *argv[]) { char s[MAX_N]; int n; int eight = 0; cin >> n; for (int i = 0; i < n; ++i) { cin >> s[i]; if (s[i] == '8') eight++; } cout << min(eight, n / 11) << endl; return 0; }
7
CPP
_ = input() N = input() LLLLen = N.count('8') sss = len(N) // 11 print(min(LLLLen, sss))
7
PYTHON3
n=int(input()) s=input() i=s.count('8') if(s.count('8')==0): print(0) else: while(i>=0): if (n-i)>=10*i: print(i) break else: i-=1
7
PYTHON3
n=int(input()) s = input() s.count('8') a = int(n/11) print(min(s.count('8'),a))
7
PYTHON3
n=int(input()) s=list(input()) a=n//11 b=s.count('8') if b>=a: print(a) elif(b<a): print(b)
7
PYTHON3
input() k = input() s = k.count('8') l = len(list(k)) // 11 print(min(s,l))
7
PYTHON3
n = int(input()) s = list(input()) cnt_8 = 0 for item in s: if item == '8': cnt_8 += 1 cnt_num = n//11 if cnt_8 > cnt_num: print(cnt_num) else: print(cnt_8)
7
PYTHON3
input() s = list(input()) if len(s) < 11 or s.count('8') == 0: print(0) exit(0) s.sort() a = [i for i in range(len(s)) if s[i] == '8'] s[a[0]:a[-1]+1] = [] for _ in range(len(a)): s.append('8') cnt = 0 while len(s) >= 11: if s.count('8') == 0: break s.remove('8') s[0:10] = [] cnt += 1 print(cnt)
7
PYTHON3
print(min(int(input()) // 11, input().count("8")))
7
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { long int a, b, m, n, i, j, k, l, cnt = 0, ans, Min; char c[113]; cin >> n; for (i = 1; i <= n; i++) { cin >> c[i]; if (c[i] == '8') { cnt++; } } ans = n / 11; Min = min(ans, cnt); cout << Min << endl; return 0; }
7
CPP
N = int(input()) eight_amount = input().count("8") if N // 11 >= eight_amount: print(eight_amount) else: print(N // 11)
7
PYTHON3
#python is so shitty n=input();s=str(input()) def main(): m=len(s)//11 counter=0 for i in s: if i=="8": counter+=1 print(min(counter,m)) main()
7
PYTHON3
n=int(input()) s=input() m=n//11 c=0 for i in range(n): if(s[i]=='8'): c+=1 print(min(m,c))
7
PYTHON3
n=int(input()) s=input() c=s.count('8') if c==0 or n<11: print(0) exit() num=n-c ans=0 #print(num,c) while(True): if c<1: break if num>=10 and c>=1: ans+=1 num-=10 c-=1 elif num<10: if num+c>=11: ans+=1 c-=(11-num) num=0 else: break elif num+c<11: break print(ans)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; int n; string s; int num[10]; int main() { cin >> n; cin >> s; int c = 0; for (int i = 0; i < n; i++) { num[s[i] - '0']++; if (s[i] != '8') c++; } int ans = 0; while (num[8] >= 0) { ans = max(ans, min(num[8], c / 10)); num[8]--; c++; } cout << ans << endl; return 0; }
7
CPP
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 7; int n; int a[maxn], b[maxn]; inline int read() { int x = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } x = x * 10 + ch - '0'; return x * f; } inline void writ(int x) { if (x < 0) putchar('-'), x = -x; if (x > 9) writ(x / 10); putchar(x % 10 + '0'); } inline void write(int x) { writ(x); putchar('\n'); } inline void writt(int x) { writ(x); putchar(' '); } int main() { int ans = 0; scanf("%d", &n); for (int i = 1; i <= n; ++i) a[i] = read(), ++b[a[i]]; for (int i = 1; i <= b[8]; ++i) { int t = min(i, (n - i) / 10); ans = max(ans, t); } write(ans); return 0; }
7
CPP
n = int(input()) a = input() print(min(a.count('8'), n//11))
7
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; char a[105]; int ans = 0; for (int i = 0; i < n; i++) { cin >> a[i]; if (a[i] == '8') ans++; } if (n < 11 || ans == 0) { cout << 0 << endl; return 0; } if (ans >= n / 11) cout << n / 11 << endl; else cout << ans << endl; }
7
CPP
x=int(input()) y=input() c=y.count('8') d=x//11 print(min(c,d))
7
PYTHON3
n = int(input()) a = list(input()) # print(a) cnt = a.count('8') l = len(a)//11 print(min(cnt,l))
7
PYTHON3
nu=int(input()) number=int(input()) cont=0 for i in (str(number)): if(i=="8"): cont+=1 nu=nu/11 if(cont>nu): print(int(nu)) else: print(int(cont))
7
PYTHON3
n = int(input()) text = input() print(min(n // 11, text.count('8')))
7
PYTHON3
import collections n = int(input()) digits = input() c = collections.Counter(digits) print("{0}\n".format(min(len(digits) // 11, c['8'])))
7
PYTHON3
n = int(input()) chars = input() chars_map = [0] * 10 for char in chars: chars_map[ord(char)-ord('0')] += 1 numbers_count = 0 while chars_map[8]: chars_map[8] -= 1 remaining = 10 for char in [0, 1, 2, 3, 4, 5, 6, 7, 9, 8]: diff = min(remaining, chars_map[char]) remaining -= diff chars_map[char] -= diff if remaining == 0: break if remaining == 0: numbers_count += 1 else: break print(numbers_count)
7
PYTHON3
n=int(input()) s=input() x=int(n/11) y=0 for i in range (0, n): if s[i]=='8': y=y+1 if x>y: pn=y else: pn=x print(pn)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { int n; int n1 = 0, n2 = 0, n3 = 0; string s; cin >> n; cin >> s; for (int i = 0; i < n; i++) { if (s[i] == '8') n1++; } n2 = n / 11; if (n1 == 0 || s.size() < 8) { cout << "0" << endl; return 0; } cout << min(n2, n1) << endl; return 0; }
7
CPP
# Phone Numbers def phone(s): ans = 0 n = len(s) while True: if s.count('8') == 0 or n < 11: return ans s = s.replace('8', '', 1) n -= 11 ans += 1 return ans n = int(input()) s = input() print(phone(s))
7
PYTHON3
n = int(input()) s = input() dg = list(s) ans = 0 n8 = s.count('8') while n8: n -= 11 n8 -= 1 if (n < 0): break ans += 1 print(ans)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f, mod = 1000000007; const long long INF = 0x3f3f3f3f3f3f3f3fLL; const double pi = acosl(-1.), eps = 1e-9; inline int power(int a, int b, int m = mod, int ans = 1) { for (; b; b >>= 1, a = 1LL * a * a % m) if (b & 1) ans = 1LL * ans * a % m; return ans; } int cnt; int main() { int n; cin >> n; for (int i = 0, d; i < n; i++) { scanf("%1d", &d); if (d == 8) cnt++; } int ans = 0; for (int i = 1; i <= cnt; i++) { if ((n - i) >= i * 10) ans = i; } cout << ans << endl; return 0; }
7
CPP
# for testCase in range(int(input())): n = int(input()) s = input() ans = 0 for i in range(s.count('8')+1): ans = max(ans ,min(i ,(n-i)//10)) print(ans)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; int n, x, a; string s; int main() { cin >> n >> s; for (int i = 0; i < n; ++i) { if (s[i] == '8') { x++; } } a = n / 11; cout << min(a, x); }
7
CPP
n=int(input()) a=list(input()) x=0 for i in range(n): if a[i]=='8': x+=1 print(min(x,n//11))
7
PYTHON3
#include <bits/stdc++.h> using namespace std; int n; string s; int main() { cin >> n >> s; int x = count(s.begin(), s.end(), '8'); cout << min(n / 11, x); }
7
CPP
#include <bits/stdc++.h> int main(void) { int n; char s[100], dummy[1]; int number = 0; scanf("%d", &n); gets(dummy); gets(s); if (strlen(s) != n) { printf("%d", number); } else { for (int i = 0; i < n; i++) { if (s[i] == '0' || s[i] == '1' || s[i] == '2' || s[i] == '3' || s[i] == '4' || s[i] == '5' || s[i] == '6' || s[i] == '7' || s[i] == '8' || s[i] == '9') { if (s[i] == '8') { number++; if (number > n / 11) { number--; break; } } } else break; } printf("%d", number); } }
7
CPP
n = int(input()) // 11 s = input() eight = s.count('8') if eight >= n: print ( n ) else: print ( eight )
7
PYTHON3
a=int(input()) b=input() n=a//11 c=0 for i in range(a): if(b[i]=='8'): c+=1 print(min(c,n))
7
PYTHON3
#include <bits/stdc++.h> using namespace std; const long long max3 = 1003; const long long max4 = 10004; const long long max5 = 100005; const long long max6 = 1000006; const long long max7 = 10000007; const long long lg4 = 13; const long long lg5 = 17; const long long lg6 = 20; const long long INF = 2LL * 1000000000; const long long INFLL = 9LL * 1000000000 * 1000000000; const long long M = 1e9 + 7; long long powmod(long long a, long long b, long long mod) { 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 a, long long b) { while (b > 0) { long long t = a % b; a = b, b = t; } return a; } long long lcm(long long a, long long b) { return (a / gcd(a, b)) * b; } long long is_prime(long long n) { if (n <= 1 || n > 3 && (n % 2 == 0 || n % 3 == 0)) return 0; for (long long i = 5, t = 2; i * i <= n; i += t, t = 6 - t) if (n % i == 0) return 0; return 1; } int main() { ios::sync_with_stdio(false); cin.tie(NULL); if (fopen("input.txt", "r")) { freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); } int n; cin >> n; string s; cin >> s; int cnt = 0; for (int i = 0; i < n; i++) if (s[i] == '8') cnt++; int sets = n / 11; cout << min(sets, cnt) << "\n"; return 0; }
7
CPP
# You'll never get ahead of anyone as long as you try to get even with him. Lou Holtz # by : Blue Edge - Create some chaos n=int(input()) s=input() print(min(n//11,s.count("8")))
7
PYTHON3
n=int(input())#n个m=input() m=int(input()) s=map(int,str(m)) i=0 for k in s: if k==8: i=i+1 j=int(n/11) if i>j: print(j) else: print(i)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; string a; cin >> a; int ans = 0; for (int i = 0; i < n; ++i) { ans += (a[i] == '8'); } cout << min(ans, n / 11) << "\n"; }
7
CPP
n = int(input()) s = input() if n<11: print(0) elif '8' not in s: print(0) else: x = s.count('8') y = len(s)//11 print(min(x,y))
7
PYTHON3
# TAIWAN NUMBER ONE!!!!!!!!!!!!!!!!!!! # TAIWAN NUMBER ONE!!!!!!!!!!!!!!!!!!! # TAIWAN NUMBER ONE!!!!!!!!!!!!!!!!!!! from sys import stdin, stdout N = int(input()) s = input() #arr = [int(x) for x in stdin.readline().split()] eight = 0 for i in range(N): if s[i]=='8': eight += 1 non_eight = N-eight #print(eight,non_eight) res = 0 while True: if non_eight>=10 and eight>0: eight -= 1 non_eight -= 10 res += 1 elif eight>0 and non_eight<=9: if eight+non_eight>=11: res += 1 eight -= 1+(10-non_eight) non_eight = 0 else: break else: break print(res)
7
PYTHON3
n = int(input()) s = input() print(min(s.count('8'), len(s)//11))
7
PYTHON3
#include <bits/stdc++.h> using namespace std; void Letters() { int n, m; cin >> n >> m; vector<int64_t> houses; vector<int64_t> letters; vector<int64_t> apart; for (int i = 0; i < n; i++) { int64_t k; cin >> k; houses.push_back(k); } for (int i = 0; i < m; i++) { int64_t k; cin >> k; letters.push_back(k); } apart.push_back(houses[0]); for (int i = 1; i < n; i++) { int64_t k = apart[i - 1]; k += houses[i]; apart.push_back(k); } int l = 0, r = letters.size() - 1; int mid; for (int i = 0; i < letters.size(); i++) { int64_t need_to_found = letters[i]; if (need_to_found <= apart[0]) { cout << "1 " << need_to_found << "\n"; } else { l = 0; r = apart.size() - 1; while (l <= r) { mid = static_cast<int>((l + r) / 2); if (need_to_found < apart[mid]) { r = mid - 1; } else { l = mid + 1; } } if (l + 1 >= apart.size()) { l = apart.size() - 1; } if (need_to_found - apart[l - 1]) { cout << l + 1 << " " << need_to_found - apart[l - 1] << endl; } else { cout << l << " " << houses[l - 1] << endl; } } } } void NewYear() { int n, k; cin >> n >> k; int left = 240 - k; int i; for (i = 1; i <= n; i++) { left -= i * 5; if (left < 0) { cout << i - 1 << endl; return; } if (left == 0) { cout << i << endl; return; } } cout << n << endl; return; } void Frog() { string s; cin >> s; int d = 1, min_d = 1; int flag = 0; for (char c : s) { if (c == 'L') { d++; } if (c == 'R') { flag = 1; if (min_d < d) { min_d = d; } d = 1; } } if (min_d < d) { min_d = d; } cout << min_d << "\n"; return; } void StartTTests() { int t; cin >> t; for (int i = 0; i < t; i++) { Frog(); } } void ZeinInLove() { int n, m, k; cin >> n >> m >> k; vector<int> houses; for (int i = 0; i < n; i++) { int house; cin >> house; houses.push_back(house); } int min_l = 0, min_r = 0; int left_flag = 0, right_flag = 0; for (int i = m - 2; i >= 0; i--) { if (houses[i] <= k and houses[i] != 0) { left_flag = 1; break; } min_l += 10; } for (int i = m; i < n; i++) { if (houses[i] <= k and houses[i] != 0) { right_flag = 1; break; } min_r += 10; } if ((min_l <= min_r and left_flag != 0) or (right_flag == 0)) { cout << min_l + 10 << endl; } else { cout << min_r + 10 << endl; } } void HappyBithdaySaja() { int n; cin >> n; vector<int> price; for (int i = 0; i < n; i++) { int price_one; cin >> price_one; price.push_back(price_one); } sort(price.begin(), price.end()); for (int i = 1; i < n; i += 2) { swap(price[i], price[i - 1]); } if (n % 2) { cout << n / 2 << endl; } else { cout << n / 2 - 1 << endl; } for (int i = 0; i < n; i++) { cout << price[i] << " "; } cout << endl; } void PhoneNumber() { int n; cin >> n; string number; cin >> number; int count_8 = count(number.begin(), number.end(), '8'); int count_number = n / 11; if (count_8 >= count_number) { cout << count_number << endl; } else { cout << count_8 << endl; } } int main() { PhoneNumber(); return 0; }
7
CPP
a = int(input())//11 b = 0 for i in input(): if i == '8': b += 1 print(min(a,b))
7
PYTHON3
#22 #0011223344556677889988 n = int(input()) t = input() c = t.count('8') for x in range(c,-1,-1): if (x + 10 * x) <= n: print (x) break
7
PYTHON3
n = int(input()) s = input() p = s.count('8') m = n // 11 if n < 11 or p == 0: print(0) else: print(min(p,m))
7
PYTHON3
n = int(input()) s = input() if n>=11: t = n//11 c = s.count('8') print(min(c, t)) else: print(0)
7
PYTHON3
n = int(input()) s = input() count8 = 0 if '8' in s and n >= 11: for i in range(n): if '8' == s[i]: count8 += 1 count11 = n//11 if count8 > count11: print(count11) else: print(count8) else: print(0)
7
PYTHON3
n=input() c=input() eig_d=c.count('8') if eig_d==0 or int(n)<8 : print(0) else : print(min(eig_d,int(n) //11))
7
PYTHON3
# cf 1060 A 800 n = int(input()) s = [*map(int, input())] n8 = s.count(8) while n8 > 0: if (len(s) - n8) // 10 >= n8: break n8 -= 1 print(n8)
7
PYTHON3
n=int(input()) ph=str(input()) ct=0 for i in range(0,n): if(ph[i]=='8'): ct+=1 if(n<11): print("0") exit() elif(ct==0): print("0") exit() else: tt=0 tt=n//11 print(min(tt,ct))
7
PYTHON3