Search is not available for this dataset
name
stringlengths
2
112
description
stringlengths
29
13k
source
int64
1
7
difficulty
int64
0
25
solution
stringlengths
7
983k
language
stringclasses
4 values
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> using namespace std; bool used[200005]; vector<int> r; int n, m, x, y; int u[200005]; bool cycle; vector<int> G[200005]; vector<int> g[200005]; void dfs(int v) { r.push_back(v); used[v] = true; for (int i = 0; i < (int)G[v].size(); ++i) { int to = G[v][i]; if (!used[to]) dfs(to); ...
CPP
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> using namespace std; const int N = 100500; vector<int> g[N], f[N], vc; int us[N], vis[N], cyc; void dfs(int x) { us[x] = 1; for (int i = 0; i < g[x].size(); i++) { int y = g[x][i]; if (us[y] == 1) cyc = 1; if (!us[y]) dfs(y); } us[x] = 2; } void dfsu(int x) { if (vis[x]) r...
CPP
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; int n, m; queue<int> q; int vis[N]; vector<int> no[N]; vector<int> v[N]; int in[N], p[N]; long long ans = 0; int find(int u) { if (u == p[u]) return u; return p[u] = find(p[u]); } void add(int id) { q.empty(); for (int i = 0; i < no[id].size()...
CPP
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
import java.io.IOException; import java.util.HashSet; import java.util.ArrayList; import java.util.InputMismatchException; import java.util.LinkedList; public class MrKitayutasTechnology { public static void main(String[] args) { FasterScanner sc = new FasterScanner(); int N = sc.nextInt(); int M = sc.nextIn...
JAVA
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> #pragma optimization_level 3 #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx") using namespace std; const int N = 3e5 + 5; const long long mod = 1e9 + 7; const long long INF = 1e18; const int INFi = 0x7f7...
CPP
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> #pragma optimization_level 3 #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx") using namespace std; const long double PI = 3.14159265358979323846; const long long MOD = 1e+9 + 7; const long long INF = LLO...
CPP
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 9; struct edge { int to, next; } e[maxn]; int fa[maxn], siz[maxn], n, m, last[maxn], cnt; inline void add(int u, int v) { cnt++; e[cnt].to = v; e[cnt].next = last[u]; last[u] = cnt; } int find(int x) { return x == fa[x] ? x : fa[x] = find(fa...
CPP
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> using namespace std; int n, m; int E[200010], X[200010], H[100010], co = 1; int rd[100010]; inline void addEdge(int x, int y) { E[++co] = y, X[co] = H[x], H[x] = co; E[++co] = x, X[co] = H[y], H[y] = co; ++rd[y]; } bool v[100010]; int g[100010], tt; void dfs(int x) { v[x] = true; g[++...
CPP
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; vector<vector<int> > gu(n); vector<vector<int> > gd(n); vector<int> dg(n); for (int i = 0; i < m; i++) { int a, b; cin >> a >> b; a--; b--; gu[a].push_back(b); gd[a].push_back(b); gd[b].push_back(...
CPP
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> using namespace std; vector<int> adj[100010], radj[100010]; bool vis[100010]; int N, M; vector<int> order; int grp[100010], gz, grp_size[100010]; int wcc_size[100010], wcc_cnt; bool wcc_cyclic[100010]; void dfs(int u) { vis[u] = true; for (const int v : adj[u]) { if (!vis[v]) { df...
CPP
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> using namespace std; int dfsnum = 0, dfn[110000], low[110000], n, m, sta[110000], top = 0, sccnum = 0, scc[110000], sc[110000], insta[110000]; vector<int> g[110000], rg[110000]; bool bo[110000]; void tarjan(int x) { int i, j, k; bo[x] = true; dfn[x] = low[x] = ++dfsnum; sta[++top] =...
CPP
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> using namespace std; vector<vector<int>> edge; int n, m; int parent[100000]; int size[100000]; int visited[100000]; int finished[100000]; int has_loop[100000]; int find_root(int v) { if (parent[v] == -1) { return v; } return parent[v] = find_root(parent[v]); } void merge(int u, int v)...
CPP
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> using namespace std; const int maxn = 2000011, maxm = 2000011; int tot = 0, v[maxm], son[maxm], pre[maxm], now[maxn]; void add(int a, int b) { pre[++tot] = now[a]; now[a] = tot; son[tot] = b; } int fa[maxn], n, m; bool Vis[maxn]; int find(int x) { return fa[x] == x ? x : fa[x] = find(fa[x...
CPP
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> using namespace std; long long read() { long long x = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); } return x * f; } int n, m, ans, cnt...
CPP
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> using namespace std; const int N = 100100; int n, m, ans = 0; int fa[N], u[N], v[N], cnt[N], ord[N], deg[N]; vector<pair<int, int> > edge[N]; vector<int> a[N]; int Root(int x) { return (fa[x] == x) ? x : (fa[x] = Root(fa[x])); } int Get(int x) { for (int i = 1; i <= cnt[x]; i++) { deg[i] ...
CPP
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> using namespace std; struct UF { int par[100005]; void init(int n) { for (int i = 0; i < n; i++) { par[i] = i; } } int find(int x) { if (par[x] == x) return x; return par[x] = find(par[x]); } void unite(int x, int y) { x = find(x); y = find(y); par[...
CPP
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> using namespace std; int n, m; bool used[100001]; int cmp[100001]; vector<int> g[100001], gr[100001]; vector<int> vs; void add(int x, int y) { g[x].push_back(y); gr[y].push_back(x); } vector<int> v[100001]; int ct; void dfs0(int x) { used[x] = 1; v[ct].push_back(x); for (auto y : g[x]...
CPP
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> using namespace std; const int maxn = 1000 * 100 + 10; vector<int> v[3][maxn], e[maxn]; int mark[maxn]; int w[maxn]; vector<int> q; int flag[maxn]; vector<pair<int, int> > edge; inline void dfs(int x, int t, int l) { mark[x] = l; for (int i = 0; i < v[t][x].size(); ++i) { int u = v[t][x...
CPP
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> using namespace std; long long int mod = 1e10; int a[100100], t1[100100], t2[100100], t, f[100100], p[100100], c[100100]; vector<int> v[100100]; int find(int x) { if (x == p[x]) return x; return (p[x] = find(p[x])); } void un(int x1, int x2) { x1 = find(x1); x2 = find(x2); if (x1 != x...
CPP
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> using namespace std; const int mxn = 100 * 1000 + 5; int n, m, ans; vector<int> g[mxn], rg[mxn], topol; bool been[mxn], cycle[mxn]; void topol_sort(int u) { been[u] = true; for (int v : g[u]) if (!been[v]) topol_sort(v); topol.push_back(u); } void scc(int u, bool q) { been[u] = true...
CPP
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.LinkedList; import java.util.StringTokenizer; public class Main { public static void main(Str...
JAVA
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> using namespace std; vector<long long> graph[100005], dg[100005]; long long vis[100005]; long long vis2[100005]; stack<long long> st; long long cycle; void dfs(long long src) { vis[src] = 1; for (long long i = 0; i < graph[src].size(); i++) { long long v = graph[src][i]; if (!vis[v]...
CPP
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:26777216") const int mod = 2e9 + 7; const double eps = 1e-8; const int N = 803; const double pi = acos(-1.0); const long long inf = 1ll << 50; int gcd(int a, int b) { return !b ? a : gcd(b, a % b); } struct union_set { int fa[103]; void i...
CPP
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> using namespace std; const int maxn = 100000 + 10; const int maxm = 100000 + 10; struct edge { int x, y, next; }; edge gr[maxm], gd[maxm]; int tot, n, m, fir[maxn], fid[maxn]; int L[maxn], col[maxn], totcol; int fa[maxn], sumc[maxn]; bool mark[maxn]; void dfs_d(int u) { mark[u] = true; fo...
CPP
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> using namespace std; int N, M; vector<int> V2[101101]; vector<int> V[101101]; vector<int> VV[101101]; int Gp = 0; vector<int> G[101101]; bool Check[101101]; void Make_Group(int now) { Check[now] = true; G[Gp].push_back(now); for (int i = 0; i < V2[now].size(); i++) { int next = V2[now...
CPP
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
//package round286; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.ArrayDeque; import java.util.Arrays; import java.util.BitSet; import java.util.InputMismatchException; import java.util.Queue; public class B { InputStream is; ...
JAVA
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
import java.io.*; import java.util.*; public class CFB { BufferedReader br; PrintWriter out; StringTokenizer st; boolean eof; private static final long MOD = 1000L * 1000L * 1000L + 7; private static final int[] dx = {0, -1, 0, 1}; private static final int[] dy = {1, 0, -1, 0}; private...
JAVA
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> using namespace std; const int MAXN = 100001; int n; vector<int> g[MAXN]; int dfn[MAXN]; int low[MAXN]; int vis[MAXN]; int ins[MAXN]; int ind = 1; stack<int> st; int cyc[MAXN]; int ans1 = 0, ans2 = 0; void dfs(int u) { dfn[u] = low[u] = ind++; st.push(u); ins[u] = vis[u] = 1; for (auto ...
CPP
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> using namespace std; template <class T> void pr(const string& name, T t) { cerr << name << ": " << t << endl; } template <typename T, typename... Types> void pr(const string& names, T t, Types... rest) { auto comma_pos = names.find(','); cerr << names.substr(0, comma_pos) << ": " << t << ...
CPP
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> using namespace std; int head[100005], dfn[100005], low[100005], z[100005], fa[100005], size[100005], si[100005], belong[100005], num[100005]; struct ff { int to, nxt; } e[100005]; bool vis[100005], init[100005], pd; int i, u, v, n, m, fx, fy, ans, cnt, Time, top, tmp; void add(int u, int...
CPP
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> using namespace std; const long long N = 1e5 + 10, MOD = 1e9 + 7; vector<vector<int> > E, F; vector<int> D; vector<bool> V; int dfs(int u) { if (V[u]) return 0; V[u] = 1; int r = 1; for (int v : E[u]) r += dfs(v); for (int v : F[u]) r += dfs(v); return r; } int main() { int n, m; ...
CPP
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> using namespace std; const int N = 100007; int in[N], n, m, st[N], p, visit[N], loop[N], num[N], u[N], v[N]; vector<int> child[N]; int Arr[N], sizee[N]; void initialize_dsu(int a, int b) { for (int i = a; i <= b; ++i) Arr[i] = i, sizee[i] = 1; } int root(int a) { if (a == Arr[a]) return a; ...
CPP
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const double EPS = 0.000000001; const double PI = 3.141592653589793; const long long LLINF = 99999999999999999LL; const int MAX_N = 100005; const int MOD = 1000000007; int N, M, n, cnt, ans; vector<int> v[MAX_N], w[MAX_N], SCC[MAX_N], a; bool cyc...
CPP
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> using namespace std; int Set(int N, int pos) { return N = N | (1 << pos); } int reset(int N, int pos) { return N = N & ~(1 << pos); } bool check(int N, int pos) { return (bool)(N & (1 << pos)); } inline int addmod(int x, int y) { return (x % 1000000007 + y % 1000000007) % 1000000007; } inline...
CPP
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
import static java.lang.Math.*; import static java.lang.Integer.*; import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.ArrayList; public class round286B { static int n; static ArrayList <Integer> [] graph; static ArrayList<Integer> [] graph2; static ArrayList<ArrayList<...
JAVA
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> using namespace std; int n, m; vector<int> G[100005]; int low[100005], num[100005], _time; bool del[100005]; stack<int> st; int tplt_cnt, tplt_size[100005], tplt_type[100005]; int ans; vector<int> Gvh[100005]; int vo_huong_cnt, vo_huong_type[100005], vo_huong_size[100005]; bool visited[100005];...
CPP
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> using namespace std; template <typename T, typename S> inline bool REMIN(T& a, const S& b) { return a > b ? a = b, 1 : 0; } template <typename T, typename S> inline bool REMAX(T& a, const S& b) { return a < b ? a = b, 1 : 0; } int bit(long long x, int pos) { return (x >> pos) & 1; } long lo...
CPP
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> using namespace std; vector<int> graph[100001], rev_graph[100001]; vector<int> order; int visited[100001], comp[100001], comp_size[100001], n, m, a, b, no_of_comp = 0, res; void dfs(int v) { visited[v] = 1; for (int i = 0; i < graph[v].size(); i++) { if (visited[graph[v][i]] != 1) d...
CPP
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> using namespace std; int n, m, x, y; bool circle = true; int vis[100010], vis2[100010]; vector<int> neg[100010], adj[100010]; vector<int> dot; void ndfs(int start) { dot.push_back(start); vis[start] = 1; for (int i = 0; i <= int(neg[start].size()) - 1; i++) { if (!vis[neg[start][i]]) ...
CPP
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
import java.util.*; import java.io.*; public class b { static ArrayList<Integer>[] g; public static void main(String[] args) throws IOException { input.init(System.in); int n = input.nextInt(), m = input.nextInt(); g = new ArrayList[n]; for(int i = 0; i<n; i++) g[i] = new ArrayList<Integer>(); f...
JAVA
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> using namespace std; int n, m; vector<int> G[100005]; vector<int> gt[100005]; vector<int> tab; vector<vector<int> > SCC; bool looped[100005]; bool was[100005]; bool in[100005]; void dfs(int v, bool yes, int id) { was[v] = 1; for (int i = 0; i < G[v].size(); i++) if (!was[G[v][i]]) dfs(G...
CPP
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> using namespace std; vector<int> vis; vector<vector<int> > adj, adj2; long long ans; int wcc[(long long)3e5 + 100], scc[(long long)3e5 + 100], ssz[(long long)3e5 + 100], dfs_low[(long long)3e5 + 100], dfs_num[(long long)3e5 + 100], wccsz[(long long)3e5 + 100]; int scnum; stack<int> s; v...
CPP
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> using namespace std; const int MN = 1e5 + 100; vector<int> v1[MN]; vector<int> v2[MN]; vector<int> group; bool used1[MN]; bool used2[MN]; bool used3[MN]; void findGroup(int x) { used1[x] = 1; group.push_back(x); for (auto y : v1[x]) { if (!used1[y]) { findGroup(y); } } } i...
CPP
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> using namespace std; struct node { vector<int> adj; vector<int> bak; int comp; int indeg; }; int n, m; node g[100005]; int cnt[100005]; int currComp = 1; int ret; vector<int> cMembers[100005]; void DFS(int curr) { g[curr].comp = currComp; cnt[currComp]++; cMembers[currComp].push_b...
CPP
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> int n, m, cnt, head[100100], fa[100100], sccno[100100], lowlink[100100], pre[100100]; int stack[100100], top, scc_cnt, dfs_clock, size[100100], vis[100100], ans; struct data { int to, next; } edge[100100]; inline void Add_Edge(int u, int v) { edge[++cnt] = (data){v, head[u]}; head[u] ...
CPP
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> const long long N = 1000006; using namespace std; const long long MOD = 1000000007LL; template <typename T> T gcd(T a, T b) { if (a == 0) return b; return gcd(b % a, a); } template <typename T> T power(T x, T y, long long m = MOD) { T ans = 1; while (y > 0) { if (y & 1LL) ans = (ans...
CPP
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> using namespace std; int cycle[100010]; int sz[100010]; int parent[100010]; int Rank[100010]; vector<int> v[100010]; int mark[100010], use[100010]; int find(int cur) { if (parent[cur] == cur) return cur; return parent[cur] = find(parent[cur]); } void Union(int x, int y) { int xroot = find...
CPP
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> using namespace std; const int N = 100010; int n, m; vector<long long> g[N]; vector<long long> rg[N]; vector<long long> vs; bool used[N]; int cmp[N], cmpsize[N]; void add_edge(int from, int to) { g[from].push_back(to); rg[to].push_back(from); } void dfs(int v) { used[v] = 1; for (int i ...
CPP
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> const int MAXN = 1e5 + 5; std::vector<int> G[MAXN], GG[MAXN]; int n, m; bool vis[MAXN]; std::vector<int> S; inline void dfs(int v) { vis[v] = 1; S.push_back(v); for (auto x : GG[v]) { if (vis[x]) continue; dfs(x); } for (auto x : G[v]) { if (vis[x]) continue; dfs(x); ...
CPP
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> using namespace std; int M, A[100100], B[100100]; int C, N; int scc[100100]; vector<int> graph[100100], rev[100100], st; int cnt[100100]; void visit0(int p) { scc[p] = -1; for (auto q : graph[p]) if (!scc[q]) visit0(q); st.push_back(p); } void visit1(int p) { scc[p] = C; for (auto...
CPP
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> using namespace std; const long long N = 1e5 + 5; long long n, m; vector<long long> undirG[N]; long long grp = 0; vector<long long> g[N], newg[N], rg[N], todo; long long comp[N], indeg[N], sz[N]; bool vis[N]; set<long long> gr[N]; void dfs(long long u) { vis[u] = 1; for (auto &it : g[u]) { ...
CPP
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 10; int n, m, pre[N], cnt[N], ans = 0, sz[N], du[N], u, v; int find(int x) { return x == pre[x] ? x : pre[x] = find(pre[x]); } vector<int> g[N]; queue<int> q; int main() { cin >> n >> m; for (int i = 1; i <= n; i++) pre[i] = i; for (int i = 1; i <=...
CPP
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #pragma GCC target("sse,sse2,ssse3,sse3,sse4,popcnt,avx,mmx,abm,tune=native") using namespace std; namespace output { void __(short x) { cout << x; } void __(unsigned x) { cout << x; } void __(int x) { cout << x; } void __(long ...
CPP
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> using namespace std; const int MAXN = 100010; vector<int> adj_dir[MAXN], adj[MAXN]; int visited[MAXN]; vector<int> comp; bool has_cycle; void dfs(int u) { visited[u] = 1; comp.push_back(u); for (int i = 0; i < adj[u].size(); i++) { int v = adj[u][i]; if (!visited[v]) { dfs(v...
CPP
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> using namespace std; void setIO() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); } const long double PI = 4 * atan((long double)1); const int INF = 1e9 + 7; const long long _INF = 1e18; vector<vector<int> > med, ed; vector<bool> vs; vector<int> wut, in, low, stc; vector<vector<int> >...
CPP
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> using namespace std; vector<int> v[100001]; int c[100001]; int n; int m; int dsu[100001]; int F(int x) { if (dsu[x] < 0) return x; else { dsu[x] = F(dsu[x]); return dsu[x]; } } void U(int x, int y) { x = F(x); y = F(y); if (x == y) return; if (dsu[x] < dsu[y]) swap(x, ...
CPP
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.IOException; import java.util.HashSet; import java.util.ArrayList; import java.util.LinkedList; import java.util.StringTokenizer; public class MrKitayutasTechnology { public static void main(String[] args) { MyScanner sc = new MyScanner...
JAVA
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> using namespace std; struct Union { int par[100001], val[100001], cnt[100001], loop[100001]; Union() { for (int j = 0; j < 100001; j++) par[j] = j, val[j] = 0, cnt[j] = 1, loop[j] = 0; } int parent(int x) { if (x == par[x]) return x; return par[x] = parent(par[x]); }...
CPP
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> #pragma GCC target("avx,avx2,fma") #pragma GCC optimization("O2") #pragma GCC optimization("unroll-loops") using namespace std; const long long int N = 2e5 + 10, mod = 1e9 + 7, inf = 1e18, dlt = 12251; int poww(int n, int k) { if (!k) return 1; if (k == 1) return n; long long r = poww(n, ...
CPP
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> using namespace std; int n; int edge; int head[300001]; int scc, cnt; bool v[300001]; int s[400001], top; int dfn[400001], low[400001], belong[400001]; int indeg[400001], outdeg[400001], sdeg[400001]; struct map { int s, t; int next; } a[300001]; inline void add(int s, int t) { a[edge].ne...
CPP
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> using namespace std; vector<int> g[100010]; int dfn[100010], v[100010], w[100010], be[100010], fa[100010], low[100010], st[100010], s, h, t, n, m, ti; bool f[100010]; int getf(int x) { if (fa[x] != x) fa[x] = getf(fa[x]); return fa[x]; } void tarjan(int x) { dfn[x] = low[x] = ++h; s...
CPP
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> using namespace std; const int cmx = 1e5 + 5; vector<int> adj[cmx], und[cmx]; int mark1[cmx], mark2[cmx]; vector<int> v; int n, m; bool cycle; void dfs2(int x) { mark2[x] = 1; for (int i = 0; i < adj[x].size(); i++) { int u = adj[x][i]; if (mark2[u] == 1) cycle = true; if (!mark...
CPP
506_B. Mr. Kitayuta's Technology
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
2
8
#include <bits/stdc++.h> using namespace std; bool vis1[100011]; long long int vis2[100011]; vector<long long int> second; vector<long long int> g[100011], gd[100011]; void dfs1(long long int v) { vis1[v] = 1; second.emplace_back(v); for (auto x : g[v]) { if (!vis1[x]) dfs1(x); } } long long int dfs2(long l...
CPP
52_A. 123-sequence
There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. Input The first line contains an integer n (1 ≤ n ≤ 106). The second line contains a sequence o...
2
7
#include <bits/stdc++.h> using namespace std; int arr[4]; int main() { int n, a; scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d", &a); arr[a]++; } return printf("%d\n", n - max(max(arr[1], arr[2]), arr[3])), 0; }
CPP
52_A. 123-sequence
There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. Input The first line contains an integer n (1 ≤ n ≤ 106). The second line contains a sequence o...
2
7
from collections import deque from math import ceil,floor,sqrt,gcd def ii(): return int(input()) def mi(): return map(int,input().split()) def li(): return list(mi()) def si():return input() n=ii() a=li() m={} for i in a: if i not in m: m[i]=1 else: m[i]+=1 b=[] for i in m.keys(): b.append(m...
PYTHON3
52_A. 123-sequence
There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. Input The first line contains an integer n (1 ≤ n ≤ 106). The second line contains a sequence o...
2
7
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin >> n; vector<long long> v(n); long long a1 = 0, a2 = 0, a3 = 0; for (long long i = 0; i < n; i++) { cin >> v[i]; if (v[i] == 1) a1++; else if (v[i] == 2) a2++; else a3++; } long long a = max(a1, m...
CPP
52_A. 123-sequence
There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. Input The first line contains an integer n (1 ≤ n ≤ 106). The second line contains a sequence o...
2
7
import java.io.BufferedReader; import java.io.PrintWriter; import java.io.IOException; import java.io.InputStreamReader; import java.util.*; public class sequence { /** * @param args * @throws IOException * @throws NumberFormatException */ public static void main(String[] args) throws Numb...
JAVA
52_A. 123-sequence
There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. Input The first line contains an integer n (1 ≤ n ≤ 106). The second line contains a sequence o...
2
7
n = int(input()) s = list(map(int, input().split())) print(n-max(s.count(x) for x in [1, 2, 3]))
PYTHON3
52_A. 123-sequence
There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. Input The first line contains an integer n (1 ≤ n ≤ 106). The second line contains a sequence o...
2
7
/* * Hello! You are trying to hack my solution, are you? =) * Don't be afraid of the size, it's just a dump of useful methods like gcd, or n-th Fib number. * And I'm just too lazy to create a new .java for every task. * And if you were successful to hack my solution, please, send me this test as a message or to Abr...
JAVA
52_A. 123-sequence
There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. Input The first line contains an integer n (1 ≤ n ≤ 106). The second line contains a sequence o...
2
7
n=int(input()) a=list(map(int,input().split())) count1,count2,count3=0,0,0 for x in a: if x==1: count1+=1 elif x==2: count2+=1 else: count3+=1 print(min(count1+count2,count2+count3,count3+count1))
PYTHON3
52_A. 123-sequence
There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. Input The first line contains an integer n (1 ≤ n ≤ 106). The second line contains a sequence o...
2
7
a=int(input());b=list(map(int,input().split()));print(a-max(b.count(i) for i in [1,2,3]))
PYTHON3
52_A. 123-sequence
There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. Input The first line contains an integer n (1 ≤ n ≤ 106). The second line contains a sequence o...
2
7
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int arr[n]; int one = 0, two = 0, three = 0; for (int i = 0; i < n; i++) { cin >> arr[i]; int k = arr[i]; if (k == 1) { one++; } else if (k == 2) { two++; } else if (k == 3) { three++; } } ...
CPP
52_A. 123-sequence
There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. Input The first line contains an integer n (1 ≤ n ≤ 106). The second line contains a sequence o...
2
7
n = input() i1 = 0 i2 = 0 i3 = 0 s = list(map(int,input().split())) for j in s: if(j==1): i1 = i1+1 if(j==2): i2 = i2+1 if(j==3): i3=i3+1 if(i2>=i3 and i2>=i1): print(i3+i1) elif(i3>=i2 and i3>=i1): print(i2+i1) elif(i1>=i3 and i1>=i2): print(i3+i2) else: exit()
PYTHON3
52_A. 123-sequence
There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. Input The first line contains an integer n (1 ≤ n ≤ 106). The second line contains a sequence o...
2
7
n=int(raw_input()) l=raw_input() print n-max(l.count('1'),l.count('2'),l.count('3'))
PYTHON
52_A. 123-sequence
There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. Input The first line contains an integer n (1 ≤ n ≤ 106). The second line contains a sequence o...
2
7
n = int(input()) a = list(map(int,input().split())) ones = a.count(1) twos = a.count(2) threes = a.count(3) print(min(ones + twos, ones + threes, twos + threes))
PYTHON3
52_A. 123-sequence
There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. Input The first line contains an integer n (1 ≤ n ≤ 106). The second line contains a sequence o...
2
7
# cook your dish here n=int(input()) l=input().split() c1=0 c2=0 c3=0 #print(l) c1=l.count("1") c2=l.count("2") c3=l.count("3") li=[c1,c2,c3] #print(li) s=max(li) #print(s) print(n-s)
PYTHON3
52_A. 123-sequence
There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. Input The first line contains an integer n (1 ≤ n ≤ 106). The second line contains a sequence o...
2
7
import java.util.*; import java.io.*; public class a { static long mod = 1000000007; static boolean[][] blacks; public static void main(String[] args) throws IOException { input.init(System.in); PrintWriter out = new PrintWriter(new PrintStream(System.out)); //Scanner input = new Scanner(new File("input.txt")...
JAVA
52_A. 123-sequence
There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. Input The first line contains an integer n (1 ≤ n ≤ 106). The second line contains a sequence o...
2
7
n=int(input()) a=list(map(int,input().split())) x=a.count(1) y=a.count(2) z=n-(x+y) print(min(x+y,y+z,z+x))
PYTHON3
52_A. 123-sequence
There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. Input The first line contains an integer n (1 ≤ n ≤ 106). The second line contains a sequence o...
2
7
#include <bits/stdc++.h> using namespace std; int main() { int n, s1 = 0, s2 = 0, s3 = 0; cin >> n; for (int i = 0; i < n; i++) { int a; cin >> a; if (a == 1) s1++; if (a == 2) s2++; if (a == 3) s3++; } int k = max(max(s1, s2), s3); cout << n - k; return 0; }
CPP
52_A. 123-sequence
There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. Input The first line contains an integer n (1 ≤ n ≤ 106). The second line contains a sequence o...
2
7
import java.io.*; import java.util.*; public class A { PrintWriter out; BufferedReader in; StringTokenizer ss; static void dbg(String s){System.out.println(s);}; String next_token() throws IOException {while (!ss.hasMoreTokens())ss=new StringTokenizer(in.readLine()); return ss.nextToken();} Double _...
JAVA
52_A. 123-sequence
There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. Input The first line contains an integer n (1 ≤ n ≤ 106). The second line contains a sequence o...
2
7
#include <bits/stdc++.h> using namespace std; int n, a[1000001]; int cont1, cont2, cont3; int s1, s2, s3; int main() { cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = 1; i <= n; i++) { if (a[i] == 1) cont1++; else if (a[i] == 2) cont2++; else cont3++; } s1 = cont...
CPP
52_A. 123-sequence
There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. Input The first line contains an integer n (1 ≤ n ≤ 106). The second line contains a sequence o...
2
7
i = int(input()) l = list(map(int, input().split())) g = max(l.count(1), l.count(2), l.count(3)) print(i - g)
PYTHON3
52_A. 123-sequence
There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. Input The first line contains an integer n (1 ≤ n ≤ 106). The second line contains a sequence o...
2
7
#include <bits/stdc++.h> using namespace std; int arr[4]; int main() { int n; cin >> n; int inp; for (int i = 0; i < n; i++) { cin >> inp; arr[inp]++; } cout << n - *max_element(arr, arr + 4) << endl; return 0; }
CPP
52_A. 123-sequence
There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. Input The first line contains an integer n (1 ≤ n ≤ 106). The second line contains a sequence o...
2
7
import java.io.*; import java.lang.reflect.Array; import java.util.ArrayList; import java.util.Arrays; import java.util.StringTokenizer; public class A1008 { public static void main(String [] args) /*throws Exception*/ { InputStream inputReader = System.in; OutputStream outputReader = System.out; ...
JAVA
52_A. 123-sequence
There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. Input The first line contains an integer n (1 ≤ n ≤ 106). The second line contains a sequence o...
2
7
def sequence(lst): a = [0, 0, 0] for elem in lst: if elem == 1: a[0] += 1 elif elem == 2: a[1] += 1 else: a[2] += 1 return len(lst) - max(a) n = int(input()) b = [int(i) for i in input().split()] print(sequence(b))
PYTHON3
52_A. 123-sequence
There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. Input The first line contains an integer n (1 ≤ n ≤ 106). The second line contains a sequence o...
2
7
#include <bits/stdc++.h> using namespace std; int main() { int a; int num[3] = {0}; int n; cin >> n; for (int i = 0; i < n; i++) { cin >> a; num[a - 1]++; } printf("%d\n", n - max(num[0], max(num[1], num[2]))); return 0; }
CPP
52_A. 123-sequence
There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. Input The first line contains an integer n (1 ≤ n ≤ 106). The second line contains a sequence o...
2
7
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; int n, I = 0, II = 0, III = 0; cin >> n; for (int i = 0; i < n; i++) { int a; cin >> a; if (a == 1) { I++; } else if (a == 2) { II++; } else { III++; } ...
CPP
52_A. 123-sequence
There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. Input The first line contains an integer n (1 ≤ n ≤ 106). The second line contains a sequence o...
2
7
import java.util.*; import java.io.*; public class Main{ int a; public static void main(String args[]) { Scanner scan=new Scanner(System.in); int t=scan.nextInt(); int a[]=new int[t]; int temp[]=new int[4]; TreeMap<Integer,Integer>T=new TreeMap<>(); for(int i=0;i<t;++i) { a[i]=scan.nextInt(); ...
JAVA
52_A. 123-sequence
There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. Input The first line contains an integer n (1 ≤ n ≤ 106). The second line contains a sequence o...
2
7
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a = 0; int b = 0; int c = 0; for (int i = 0; i < n; i++) { int m; cin >> m; if (m == 1) { a++; } if (m == 2) { b++; } if (m == 3) { c++; } } int max = a; if (b > max) { ...
CPP
52_A. 123-sequence
There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. Input The first line contains an integer n (1 ≤ n ≤ 106). The second line contains a sequence o...
2
7
#include <bits/stdc++.h> using namespace std; inline int read() { char ch = getchar(); if (!(~ch)) return 0; int f = 1; while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } int x = 0; while (ch >= '0' && ch <= '9') { x = (x << 3) + (x << 1) + (ch ^ 48); ch = getchar(); ...
CPP
52_A. 123-sequence
There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. Input The first line contains an integer n (1 ≤ n ≤ 106). The second line contains a sequence o...
2
7
n = int(input()) arr = list(map(int,input().split())) one = arr.count(1) two = arr.count(2) three = arr.count(3) print( min(n-one,n-two,n-three))
PYTHON3
52_A. 123-sequence
There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. Input The first line contains an integer n (1 ≤ n ≤ 106). The second line contains a sequence o...
2
7
#include <bits/stdc++.h> using namespace std; template <typename T> void Print(const vector<T> &v) { for (int i = 0; i + 1 < v.size(); i++) cout << v[i] << " "; cout << v.back() << "\n"; } void solve() { int n; cin >> n; int one, two, three; one = two = three = 0; int temp; for (int i = 0; i < n; i++) {...
CPP
52_A. 123-sequence
There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. Input The first line contains an integer n (1 ≤ n ≤ 106). The second line contains a sequence o...
2
7
#include <bits/stdc++.h> using namespace std; int n, num[4]; int main() { scanf("%d", &n); int i; for (i = 1; i <= n; i++) { int x; scanf("%d", &x); num[x]++; } int maxn = num[1], sum = num[1] + num[2] + num[3]; if (num[2] > maxn) maxn = num[2]; if (num[3] > maxn) maxn = num[3]; printf("%d",...
CPP
52_A. 123-sequence
There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. Input The first line contains an integer n (1 ≤ n ≤ 106). The second line contains a sequence o...
2
7
import java.util.*; public class Solution_1 { public static void main(String[] args) { // solution start :-) Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int a[] = new int[n]; int c1 = 0; int c2 = 0; int c3 = 0; for(int i=0;i<n;i++) { a[i] = sc.nextInt(); if(a[i]==1) c1++; else i...
JAVA
52_A. 123-sequence
There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. Input The first line contains an integer n (1 ≤ n ≤ 106). The second line contains a sequence o...
2
7
n=int(input()) s=[int(i) for i in input().split()] a=s.count(1) b=s.count(2) c=s.count(3) r=min(a+b,a+c,b+c) print(r)
PYTHON3
52_A. 123-sequence
There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. Input The first line contains an integer n (1 ≤ n ≤ 106). The second line contains a sequence o...
2
7
n = int(input()) a = list(map(int, input().split())) ans = n - max([a.count(x) for x in [1, 2, 3]]) print(ans)
PYTHON3
52_A. 123-sequence
There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. Input The first line contains an integer n (1 ≤ n ≤ 106). The second line contains a sequence o...
2
7
import java.util.Scanner; import java.io.*; public class p52a { public static void main(String[] args) throws Exception { p52aa in = new p52aa(System.in); int n = in.nextLong(); int[] all = new int[n]; for (int i = 0; i < all.length; i++) { all[i] = in.nextLong(); ...
JAVA
52_A. 123-sequence
There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. Input The first line contains an integer n (1 ≤ n ≤ 106). The second line contains a sequence o...
2
7
n=int(input()) ar=list(map(int,input().split())) print(n-max([ar.count(i) for i in range(1,4)]))
PYTHON3
52_A. 123-sequence
There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. Input The first line contains an integer n (1 ≤ n ≤ 106). The second line contains a sequence o...
2
7
import java.util.*; import java.io.*; public class testa { public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(br.readLine()); int n = Integer.parseInt(st.nextToken()); st = new StringToken...
JAVA
52_A. 123-sequence
There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. Input The first line contains an integer n (1 ≤ n ≤ 106). The second line contains a sequence o...
2
7
import java.io.*; import java.io.ObjectInputStream.GetField; import java.util.Collection; import java.util.HashMap; import java.util.Iterator; public class _A_ { public static void main(String[] args) throws IOException{ BufferedReader stdin = new BufferedReader (new InputStreamReader(System.in)); ...
JAVA