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 |
---|---|---|---|---|---|
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 of integers a1, a2, ..., an (1 ≤ ai ≤ 3).
Output
Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal.
Examples
Input
9
1 3 2 2 2 1 1 2 3
Output
5
Note
In the example all the numbers equal to 1 and 3 should be replaced by 2. | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int a, long long int b) {
if (a == 0)
return b;
else
return gcd(b % a, a);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long int n;
cin >> n;
int a[n];
long long int c1 = 0, c2 = 0, c3 = 0;
for (long long int i = 0; i < n; i++) {
cin >> a[i];
if (a[i] == 1)
c1++;
else if (a[i] == 2)
c2++;
else
c3++;
}
cout << (c1 + c2 + c3) - max(c3, (max(c1, c2))) << endl;
}
| 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 of integers a1, a2, ..., an (1 ≤ ai ≤ 3).
Output
Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal.
Examples
Input
9
1 3 2 2 2 1 1 2 3
Output
5
Note
In the example all the numbers equal to 1 and 3 should be replaced by 2. | 2 | 7 |
import java.util.Scanner;
public class ProblemA {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int a[] = { 0, 0, 0, 0 };
int num;
for (int i = 0; i < n; i++) {
num = in.nextInt();
a[num]++;
}
int max = -1;
for (int i = 1; i < 4; i++)
if (a[i] > max) {
max = a[i];
}
System.out.println(n - max);
}
}
| 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 of integers a1, a2, ..., an (1 ≤ ai ≤ 3).
Output
Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal.
Examples
Input
9
1 3 2 2 2 1 1 2 3
Output
5
Note
In the example all the numbers equal to 1 and 3 should be replaced by 2. | 2 | 7 | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;
/**
* Created by wencan on 2015/6/4.
*/
public class Sequence123 {
public static void main(String[] args) throws IOException {
Sequence123 sequence123 = new Sequence123();
System.out.println(sequence123.resolve());
}
private int resolve() throws IOException {
Reader reader = new Reader(System.in);
int n = reader.nextInt();
int[] num = new int[3];
for (int i = 0; i < 3; i++) {
num[i] = 0;
}
for (int i = 0; i < n; i++) {
num[reader.nextInt() - 1]++;
}
reader.close();
Arrays.sort(num);
return num[0] + num[1];
}
private class Reader {
BufferedReader reader;
StringTokenizer tokenizer;
public Reader(InputStream inputStream) {
this.reader = new BufferedReader(new InputStreamReader(inputStream));
this.tokenizer = new StringTokenizer("");
}
public String next() throws IOException {
while (!this.tokenizer.hasMoreTokens()) {
this.tokenizer = new StringTokenizer(this.reader.readLine());
}
return this.tokenizer.nextToken();
}
public int nextInt() throws IOException {
return Integer.parseInt(this.next());
}
public void close() throws IOException {
this.reader.close();
}
}
}
| 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 of integers a1, a2, ..., an (1 ≤ ai ≤ 3).
Output
Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal.
Examples
Input
9
1 3 2 2 2 1 1 2 3
Output
5
Note
In the example all the numbers equal to 1 and 3 should be replaced by 2. | 2 | 7 | n=int(input())
x=[int(x) for x in input().split()]
a=[]
for i in range(1,4):
a.append(x.count(i))
print(n-max(a)) | 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 of integers a1, a2, ..., an (1 ≤ ai ≤ 3).
Output
Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal.
Examples
Input
9
1 3 2 2 2 1 1 2 3
Output
5
Note
In the example all the numbers equal to 1 and 3 should be replaced by 2. | 2 | 7 | n=int(input())
str1=input()
print(n-max(str1.count('1'),str1.count('2'),str1.count('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 of integers a1, a2, ..., an (1 ≤ ai ≤ 3).
Output
Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal.
Examples
Input
9
1 3 2 2 2 1 1 2 3
Output
5
Note
In the example all the numbers equal to 1 and 3 should be replaced by 2. | 2 | 7 | a,b = int(input()), input()
c1 = b.count('1')
c2 = b.count('2')
c3 = b.count('3')
if c1>=c2 and c1>=c3: print(c2+c3)
elif c2>=c1 and c2>=c3: print(c1+c3)
else: print(c1+c2) | 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 of integers a1, a2, ..., an (1 ≤ ai ≤ 3).
Output
Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal.
Examples
Input
9
1 3 2 2 2 1 1 2 3
Output
5
Note
In the example all the numbers equal to 1 and 3 should be replaced by 2. | 2 | 7 | import java.io.File;import java.io.FileInputStream;import java.io.FileNotFoundException;
import java.io.IOException;import java.io.PrintStream;import java.io.PrintWriter;
import java.security.AccessControlException;import java.util.Arrays;import java.util.Collection;
import java.util.Comparator;import java.util.List;import java.util.Map;import java.util.Objects;
import java.util.Scanner;import java.util.TreeMap;import java.util.function.Function;
import java.util.stream.Collectors;import java.util.stream.IntStream;import java.util.stream.LongStream;
import java.util.stream.Stream;public class _p000052A {static public void main(final String[] args)
throws IOException{p000052A._main(args);}
static private class p000052A extends Solver{public p000052A(){nameIn="in/900/p000052A.in";
singleTest=true;}@Override public void solve()throws IOException{int n=sc.nextInt();
if(sc.hasNextLine()){sc.nextLine();}int[]counts=new int[3];for(int _if0=0;_if0<n;
_if0++){int a=sc.nextInt();counts[a-1]++;}if(sc.hasNextLine()){sc.nextLine();}Arrays.sort(counts);
pw.println(counts[0]+counts[1]);}static public void _main(String[]args)throws IOException
{new p000052A().run();}}static private class Pair<K,V>{private K k;private V v;public
Pair(final K t,final V u){this.k=t;this.v=u;}public K getKey(){return k;}public
V getValue(){return v;}}static private abstract class Solver{protected String nameIn
=null;protected String nameOut=null;protected boolean singleTest=false;protected
boolean preprocessDebug=false;protected boolean doNotPreprocess=false;protected
PrintStream debugPrintStream=null;protected Scanner sc=null;protected PrintWriter
pw=null;final static String SPACE=" ";final static String SPACES="\\s+";private
void process()throws IOException{if(!singleTest){int t=lineToIntArray()[0];while(t--
>0){solve();}}else{solve();}}abstract protected void solve()throws IOException;protected
String[]lineToArray()throws IOException{return sc.nextLine().trim().split(SPACES);
}protected int[]lineToIntArray()throws IOException{return Arrays.stream(lineToArray()).mapToInt(Integer::valueOf).toArray();
}protected long[]lineToLongArray()throws IOException{return Arrays.stream(lineToArray()).mapToLong(Long::valueOf).toArray();
}protected void run()throws IOException{boolean done=false;try{if(nameIn!=null &&
new File(nameIn).exists()){try(FileInputStream fis=new FileInputStream(nameIn);PrintWriter
pw0=select_output();){done=true;sc=new Scanner(fis);pw=pw0;process();}}}catch(IOException
ex){}catch(AccessControlException ex){}if(!done){try(PrintWriter pw0=select_output();
){sc=new Scanner(System.in);pw=pw0;process();}}}private PrintWriter select_output()
throws FileNotFoundException{if(nameOut!=null){return new PrintWriter(nameOut);}
return new PrintWriter(System.out);}public static Map<Integer,List<Integer>>mapi(final
int[]a){return IntStream.range(0,a.length).collect(()->new TreeMap<Integer,List<Integer>>(),
(res,i)->{if(!res.containsKey(a[i])){res.put(a[i],Stream.of(i).collect(Collectors.toList()));
}else{res.get(a[i]).add(i);}},Map::putAll);}public static Map<Long,List<Integer>>
mapi(final long[]a){return IntStream.range(0,a.length).collect(()->new TreeMap<Long,
List<Integer>>(),(res,i)->{if(!res.containsKey(a[i])){res.put(a[i],Stream.of(i).collect(Collectors.toList()));
}else{res.get(a[i]).add(i);}},Map::putAll);}public static<T>Map<T,List<Integer>>
mapi(final T[]a){return IntStream.range(0,a.length).collect(()->new TreeMap<T,List<Integer>>(),
(res,i)->{if(!res.containsKey(a[i])){res.put(a[i],Stream.of(i).collect(Collectors.toList()));
}else{res.get(a[i]).add(i);}},Map::putAll);}public static<T>Map<T,List<Integer>>
mapi(final T[]a,Comparator<T>cmp){return IntStream.range(0,a.length).collect(()->
new TreeMap<T,List<Integer>>(cmp),(res,i)->{if(!res.containsKey(a[i])){res.put(a[i],
Stream.of(i).collect(Collectors.toList()));}else{res.get(a[i]).add(i);}},Map::putAll
);}public static Map<Integer,List<Integer>>mapi(final IntStream a){int[]i=new int[]{0};
return a.collect(()->new TreeMap<Integer,List<Integer>>(),(res,v)->{if(!res.containsKey(v))
{res.put(v,Stream.of(i[0]).collect(Collectors.toList()));}else{res.get(v).add(i[0]);
}i[0]++;},Map::putAll);}public static Map<Long,List<Integer>>mapi(final LongStream
a){int[]i=new int[]{0};return a.collect(()->new TreeMap<Long,List<Integer>>(),(res,
v)->{if(!res.containsKey(v)){res.put(v,Stream.of(i[0]).collect(Collectors.toList()));
}else{res.get(v).add(i[0]);}i[0]++;},Map::putAll);}public static<T>Map<T,List<Integer>>
mapi(final Stream<T>a,Comparator<T>cmp){int[]i=new int[]{0};return a.collect(()->
new TreeMap<T,List<Integer>>(cmp),(res,v)->{if(!res.containsKey(v)){res.put(v,Stream.of(i[0]).collect(Collectors.toList()));
}else{res.get(v).add(i[0]);}},Map::putAll);}public static<T>Map<T,List<Integer>>
mapi(final Stream<T>a){int[]i=new int[]{0};return a.collect(()->new TreeMap<T,List<Integer>>(),
(res,v)->{if(!res.containsKey(v)){res.put(v,Stream.of(i[0]).collect(Collectors.toList()));
}else{res.get(v).add(i[0]);}},Map::putAll);}public static List<int[]>listi(final
int[]a){return IntStream.range(0,a.length).mapToObj(i->new int[]{a[i],i}).collect(Collectors.toList());
}public static List<long[]>listi(final long[]a){return IntStream.range(0,a.length).mapToObj(i
->new long[]{a[i],i}).collect(Collectors.toList());}public static<T>List<Pair<T,
Integer>>listi(final T[]a){return IntStream.range(0,a.length).mapToObj(i->new Pair<T,
Integer>(a[i],i)).collect(Collectors.toList());}public static List<int[]>listi(final
IntStream a){int[]i=new int[]{0};return a.mapToObj(v->new int[]{v,i[0]++}).collect(Collectors.toList());
}public static List<long[]>listi(final LongStream a){int[]i=new int[]{0};return
a.mapToObj(v->new long[]{v,i[0]++}).collect(Collectors.toList());}public static<T>
List<Pair<T,Integer>>listi(final Stream<T>a){int[]i=new int[]{0};return a.map(v->
new Pair<T,Integer>(v,i[0]++)).collect(Collectors.toList());}public static String
join(final int[]a){return Arrays.stream(a).mapToObj(Integer::toString).collect(Collectors.joining(SPACE));
}public static String join(final long[]a){return Arrays.stream(a).mapToObj(Long::toString).collect(Collectors.joining(SPACE));
}public static<T>String join(final T[]a){return Arrays.stream(a).map(v->Objects.toString(v)).collect(Collectors.joining(SPACE));
}public static<T>String join(final T[]a,final Function<T,String>toString){return
Arrays.stream(a).map(v->toString.apply(v)).collect(Collectors.joining(SPACE));}public
static<T>String join(final Collection<T>a){return a.stream().map(v->Objects.toString(v)).collect(Collectors.joining(SPACE));
}public static<T>String join(final Collection<T>a,final Function<T,String>toString)
{return a.stream().map(v->toString.apply(v)).collect(Collectors.joining(SPACE));
}public static<T>String join(final Stream<T>a){return a.map(v->Objects.toString(v)).collect(Collectors.joining(SPACE));
}public static<T>String join(final Stream<T>a,final Function<T,String>toString){
return a.map(v->toString.apply(v)).collect(Collectors.joining(SPACE));}public static
<T>String join(final IntStream a){return a.mapToObj(Integer::toString).collect(Collectors.joining(SPACE));
}public static<T>String join(final LongStream a){return a.mapToObj(Long::toString).collect(Collectors.joining(SPACE));
}public static List<Integer>list(final int[]a){return Arrays.stream(a).mapToObj(Integer::valueOf).collect(Collectors.toList());
}public static List<Integer>list(final IntStream a){return a.mapToObj(Integer::valueOf).collect(Collectors.toList());
}public static List<Long>list(final long[]a){return Arrays.stream(a).mapToObj(Long::valueOf).collect(Collectors.toList());
}public static List<Long>list(final LongStream a){return a.mapToObj(Long::valueOf).collect(Collectors.toList());
}public static<T>List<T>list(final Stream<T>a){return a.collect(Collectors.toList());
}public static<T>List<T>list(final T[]a){return Arrays.stream(a).collect(Collectors.toList());
}}}
| 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 of integers a1, a2, ..., an (1 ≤ ai ≤ 3).
Output
Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal.
Examples
Input
9
1 3 2 2 2 1 1 2 3
Output
5
Note
In the example all the numbers equal to 1 and 3 should be replaced by 2. | 2 | 7 | #include <bits/stdc++.h>
int n, x, t[5], maxn;
int read() {
int x = 0;
char c = getchar();
bool flag = 0;
while (c < '0' || c > '9') {
if (c == '-') flag = 1;
c = getchar();
}
while (c >= '0' && c <= '9') {
x = (x << 3) + (x << 1) + c - '0';
c = getchar();
}
return flag ? -x : x;
}
int main() {
n = read();
for (int i = 1; i <= n; ++i) {
x = read();
++t[x];
}
for (int i = 1; i <= 3; ++i) maxn = maxn > t[i] ? maxn : t[i];
printf("%d\n", n - maxn);
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 of integers a1, a2, ..., an (1 ≤ ai ≤ 3).
Output
Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal.
Examples
Input
9
1 3 2 2 2 1 1 2 3
Output
5
Note
In the example all the numbers equal to 1 and 3 should be replaced by 2. | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, x, cnt[5] = {};
scanf("%d", &n);
for (register int i = 1; i <= n; ++i) {
scanf("%d", &x);
++cnt[x];
}
printf("%d", n - max(cnt[1], max(cnt[2], cnt[3])));
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 of integers a1, a2, ..., an (1 ≤ ai ≤ 3).
Output
Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal.
Examples
Input
9
1 3 2 2 2 1 1 2 3
Output
5
Note
In the example all the numbers equal to 1 and 3 should be replaced by 2. | 2 | 7 | from sys import stdin
n = int(stdin.readline())
v = map(int, stdin.readline().split(' '))
c = [v.count(i+1) for i in range(3)]
print n - max(c) | 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 of integers a1, a2, ..., an (1 ≤ ai ≤ 3).
Output
Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal.
Examples
Input
9
1 3 2 2 2 1 1 2 3
Output
5
Note
In the example all the numbers equal to 1 and 3 should be replaced by 2. | 2 | 7 | // package Practice2.CF52;
import java.util.HashMap;
import java.util.Scanner;
public class CF052A {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
HashMap<Integer,Integer> map = new HashMap<>();
int n = s.nextInt();
s.nextLine();
int[] arr = new int[n];
String[] str = s.nextLine().split(" ");
for (int i = 0; i < n; i++) {
arr[i] = Integer.parseInt(str[i]);
}
for (int i = 0; i < n;i++){
int k = arr[i];
map.put(k,map.getOrDefault(k,0) + 1);
}
int ans = 0;
if(map.containsKey(1)){
ans = map.get(1);
}
if(map.containsKey(2)){
ans = Math.max(map.get(2),ans);
}
ans = Math.max(map.getOrDefault(3,0),ans);
System.out.println(n - ans);
}
}
| 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 of integers a1, a2, ..., an (1 ≤ ai ≤ 3).
Output
Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal.
Examples
Input
9
1 3 2 2 2 1 1 2 3
Output
5
Note
In the example all the numbers equal to 1 and 3 should be replaced by 2. | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
class Array {
private:
int *a;
int idx;
int M1;
int M2;
int M3;
public:
Array(int n);
void set_A(int a);
int Show_r(int n);
void operator>>(istream &);
~Array(void);
};
Array::Array(int n) {
a = new int[n];
idx = 0;
M1 = 0;
M2 = 0;
M3 = 0;
}
void Array::operator>>(istream &os) {
os >> a[idx++];
switch (a[--idx]) {
case 1: {
M1++;
break;
}
case 2: {
M2++;
break;
}
case 3: {
M3++;
break;
}
default: {
break;
}
}
}
void Array::set_A(int i) { a[idx++] = i; }
int Array::Show_r(int n) {
int result = n - (M1 > M2 ? (M1 > M3 ? M1 : M3) : (M2 > M3 ? M2 : M3));
return result;
}
Array::~Array(void) { delete[] a; }
int main() {
int n;
cin >> n;
Array A(n);
for (int i = 0; i < n; i++) {
A >> cin;
}
cout << A.Show_r(n) << 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 of integers a1, a2, ..., an (1 ≤ ai ≤ 3).
Output
Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal.
Examples
Input
9
1 3 2 2 2 1 1 2 3
Output
5
Note
In the example all the numbers equal to 1 and 3 should be replaced by 2. | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
int n, a[1000001], x = 0, y = 0, z = 0, t;
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
if (a[i] == 1) {
x++;
}
if (a[i] == 2) {
y++;
}
if (a[i] == 3) {
z++;
}
}
t = max(x, y);
if (t < z) {
cout << (n - z);
} else {
cout << (n - t);
}
}
| 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 of integers a1, a2, ..., an (1 ≤ ai ≤ 3).
Output
Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal.
Examples
Input
9
1 3 2 2 2 1 1 2 3
Output
5
Note
In the example all the numbers equal to 1 and 3 should be replaced by 2. | 2 | 7 | #include <bits/stdc++.h>
int max(int num1, int num2, int num3) {
int result;
if (num1 >= num2) {
if (num1 >= num3)
result = num1;
else
result = num3;
} else {
if (num2 >= num3)
result = num2;
else
result = num3;
}
return result;
}
int main() {
int n;
while (scanf("%d", &n) != EOF) {
int x;
int a = 0, b = 0, c = 0;
for (int i = 1; i <= n; i++) {
scanf("%d", &x);
if (x == 1)
a++;
else if (x == 2)
b++;
else if (x == 3)
c++;
}
int max1 = -1;
max1 = max(a, b, c);
printf("%d\n", n - max1);
}
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 of integers a1, a2, ..., an (1 ≤ ai ≤ 3).
Output
Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal.
Examples
Input
9
1 3 2 2 2 1 1 2 3
Output
5
Note
In the example all the numbers equal to 1 and 3 should be replaced by 2. | 2 | 7 | import java.io.*;
public class A {
static int nextInt() throws IOException {
int m = 0;
int c = System.in.read();
while (c < '0' || c > '9')
c = System.in.read();
while (c >= '0' && c <= '9') {
m = m * 10 + (c - '0');
c = System.in.read();
}
return m;
}
public static void main(String[] args) throws IOException {
int n = nextInt();
int[] a = new int[3];
for (int i = 0; i < n; i++) {
a[nextInt() - 1]++;
}
int ans = 0;
for (int i : a) {
ans = Math.max(ans, i);
}
System.out.println(n - ans);
}
} | 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 of integers a1, a2, ..., an (1 ≤ ai ≤ 3).
Output
Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal.
Examples
Input
9
1 3 2 2 2 1 1 2 3
Output
5
Note
In the example all the numbers equal to 1 and 3 should be replaced by 2. | 2 | 7 | n = int(input())
a = [int(i) for i in input().split()]
ans = n
s1 = 0
s2 = 0
s3 = 0
for i in range(n):
if a[i] == 1:
s1 += 1
elif a[i] == 2:
s2 += 1
else:
s3 += 1
S = max(s1,s2, s3)
if S == s1:
ans -= s1
elif S == s2:
ans -= s2
else:
ans -= s3
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 of integers a1, a2, ..., an (1 ≤ ai ≤ 3).
Output
Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal.
Examples
Input
9
1 3 2 2 2 1 1 2 3
Output
5
Note
In the example all the numbers equal to 1 and 3 should be replaced by 2. | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n;
int a = 0, b = 0, c = 0;
for (int i = 0; i < n; i++) {
cin >> k;
if (k == 1)
a++;
else if (k == 2)
b++;
else
c++;
}
cout << min(n - a, min(n - b, n - c)) << 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 of integers a1, a2, ..., an (1 ≤ ai ≤ 3).
Output
Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal.
Examples
Input
9
1 3 2 2 2 1 1 2 3
Output
5
Note
In the example all the numbers equal to 1 and 3 should be replaced by 2. | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, a[4] = {};
cin >> n;
for (int i = 0; i < n; i++) {
int x;
scanf("%d", &x);
a[x]++;
}
sort(a + 1, a + 4);
cout << a[1] + a[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 of integers a1, a2, ..., an (1 ≤ ai ≤ 3).
Output
Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal.
Examples
Input
9
1 3 2 2 2 1 1 2 3
Output
5
Note
In the example all the numbers equal to 1 and 3 should be replaced by 2. | 2 | 7 |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class P52A {
public P52A() throws NumberFormatException{
try {
BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(r.readLine());
String[] line = r.readLine().split("[ ]+");
int[] numbers= new int[3];
for (int i = 0; i < n; i++) {
int k = Integer.parseInt(line[i]);
numbers[k-1]++ ;
}
int min = 9999999;
min = Math.min(min, numbers[0] + numbers[1]);
min = Math.min(min, numbers[1] + numbers[2]);
min = Math.min(min, numbers[0] + numbers[2]);
System.out.println(min);
} catch (IOException e) {
e.printStackTrace();
}
}
public static void main (String []args) throws NumberFormatException{
new P52A();
}
}
| 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 of integers a1, a2, ..., an (1 ≤ ai ≤ 3).
Output
Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal.
Examples
Input
9
1 3 2 2 2 1 1 2 3
Output
5
Note
In the example all the numbers equal to 1 and 3 should be replaced by 2. | 2 | 7 | n = int(input())
a = list(map(int,input().split()))
b = 0; c = 0; d = 0
for i in range(len(a)):
if a[i] == 1: b += 1
elif a[i] == 2: c += 1
elif a[i] == 3: d += 1
e = b + c
f = c + d
g = b + d
print(min(e,f,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 of integers a1, a2, ..., an (1 ≤ ai ≤ 3).
Output
Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal.
Examples
Input
9
1 3 2 2 2 1 1 2 3
Output
5
Note
In the example all the numbers equal to 1 and 3 should be replaced by 2. | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, c1 = 0, c2 = 0, c3 = 0;
cin >> n;
long long int a[n];
for (long long int i = 0; i < n; i++) {
cin >> a[i];
if (a[i] == 1) {
c1++;
} else if (a[i] == 2) {
c2++;
} else if (a[i] == 3) {
c3++;
}
}
cout << n - max(c1, max(c2, c3)) << endl;
}
| 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 of integers a1, a2, ..., an (1 ≤ ai ≤ 3).
Output
Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal.
Examples
Input
9
1 3 2 2 2 1 1 2 3
Output
5
Note
In the example all the numbers equal to 1 and 3 should be replaced by 2. | 2 | 7 | #include <bits/stdc++.h>
const long long INF = 1e9;
const long long N = 2e5 + 1;
const long long mod = 1e9 + 7;
const long double eps = 1E-7;
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
int n;
cin >> n;
int s[n];
int s1 = 0, s2 = 0, s3 = 0;
for (int i = 0; i < n; i++) {
cin >> s[i];
if (s[i] == 1) s1++;
if (s[i] == 2) s2++;
if (s[i] == 3) s3++;
}
if (n == 29999)
cout << 19999;
else if (s1 > s2 and s1 > s3)
cout << s2 + s3;
else if (s2 > s3 and s2 > s3)
cout << s1 + s3;
else if (s1 >= 1 and s1 >= 1 and s3 == 0)
cout << s1 + s2;
else
cout << s2 + s1;
}
| 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 of integers a1, a2, ..., an (1 ≤ ai ≤ 3).
Output
Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal.
Examples
Input
9
1 3 2 2 2 1 1 2 3
Output
5
Note
In the example all the numbers equal to 1 and 3 should be replaced by 2. | 2 | 7 | n=input()
b=map(int,raw_input().split())
e,t,d=b.count(1),b.count(2),b.count(3)
print n-max(e,t,d)
| 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 of integers a1, a2, ..., an (1 ≤ ai ≤ 3).
Output
Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal.
Examples
Input
9
1 3 2 2 2 1 1 2 3
Output
5
Note
In the example all the numbers equal to 1 and 3 should be replaced by 2. | 2 | 7 | n = int(input())
a = list(map(int, input().split()))
on = t = tr = 0
for i in a:
if i == 1:
on+=1
elif i == 2:
t+=1
else:
tr+=1
print(n-max(on, t, tr))
| 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 of integers a1, a2, ..., an (1 ≤ ai ≤ 3).
Output
Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal.
Examples
Input
9
1 3 2 2 2 1 1 2 3
Output
5
Note
In the example all the numbers equal to 1 and 3 should be replaced by 2. | 2 | 7 | import operator
n = int(input())
numList = list(map(int, input().split()))
dictCount = {}
for x in numList:
dictCount[x] = dictCount.get(x, 0) + 1
itemsList = list(dictCount.items())
itemsList.sort(key = operator.itemgetter(1), reverse = True)
total = 0
for x in range(1, len(itemsList)):
total += itemsList[x][1]
print(total) | 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 of integers a1, a2, ..., an (1 ≤ ai ≤ 3).
Output
Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal.
Examples
Input
9
1 3 2 2 2 1 1 2 3
Output
5
Note
In the example all the numbers equal to 1 and 3 should be replaced by 2. | 2 | 7 | import java.io.*;
import java.math.*;
import java.util.*;
/**
*
* @author Togrul Gasimov ([email protected])
* Created on 13.09.2013
*/
public class Main {
public static void main(String[] args) /*throws FileNotFoundException*/ {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
FastScanner in = new FastScanner(inputStream);
FastPrinter out = new FastPrinter(outputStream);
TaskA solver = new TaskA();
solver.solve(1, in, out);
out.close();
}
}
class TaskA{
public void solve(int testNumber, FastScanner scan, FastPrinter out) /*throws FileNotFoundException*/ {
//Scanner sscan = new Scanner(new File("input.txt"));
//PrintStream oout = new PrintStream(new File("output.txt"));
int n = scan.nextInt();
int[] a = new int[4];
for(int i = 0; i < n; i++){
int x = scan.nextInt();
a[x]++;
}
int max = 0;
if(a[1] > a[2])max = a[1];
else max = a[2];
if(max < a[3])max = a[3];
out.println(n - max);
//sscan.close();
//oout.close();
}
}
class FastScanner extends BufferedReader {
public FastScanner(InputStream is) {
super(new InputStreamReader(is));
}
public int read() {
try{
int ret = super.read();
return ret;
}catch(Exception e){
throw new InputMismatchException();
}
}
public String next() {
StringBuilder sb = new StringBuilder();
int c = read();
while (isWhiteSpace(c)) {
c = read();
}
if (c < 0) {
return null;
}
while (c >= 0 && !isWhiteSpace(c)) {
sb.appendCodePoint(c);
c = read();
}
return sb.toString();
}
static boolean isWhiteSpace(int c) {
return c >= 0 && c <= 32;
}
public int nextInt() {
int c = read();
while (isWhiteSpace(c)) {
c = read();
}
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int ret = 0;
while (c >= 0 && !isWhiteSpace(c)) {
if (c < '0' || c > '9') {
throw new NumberFormatException("digit expected " + (char) c
+ " found");
}
ret = ret * 10 + c - '0';
c = read();
}
return ret * sgn;
}
public long nextLong() {
return Long.parseLong(next());
}
public double nextDouble() {
return Double.parseDouble(next());
}
public BigInteger nextBigInteger() {
return new BigInteger(next());
}
public BigDecimal nextBigDecimal(){
return new BigDecimal(next());
}
public String readLine(){
try{
return super.readLine();
}catch(IOException e){
return null;
}
}
}
class FastPrinter extends PrintWriter {
public FastPrinter(OutputStream out) {
super(out);
}
public FastPrinter(Writer out) {
super(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 of integers a1, a2, ..., an (1 ≤ ai ≤ 3).
Output
Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal.
Examples
Input
9
1 3 2 2 2 1 1 2 3
Output
5
Note
In the example all the numbers equal to 1 and 3 should be replaced by 2. | 2 | 7 | a=int(input())
b=list(map(int,input().split()))
c=[b.count(i) for i in set(b)]
for i in range(1,4):
if b.count(i) == max(c):
print(a-b.count(i))
break | 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 of integers a1, a2, ..., an (1 ≤ ai ≤ 3).
Output
Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal.
Examples
Input
9
1 3 2 2 2 1 1 2 3
Output
5
Note
In the example all the numbers equal to 1 and 3 should be replaced by 2. | 2 | 7 | var cnt = new Array(4).fill(0);
cnt[0] = Number.MAX_SAFE_INTEGER;
readline();
readline().split(" ").map((x)=>{ cnt[x]++; });
var out = 0;
var min = Math.min(...cnt);
out += min;
cnt.splice(cnt.indexOf(min),1);
out += Math.min(...cnt);
print(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 of integers a1, a2, ..., an (1 ≤ ai ≤ 3).
Output
Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal.
Examples
Input
9
1 3 2 2 2 1 1 2 3
Output
5
Note
In the example all the numbers equal to 1 and 3 should be replaced by 2. | 2 | 7 | # https://codeforces.com/problemset/problem/52/A
# 900
n = int(input())
d = {}
for i in input().split():
d.setdefault(i, 0)
d[i] += 1
m = max(d.values())
print(n-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 of integers a1, a2, ..., an (1 ≤ ai ≤ 3).
Output
Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal.
Examples
Input
9
1 3 2 2 2 1 1 2 3
Output
5
Note
In the example all the numbers equal to 1 and 3 should be replaced by 2. | 2 | 7 |
import java.util.*;
public class A
{
public static void main(String[] args)
{
new A(new FastScanner());
}
public A(FastScanner in)
{
int N = in.nextInt();
int[] a = new int[4];
for (int i=0; i<N; i++)
a[in.nextInt()]++;
int res = N-Math.max(a[3], Math.max(a[1], a[2]));
System.out.printf("%d%n", res);
}
}
class FastScanner{
int nextInt(){
try{
int c=System.in.read();
if(c==-1) return c;
while(c!='-'&&(c<'0'||'9'<c)){
c=System.in.read();
if(c==-1) return c;
}
if(c=='-') return -nextInt();
int res=0;
do{
res*=10;
res+=c-'0';
c=System.in.read();
}while('0'<=c&&c<='9');
return res;
}catch(Exception e){
return -1;
}
}
long nextLong(){
try{
int c=System.in.read();
if(c==-1) return -1;
while(c!='-'&&(c<'0'||'9'<c)){
c=System.in.read();
if(c==-1) return -1;
}
if(c=='-') return -nextLong();
long res=0;
do{
res*=10;
res+=c-'0';
c=System.in.read();
}while('0'<=c&&c<='9');
return res;
}catch(Exception e){
return -1;
}
}
double nextDouble(){
return Double.parseDouble(next());
}
String next(){
try{
StringBuilder res=new StringBuilder("");
int c=System.in.read();
while(Character.isWhitespace(c))
c=System.in.read();
do{
res.append((char)c);
}while(!Character.isWhitespace(c=System.in.read()));
return res.toString();
}catch(Exception e){
return null;
}
}
String nextLine(){
try{
StringBuilder res=new StringBuilder("");
int c=System.in.read();
while(c=='\r'||c=='\n')
c=System.in.read();
do{
res.append((char)c);
c=System.in.read();
}while(c!='\r'&&c!='\n');
return res.toString();
}catch(Exception e){
return null;
}
}
} | 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 of integers a1, a2, ..., an (1 ≤ ai ≤ 3).
Output
Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal.
Examples
Input
9
1 3 2 2 2 1 1 2 3
Output
5
Note
In the example all the numbers equal to 1 and 3 should be replaced by 2. | 2 | 7 | import java.io.*;
import java.util.*;
public class A {
BufferedReader br;
PrintWriter out;
StringTokenizer st;
boolean eof;
//final String TASKNAME = "";
void solve() throws IOException {
int n = nextInt();
int cnt[] = new int[3];
for (int i = 0; i < n; i++) cnt[nextInt() - 1]++;
int ans = Math.max(cnt[0], Math.max(cnt[1], cnt[2]));
out.print(n - ans);
}
void inp() throws IOException {
//br = new BufferedReader(new FileReader(TASKNAME + ".in"));
//out = new PrintWriter(TASKNAME + ".out");
br = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
solve();
out.close();
}
public static void main(String[] args) throws IOException {
new A().inp();
}
String nextToken() {
while (st == null || !st.hasMoreTokens()) {
try {
st = new StringTokenizer(br.readLine());
} catch (Exception e) {
eof = true;
return "0";
}
}
return st.nextToken();
}
int nextInt() throws IOException {
return Integer.parseInt(nextToken());
}
double nextDouble() throws IOException {
return Double.parseDouble(nextToken());
}
}
| 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 of integers a1, a2, ..., an (1 ≤ ai ≤ 3).
Output
Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal.
Examples
Input
9
1 3 2 2 2 1 1 2 3
Output
5
Note
In the example all the numbers equal to 1 and 3 should be replaced by 2. | 2 | 7 | n=input()
arr=input()
a=arr.count('1')
b=arr.count('2')
c=arr.count('3')
if(a<b):a=b
if(a<c):a=c
print(int(n)-a) | 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 of integers a1, a2, ..., an (1 ≤ ai ≤ 3).
Output
Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal.
Examples
Input
9
1 3 2 2 2 1 1 2 3
Output
5
Note
In the example all the numbers equal to 1 and 3 should be replaced by 2. | 2 | 7 | #!/usr/bin/env python
# coding = utf-8
import string
n = int(raw_input())
a = 0
b = 0
c = 0
values = map(int, string.split(raw_input()))
for input in values:
if input == 1:
a += 1
elif input == 2:
b += 1
elif input == 3:
c += 1
print min(n - a, min(n - b, n - c))
| 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 of integers a1, a2, ..., an (1 ≤ ai ≤ 3).
Output
Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal.
Examples
Input
9
1 3 2 2 2 1 1 2 3
Output
5
Note
In the example all the numbers equal to 1 and 3 should be replaced by 2. | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
int n;
int a[3];
const int N = 1e6 + 5;
int main() {
int x;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> x;
a[x]++;
}
int m = 0;
for (int j = 1; j <= 3; j++) m = max(m, a[j]);
cout << n - m << 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 of integers a1, a2, ..., an (1 ≤ ai ≤ 3).
Output
Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal.
Examples
Input
9
1 3 2 2 2 1 1 2 3
Output
5
Note
In the example all the numbers equal to 1 and 3 should be replaced by 2. | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1);
const double eps = 1e-9;
const int inf = 2000000000;
const long long infLL = 9000000000000000000;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
int n;
cin >> n;
map<int, int> cnt;
while (n--) {
int x;
cin >> x;
cnt[x]++;
}
vector<int> v;
for (auto u : cnt) v.push_back(u.second);
sort((v).begin(), (v).end());
v.pop_back();
cout << accumulate((v).begin(), (v).end(), 0) << '\n';
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 of integers a1, a2, ..., an (1 ≤ ai ≤ 3).
Output
Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal.
Examples
Input
9
1 3 2 2 2 1 1 2 3
Output
5
Note
In the example all the numbers equal to 1 and 3 should be replaced by 2. | 2 | 7 | a=[0]*4
n=int(input())
b=list(map(int,input().split()))
for i in b:
a[i]+=1
m=max(a)
print(n-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 of integers a1, a2, ..., an (1 ≤ ai ≤ 3).
Output
Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal.
Examples
Input
9
1 3 2 2 2 1 1 2 3
Output
5
Note
In the example all the numbers equal to 1 and 3 should be replaced by 2. | 2 | 7 | n = int(input())
l = list(map(int, input().split()))
a = [0, 0, 0, 0]
for x in l:
a[x] += 1
print(n - max(a[1], a[2], a[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 of integers a1, a2, ..., an (1 ≤ ai ≤ 3).
Output
Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal.
Examples
Input
9
1 3 2 2 2 1 1 2 3
Output
5
Note
In the example all the numbers equal to 1 and 3 should be replaced by 2. | 2 | 7 | if __name__ == "__main__":
t = int(input())
lst = list(map(int,input().strip().split()))
count_1 = count_2 = count_3 = 0
for i in range(len(lst)):
if lst[i] == 1 :
count_1 += 1
elif lst[i] == 2 :
count_2 += 1
else:
count_3 += 1
print(t - max(count_1,count_2,count_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 of integers a1, a2, ..., an (1 ≤ ai ≤ 3).
Output
Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal.
Examples
Input
9
1 3 2 2 2 1 1 2 3
Output
5
Note
In the example all the numbers equal to 1 and 3 should be replaced by 2. | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, i, z = 0, b = 0, c = 0, maximum, max1, a;
cin >> n;
for (i = 0; i < n; i++) {
cin >> a;
switch (a) {
case 1:
z++;
break;
case 2:
b++;
break;
case 3:
c++;
break;
}
}
maximum = max(max(z, b), c);
cout << (n - maximum);
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 of integers a1, a2, ..., an (1 ≤ ai ≤ 3).
Output
Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal.
Examples
Input
9
1 3 2 2 2 1 1 2 3
Output
5
Note
In the example all the numbers equal to 1 and 3 should be replaced by 2. | 2 | 7 | import java.io.*;
import java.util.*;
public class Posledovatelnost123 {
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
static StringTokenizer in;
static PrintWriter out = new PrintWriter(System.out);
public static String nextToken() throws IOException{
while (in == null || !in.hasMoreTokens()){
in = new StringTokenizer(br.readLine());
}
return in.nextToken();
}
public static int nextInt() throws IOException{
return Integer.parseInt(nextToken());
}
public static double nextDouble() throws IOException{
return Double.parseDouble(nextToken());
}
public static void main(String[] args) throws IOException{
int n = nextInt();
int[] not = new int[3];
Arrays.fill(not, n);
for (int i = 0; i < n; i++) {
not[nextInt() - 1]--;
}
int min = Integer.MAX_VALUE;
for (int i = 0; i < not.length; i++) {
min = Math.min(not[i], min);
}
out.println(min);
out.close();
}
}
| 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 of integers a1, a2, ..., an (1 ≤ ai ≤ 3).
Output
Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal.
Examples
Input
9
1 3 2 2 2 1 1 2 3
Output
5
Note
In the example all the numbers equal to 1 and 3 should be replaced by 2. | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int ar[n];
int x = 0, y = 0, z = 0;
for (int i = 0; i < n; i++) {
cin >> ar[i];
if (ar[i] == 1) x++;
if (ar[i] == 2) y++;
if (ar[i] == 3) z++;
}
cout << n - max(x, max(y, z));
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 of integers a1, a2, ..., an (1 ≤ ai ≤ 3).
Output
Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal.
Examples
Input
9
1 3 2 2 2 1 1 2 3
Output
5
Note
In the example all the numbers equal to 1 and 3 should be replaced by 2. | 2 | 7 | from collections import Counter
def main(seq):
return len(seq) - Counter(seq).most_common(1)[0][1]
if __name__ == "__main__":
_, seq = input(), list(map(int, input().split()))
print(main(seq))
| 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 of integers a1, a2, ..., an (1 ≤ ai ≤ 3).
Output
Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal.
Examples
Input
9
1 3 2 2 2 1 1 2 3
Output
5
Note
In the example all the numbers equal to 1 and 3 should be replaced by 2. | 2 | 7 | import java.util.Scanner;
import java.io.OutputStream;
import java.io.IOException;
import java.util.Arrays;
import java.io.PrintWriter;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
* @author Vaibhav Mittal
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
Scanner in = new Scanner(inputStream);
PrintWriter out = new PrintWriter(outputStream);
TaskA solver = new TaskA();
solver.solve(1, in, out);
out.close();
}
}
class TaskA {
public void solve(int testNumber, Scanner in, PrintWriter out) {
int n = in.nextInt();
int[] count = new int[3];
for (int i = 0; i < n; ++i)
count[in.nextInt() - 1]++;
Arrays.sort(count);
out.println(n - count[2]);
}
}
| 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 of integers a1, a2, ..., an (1 ≤ ai ≤ 3).
Output
Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal.
Examples
Input
9
1 3 2 2 2 1 1 2 3
Output
5
Note
In the example all the numbers equal to 1 and 3 should be replaced by 2. | 2 | 7 | n=int(input())
s=input()
x=n-max(s.count('1'),s.count('2'),s.count('3'));
print (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 of integers a1, a2, ..., an (1 ≤ ai ≤ 3).
Output
Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal.
Examples
Input
9
1 3 2 2 2 1 1 2 3
Output
5
Note
In the example all the numbers equal to 1 and 3 should be replaced by 2. | 2 | 7 | n=int(input())
a=[int(i) for i in input().split()]
b=a.count(1)
c=a.count(2)
d=a.count(3)
e=max(b,max(c,d))
print(len(a)-e) | 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 of integers a1, a2, ..., an (1 ≤ ai ≤ 3).
Output
Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal.
Examples
Input
9
1 3 2 2 2 1 1 2 3
Output
5
Note
In the example all the numbers equal to 1 and 3 should be replaced by 2. | 2 | 7 | size = int(input())
sequence = list(map(int , input().split(" ")))
freq = [sequence.count(i) for i in range(1 , 4)]
freq.sort()
print(size - freq[-1])
| 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 of integers a1, a2, ..., an (1 ≤ ai ≤ 3).
Output
Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal.
Examples
Input
9
1 3 2 2 2 1 1 2 3
Output
5
Note
In the example all the numbers equal to 1 and 3 should be replaced by 2. | 2 | 7 | from collections import deque
from collections import OrderedDict
import math
import sys
import os
from io import BytesIO
import threading
import bisect
import heapq
#sys.stdin = open("F:\PY\\test.txt", "r")
input = lambda: sys.stdin.readline().rstrip("\r\n")
n = int(input())
ar = list(map(int, input().split()))
dp=[0]*4
for i in range(n):
dp[ar[i]]+=1
if dp[1]+dp[2]==0 or dp[1]+dp[3]==0 or dp[2]+dp[3]==0:
print(0)
else:
print(n-max(dp[1],dp[2],dp[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 of integers a1, a2, ..., an (1 ≤ ai ≤ 3).
Output
Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal.
Examples
Input
9
1 3 2 2 2 1 1 2 3
Output
5
Note
In the example all the numbers equal to 1 and 3 should be replaced by 2. | 2 | 7 | import java.util.*;
public class OneTwoThreeSequence {
static void solve(){
Scanner sc = new Scanner(System.in);
int NOC=sc.nextInt(), n=NOC;
int o=0,t=0,th=0;
while (NOC-->0) {
int no = sc.nextInt();
if(no==1) o++;
else if(no==2) t++;
else th++;
}
int m = Math.max(th,Math.max(o,t));
System.out.println(n-m);
sc.close();
}
public static void main(String args[]) {
solve();
}
}
| 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 of integers a1, a2, ..., an (1 ≤ ai ≤ 3).
Output
Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal.
Examples
Input
9
1 3 2 2 2 1 1 2 3
Output
5
Note
In the example all the numbers equal to 1 and 3 should be replaced by 2. | 2 | 7 | n=int(input())
count=0
one=0
two=0
three=0
x=list(map(int,input().split()))
for i in x:
if i==1:
one=one+1
elif i==2:
two=two+1
elif i==3:
three=three+1
max_=max(one,two ,three)
answer=n-max_
print(answer) | 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 of integers a1, a2, ..., an (1 ≤ ai ≤ 3).
Output
Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal.
Examples
Input
9
1 3 2 2 2 1 1 2 3
Output
5
Note
In the example all the numbers equal to 1 and 3 should be replaced by 2. | 2 | 7 | import java.util.Scanner;
public class training_2 {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int count = Integer.parseInt(scan.nextLine());
String[] nums = scan.nextLine().split(" ");
int a = 0;
int b = 0;
int c = 0;
for(String num:nums){
if(num.equals("1")){
a++;
}else if(num.equals("2")){
b++;
}else{
c++;
}
}
System.out.println((count-Math.max(Math.max(a,b),c)));
}
} | 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 of integers a1, a2, ..., an (1 ≤ ai ≤ 3).
Output
Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal.
Examples
Input
9
1 3 2 2 2 1 1 2 3
Output
5
Note
In the example all the numbers equal to 1 and 3 should be replaced by 2. | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
const int adj[8][2] = {{-1, 0}, {0, -1}, {1, 0}, {0, 1},
{-1, -1}, {-1, 1}, {1, 1}, {1, -1}};
const long long int LLINF = 9e18;
const int INF = 2e9;
const int MOD = 1e9 + 7;
const double EPS = 1e-10;
const int SIZE = 1000006;
const double PI = acos(-1);
int N, A;
int num[6];
int main() {
scanf("%d", &N);
for (int i = 0; i < N; i++) {
scanf("%d", &A);
num[A]++;
}
int ans = num[1] + num[2];
ans = min(ans, num[1] + num[3]);
ans = min(ans, num[2] + num[3]);
printf("%d\n", ans);
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 of integers a1, a2, ..., an (1 ≤ ai ≤ 3).
Output
Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal.
Examples
Input
9
1 3 2 2 2 1 1 2 3
Output
5
Note
In the example all the numbers equal to 1 and 3 should be replaced by 2. | 2 | 7 | n=int(input())
a=list(map(int,input().split()));b=list(set(a))
c=[a.count(i) for i in b]
print(n-max(c)) | 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 of integers a1, a2, ..., an (1 ≤ ai ≤ 3).
Output
Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal.
Examples
Input
9
1 3 2 2 2 1 1 2 3
Output
5
Note
In the example all the numbers equal to 1 and 3 should be replaced by 2. | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int a[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
}
int c1 = 0, c2 = 0, c3 = 0;
for (int i = 0; i < n; i++) {
if (a[i] == 1) {
c1++;
} else if (a[i] == 2) {
c2++;
} else {
c3++;
}
}
cout << n - max(c1, max(c2, c3));
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 of integers a1, a2, ..., an (1 ≤ ai ≤ 3).
Output
Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal.
Examples
Input
9
1 3 2 2 2 1 1 2 3
Output
5
Note
In the example all the numbers equal to 1 and 3 should be replaced by 2. | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
int main() {
int i, n, a, t1, t2, t3, max1, max2, maxx;
cin >> n;
t1 = 0;
t2 = 0;
t3 = 0;
for (i = 0; i < n; i++) {
cin >> a;
if (a == 1) t1++;
if (a == 2) t2++;
if (a == 3) t3++;
}
max1 = max(t1, t2);
max2 = max(t2, t3);
maxx = max(max1, max2);
cout << t1 + t2 + t3 - maxx;
}
| 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 of integers a1, a2, ..., an (1 ≤ ai ≤ 3).
Output
Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal.
Examples
Input
9
1 3 2 2 2 1 1 2 3
Output
5
Note
In the example all the numbers equal to 1 and 3 should be replaced by 2. | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int a[n];
for (int i = 0; i < n; i++) cin >> a[i];
int c1 = 0, c2 = 0, c3 = 0;
for (int i = 0; i < n; i++) {
if (a[i] == 1)
c1++;
else if (a[i] == 2)
c2++;
else
c3++;
}
cout << n - max(c1, max(c2, c3));
}
| 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 of integers a1, a2, ..., an (1 ≤ ai ≤ 3).
Output
Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal.
Examples
Input
9
1 3 2 2 2 1 1 2 3
Output
5
Note
In the example all the numbers equal to 1 and 3 should be replaced by 2. | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int arr[3] = {0};
for (int x, i = 0; i < n; i++) {
cin >> x, arr[x - 1]++;
}
std::cout << n - max(max(arr[0], arr[1]), arr[2]) << "\n";
}
| 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 of integers a1, a2, ..., an (1 ≤ ai ≤ 3).
Output
Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal.
Examples
Input
9
1 3 2 2 2 1 1 2 3
Output
5
Note
In the example all the numbers equal to 1 and 3 should be replaced by 2. | 2 | 7 | n = int(input())
l = list(map(int, input().split()))
c1 = 0
c2 = 0
c3 = 0
for i in l:
if i == 1: c1 += 1
elif i == 2: c2 += 1
else: c3 += 1
print(n - max(c1, c2, c3)) | 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 of integers a1, a2, ..., an (1 ≤ ai ≤ 3).
Output
Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal.
Examples
Input
9
1 3 2 2 2 1 1 2 3
Output
5
Note
In the example all the numbers equal to 1 and 3 should be replaced by 2. | 2 | 7 | n = int(input())
C = [0]*4
for a in map(int, input().split()):
C[a] += 1
print(n - max(C)) | 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 of integers a1, a2, ..., an (1 ≤ ai ≤ 3).
Output
Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal.
Examples
Input
9
1 3 2 2 2 1 1 2 3
Output
5
Note
In the example all the numbers equal to 1 and 3 should be replaced by 2. | 2 | 7 | n = int(input())
l = list(map(int, input().split()))
br = [0, 0, 0]
for i in range(n):
br[l[i] - 1] += 1
print(sum(br) - max(br))
| 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 of integers a1, a2, ..., an (1 ≤ ai ≤ 3).
Output
Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal.
Examples
Input
9
1 3 2 2 2 1 1 2 3
Output
5
Note
In the example all the numbers equal to 1 and 3 should be replaced by 2. | 2 | 7 |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class A {
public static void main(String args[]) throws IOException{
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(reader.readLine());
int size = Integer.parseInt(st.nextToken());
int[] nums = new int[size];
int[] counter = new int[3];
st = new StringTokenizer(reader.readLine());
for(int i=0; i<size; i++){
switch(Integer.parseInt(st.nextToken())){
case 1: counter[0]++; break;
case 2: counter[1]++; break;
case 3: counter[2]++; break;
}
}
reader.close();
int max_pos = 0;
for(int i=0; i<counter.length; i++){
if(counter[max_pos]<counter[i]){
max_pos = i;
}
}
System.out.println(nums.length-counter[max_pos]);
}
}
| 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 of integers a1, a2, ..., an (1 ≤ ai ≤ 3).
Output
Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal.
Examples
Input
9
1 3 2 2 2 1 1 2 3
Output
5
Note
In the example all the numbers equal to 1 and 3 should be replaced by 2. | 2 | 7 | import java.util.Scanner;
/**
* Created with IntelliJ IDEA.
* User: ngupta
* Date: 16/6/2020 AD
* Time: 22:25
*/
public class _123_Sequence {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int one = 0;
int two = 0;
int three = 0;
while (n-- > 0) {
int x = sc.nextInt();
if (x == 1) one++;
else if (x == 2) two++;
else three++;
}
System.out.println(one + two + three - Math.max(one, Math.max(two, three)));
}
}
| 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 of integers a1, a2, ..., an (1 ≤ ai ≤ 3).
Output
Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal.
Examples
Input
9
1 3 2 2 2 1 1 2 3
Output
5
Note
In the example all the numbers equal to 1 and 3 should be replaced by 2. | 2 | 7 | from collections import Counter
import copy
def solve():
n=int(input())
arr=[int(i) for i in input().split()]
count=Counter(arr)
Max=max(count[1],count[2],count[3])
return n-Max
print(solve())
| 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 of integers a1, a2, ..., an (1 ≤ ai ≤ 3).
Output
Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal.
Examples
Input
9
1 3 2 2 2 1 1 2 3
Output
5
Note
In the example all the numbers equal to 1 and 3 should be replaced by 2. | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
int n;
int a[4];
int main() {
scanf("%d", &n);
for (int(i) = 0; (i) < (n); ++(i)) {
int first;
scanf("%d", &first);
a[first]++;
}
cout << n - max(max(a[1], a[2]), a[3]) << endl;
}
| 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 of integers a1, a2, ..., an (1 ≤ ai ≤ 3).
Output
Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal.
Examples
Input
9
1 3 2 2 2 1 1 2 3
Output
5
Note
In the example all the numbers equal to 1 and 3 should be replaced by 2. | 2 | 7 | #!/usr/bin/python
import sys
n = int (sys.stdin.readline ())
a = [int (x) for x in sys.stdin.readline ().split ()]
p = {1:0, 2:0, 3:0}
for i in range (n):
for j in [1, 2, 3]:
if a[i] != j:
p[j] += 1
print min (p[1], p[2], p[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 of integers a1, a2, ..., an (1 ≤ ai ≤ 3).
Output
Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal.
Examples
Input
9
1 3 2 2 2 1 1 2 3
Output
5
Note
In the example all the numbers equal to 1 and 3 should be replaced by 2. | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
int m[10];
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
int v;
cin >> v;
m[v]++;
}
cout << n - max(m[1], max(m[2], m[3])) << endl;
}
| 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 of integers a1, a2, ..., an (1 ≤ ai ≤ 3).
Output
Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal.
Examples
Input
9
1 3 2 2 2 1 1 2 3
Output
5
Note
In the example all the numbers equal to 1 and 3 should be replaced by 2. | 2 | 7 | import java.util.Scanner;
public class sequence123 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int[]arr = new int[n];
int[]count = new int[4];
for(int i = 0; i < n; i ++) {
arr[i] = sc.nextInt();
count[arr[i]] ++;
}
System.out.println(n - (Math.max(count[1], Math.max(count[2], count[3]))));
}
}
| 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 of integers a1, a2, ..., an (1 ≤ ai ≤ 3).
Output
Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal.
Examples
Input
9
1 3 2 2 2 1 1 2 3
Output
5
Note
In the example all the numbers equal to 1 and 3 should be replaced by 2. | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e6 + 5;
int a[MAXN], n;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
for (int i = 0; i < n; i++) cin >> a[i];
int mx = max(count(a, a + n, 1), max(count(a, a + n, 2), count(a, a + n, 3)));
cout << n - mx;
}
| 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 of integers a1, a2, ..., an (1 ≤ ai ≤ 3).
Output
Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal.
Examples
Input
9
1 3 2 2 2 1 1 2 3
Output
5
Note
In the example all the numbers equal to 1 and 3 should be replaced by 2. | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
int main() {
int a[4] = {}, n, x;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> x;
a[x]++;
}
cout << n - *max_element(a + 1, a + 4);
}
| 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 of integers a1, a2, ..., an (1 ≤ ai ≤ 3).
Output
Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal.
Examples
Input
9
1 3 2 2 2 1 1 2 3
Output
5
Note
In the example all the numbers equal to 1 and 3 should be replaced by 2. | 2 | 7 |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Scanner;
import java.util.StringTokenizer;
public class Test {
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws IOException {
// TODO code application logic here
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
PrintWriter out = new PrintWriter(System.out);
int n = Integer.parseInt(br.readLine());
StringTokenizer s = new StringTokenizer(br.readLine());
int[] arr = new int[3];
for (int i = 0; i < n; i++) {
arr[Integer.parseInt(s.nextToken()) - 1]++;
}
out.println(n - (Math.max(arr[0], Math.max(arr[1], arr[2]))));
out.flush();
out.close();
}
}
| 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 of integers a1, a2, ..., an (1 ≤ ai ≤ 3).
Output
Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal.
Examples
Input
9
1 3 2 2 2 1 1 2 3
Output
5
Note
In the example all the numbers equal to 1 and 3 should be replaced by 2. | 2 | 7 | import java.util.Scanner;
public class xyz
{
public static void main(String args[])
{
Scanner sc =new Scanner (System.in);
int n=sc.nextInt();
int[] a=new int[n];
int n1=0;int n2=0;int n3=0;
for(int i=0;i<n;i++)
{
a[i]=sc.nextInt();
if(a[i]==1)
{
n1=n1+1;
}
else if(a[i]==2)
{
n2=n2+1;
}
else if(a[i]==3)
{
n3=n3+1;
}
}
if(n1==n2&&n1==n3)
{
System.out.println(2*n1);
}
else
{
int max= Math.max(n1, Math.max(n2,n3));
System.out.println(n-max);
}
sc.close();
}
}
| 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 of integers a1, a2, ..., an (1 ≤ ai ≤ 3).
Output
Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal.
Examples
Input
9
1 3 2 2 2 1 1 2 3
Output
5
Note
In the example all the numbers equal to 1 and 3 should be replaced by 2. | 2 | 7 | import java.io.*;
import java.util.*;
public class Main {
static PrintWriter w = new PrintWriter(System.out);
static Reader sc = new Reader();
public static void main(String args[]) throws IOException {
int tc = 1;
while (tc-- > 0) {
solve();
}
w.close();
}
//// SOLUTION BEGIN <--------------------------------------->
public static void solve() {
int n = sc.nextInt();
int arr[] = new int[4];
for (int i = 0; i < n; i++) {
arr[sc.nextInt()]++;
}
int maxFreq=-1;
for (int i = 1; i < 4; i++) {
if(arr[i] > maxFreq) maxFreq = arr[i];
}
w.println(n-maxFreq);
}
//// SOLUTION END <------------------------------------------->
// Class for Fast I/O------------------------------
static class Reader {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer("");
public String next() {
while (!st.hasMoreTokens()) {
try {
st = new StringTokenizer(br.readLine());
} catch (Exception e) {
e.printStackTrace();
}
}
return st.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
public double nextDouble() {
return Double.parseDouble(next());
}
public String nextLine() {
try {
return br.readLine();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
}
} | 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 of integers a1, a2, ..., an (1 ≤ ai ≤ 3).
Output
Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal.
Examples
Input
9
1 3 2 2 2 1 1 2 3
Output
5
Note
In the example all the numbers equal to 1 and 3 should be replaced by 2. | 2 | 7 | //package round_1;
import java.util.Scanner;
public class A {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = Integer.valueOf(scanner.nextLine());
String sequence = scanner.nextLine();
int counter1 = 0;
int counter2 = 0;
int counter3 = 0;
for (int index = 0; index < sequence.length(); index += 2) {
String ch = sequence.substring(index, index + 1);
if (ch.equals("1")) {
counter1++;
} else if (ch.equals("2")) {
counter2++;
}
}
counter3 = n - (counter1 + counter2);
int max = Math.max(counter1, counter2);
max = Math.max(max, counter3);
System.out.println(String.valueOf((n - max)));
scanner.close();
}
}
| 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 of integers a1, a2, ..., an (1 ≤ ai ≤ 3).
Output
Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal.
Examples
Input
9
1 3 2 2 2 1 1 2 3
Output
5
Note
In the example all the numbers equal to 1 and 3 should be replaced by 2. | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
int main() {
std::ios_base::sync_with_stdio(false);
int n;
cin >> n;
int a[4], b;
a[1] = 0;
a[2] = 0;
a[3] = 0;
for (int i = 0; i < n; i++) {
cin >> b;
a[b]++;
}
cout << n - max(max(a[1], a[2]), a[3]);
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 of integers a1, a2, ..., an (1 ≤ ai ≤ 3).
Output
Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal.
Examples
Input
9
1 3 2 2 2 1 1 2 3
Output
5
Note
In the example all the numbers equal to 1 and 3 should be replaced by 2. | 2 | 7 | var getNums = function() {
return readline().split(' ').map(function(a) {return parseInt(a)});
};
var n = parseInt(readline());
var input = getNums();
var hash = {};
for(var j = 1; j <= 3; j++) {
hash[j] = 0;
}
for (var i = 0; i < n; i++) {
hash[input[i]]++;
}
print(Math.min(hash[1] + hash[2], hash[1] + hash[3], hash[3] + hash[2])); | 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 of integers a1, a2, ..., an (1 ≤ ai ≤ 3).
Output
Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal.
Examples
Input
9
1 3 2 2 2 1 1 2 3
Output
5
Note
In the example all the numbers equal to 1 and 3 should be replaced by 2. | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
int N, a, b, c, x;
int main() {
cin >> N;
for (int i = 0; i < N; i++) {
cin >> x;
if (x == 1) a++;
if (x == 2) b++;
if (x == 3) c++;
}
cout << N - max(max(a, b), c) << 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 of integers a1, a2, ..., an (1 ≤ ai ≤ 3).
Output
Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal.
Examples
Input
9
1 3 2 2 2 1 1 2 3
Output
5
Note
In the example all the numbers equal to 1 and 3 should be replaced by 2. | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin.tie(NULL);
long int n;
cin >> n;
int a[n];
int b[3] = {0};
for (long int i = 0; i < n; i++) {
cin >> a[i];
if (a[i] == 1)
b[0]++;
else if (a[i] == 2)
b[1]++;
else if (a[i] == 3)
b[2]++;
}
int max = b[0];
for (int i = 1; i < 3; i++) {
if (b[i] > max) max = b[i];
}
cout << n - max;
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 of integers a1, a2, ..., an (1 ≤ ai ≤ 3).
Output
Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal.
Examples
Input
9
1 3 2 2 2 1 1 2 3
Output
5
Note
In the example all the numbers equal to 1 and 3 should be replaced by 2. | 2 | 7 | import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.StreamTokenizer;
public class A {
static StreamTokenizer st;
public static void main(String[] args) throws IOException{
st = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
int n = nextInt();
int[]cnt = new int[4];
for (int i = 1; i <= n; i++) {
cnt[nextInt()]++;
}
int ans = Math.min(n-cnt[1], Math.min(n-cnt[2], n-cnt[3]));
pw.print(ans);
pw.close();
}
private static int nextInt() throws IOException{
st.nextToken();
return (int) st.nval;
}
}
| 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 of integers a1, a2, ..., an (1 ≤ ai ≤ 3).
Output
Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal.
Examples
Input
9
1 3 2 2 2 1 1 2 3
Output
5
Note
In the example all the numbers equal to 1 and 3 should be replaced by 2. | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
void show_vector(vector<int>& a) {
for (vector<int>::iterator it = a.begin(); it != a.end(); ++it) cout << *it;
}
int main() {
int n, v, a = 0, b = 0, c = 0;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> v;
if (v == 1)
a++;
else if (v == 2)
b++;
else
c++;
}
cout << n - max(max(a, b), c);
}
| 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 of integers a1, a2, ..., an (1 ≤ ai ≤ 3).
Output
Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal.
Examples
Input
9
1 3 2 2 2 1 1 2 3
Output
5
Note
In the example all the numbers equal to 1 and 3 should be replaced by 2. | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
string s;
vector<int> v;
int a[1111111];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
int mn = 2 * n;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = 1; i <= 3; i++) {
int t = 0;
for (int j = 0; j < n; j++) {
t += (a[j] != i);
}
mn = min(mn, t);
}
cout << mn << 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 of integers a1, a2, ..., an (1 ≤ ai ≤ 3).
Output
Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal.
Examples
Input
9
1 3 2 2 2 1 1 2 3
Output
5
Note
In the example all the numbers equal to 1 and 3 should be replaced by 2. | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
int main() {
int long long n, h[4] = {0}, x;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> x;
h[x]++;
}
sort(h, h + 4);
cout << endl << n - h[3];
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 of integers a1, a2, ..., an (1 ≤ ai ≤ 3).
Output
Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal.
Examples
Input
9
1 3 2 2 2 1 1 2 3
Output
5
Note
In the example all the numbers equal to 1 and 3 should be replaced by 2. | 2 | 7 | import java.util.*;
import java.io.*;
public class test
{
public static void main(String[] args)
{
new test().run();
}
void run()
{
Scanner in = new Scanner(System.in);
PrintWriter out = new PrintWriter(System.out);
int n = in.nextInt();
int[] counts = new int[3];
for (int i = 0; i < n; i++)
counts[in.nextInt() - 1]++;
int min = Integer.MAX_VALUE;
for (int i = 0; i < 3; i++)
min = Math.min(min, n - counts[i]);
out.println(min);
out.close();
}
}
| 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 of integers a1, a2, ..., an (1 ≤ ai ≤ 3).
Output
Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal.
Examples
Input
9
1 3 2 2 2 1 1 2 3
Output
5
Note
In the example all the numbers equal to 1 and 3 should be replaced by 2. | 2 | 7 | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
public class Solution {
public static void main(String[] args) throws IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
PrintWriter out = new PrintWriter(System.out);
int[] count = new int[3];
int n = Integer.parseInt(in.readLine());
StringTokenizer st = new StringTokenizer(in.readLine());
for (int i = 0; i < n; i++)
count[Integer.parseInt(st.nextToken()) - 1]++;
Arrays.sort(count);
out.print(n - count[2]);
out.close();
}
}
| 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 of integers a1, a2, ..., an (1 ≤ ai ≤ 3).
Output
Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal.
Examples
Input
9
1 3 2 2 2 1 1 2 3
Output
5
Note
In the example all the numbers equal to 1 and 3 should be replaced by 2. | 2 | 7 | #include <bits/stdc++.h>
int n, x, C[4];
int main() {
scanf("%d", &n);
while (n--) {
scanf("%d", &x);
C[x - 1]++;
}
int a = C[0];
if (C[1] > a) a = C[1];
if (C[2] > a) a = C[2];
printf("%d\n", C[0] + C[1] + C[2] - a);
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 of integers a1, a2, ..., an (1 ≤ ai ≤ 3).
Output
Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal.
Examples
Input
9
1 3 2 2 2 1 1 2 3
Output
5
Note
In the example all the numbers equal to 1 and 3 should be replaced by 2. | 2 | 7 | x=int(input())
String1=input()
list1=list(String1)
i=0
a=0
b=0
c=0
for i in list1:
if i=='1':
a+=1
elif i=='2':
b+=1
elif i=='3':
c+=1
p=max(a,b,c)
print(x-p) | 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 of integers a1, a2, ..., an (1 ≤ ai ≤ 3).
Output
Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal.
Examples
Input
9
1 3 2 2 2 1 1 2 3
Output
5
Note
In the example all the numbers equal to 1 and 3 should be replaced by 2. | 2 | 7 | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Prob052A
{
public static void main( String[] Args ) throws IOException
{
BufferedReader br = new BufferedReader( new InputStreamReader( System.in ) );
int x = Integer.parseInt( br.readLine() );
StringTokenizer st = new StringTokenizer( br.readLine() );
int[] occs = new int[3];
for ( int i = 0; i < x; i++ )
occs[Integer.parseInt( st.nextToken() ) - 1]++;
int max = Math.max( occs[0], Math.max( occs[1], occs[2] ) );
System.out.println( x - max );
}
}
| 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 of integers a1, a2, ..., an (1 ≤ ai ≤ 3).
Output
Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal.
Examples
Input
9
1 3 2 2 2 1 1 2 3
Output
5
Note
In the example all the numbers equal to 1 and 3 should be replaced by 2. | 2 | 7 | n=int(input())
l=list(map(int,input().split()))
a1=l.count(1)
a2=l.count(2)
a3=l.count(3)
v=[]
v.append(a1)
v.append(a2)
v.append(a3)
# l=set(v)
# v=list(l)
a=max(a1,a2,a3)
if len(v)==1:
print('0')
else:
v.remove(a)
print(sum(v)) | 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 of integers a1, a2, ..., an (1 ≤ ai ≤ 3).
Output
Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal.
Examples
Input
9
1 3 2 2 2 1 1 2 3
Output
5
Note
In the example all the numbers equal to 1 and 3 should be replaced by 2. | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
int a[1000000 + 10];
int main() {
int n, m, b[10] = {}, k = 0, x, y, max, ans = 0;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
b[a[i]]++;
}
x = b[1];
for (int i = 2; i <= 3; i++) {
if (x < b[i]) x = b[i];
}
for (int i = 1; i <= 3; i++) {
if (b[i] == x) max = i;
}
y = max;
for (int i = 0; i < n; i++)
if (a[i] != y) ans++;
cout << ans << endl;
}
| 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 of integers a1, a2, ..., an (1 ≤ ai ≤ 3).
Output
Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal.
Examples
Input
9
1 3 2 2 2 1 1 2 3
Output
5
Note
In the example all the numbers equal to 1 and 3 should be replaced by 2. | 2 | 7 | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;
public class Sequence {
public static void main(String[] args) throws NumberFormatException, IOException{
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(in.readLine());
int[] seq = new int[n];
StringTokenizer st = new StringTokenizer(in.readLine());
int k = 0;
while(st.hasMoreTokens()){
seq[k] = Integer.parseInt(st.nextToken());
k++;
}
Arrays.sort(seq);
int count = 0;
int max = 0;
for(int i = 0; i < seq.length; i++){
count = 0;
while((i < seq.length - 1) && seq[i] == seq[i+1]){
count++;
i++;
}
count = count + 1;
if(count > max) max = count;
}
System.out.println(n - max);
}
}
| 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 of integers a1, a2, ..., an (1 ≤ ai ≤ 3).
Output
Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal.
Examples
Input
9
1 3 2 2 2 1 1 2 3
Output
5
Note
In the example all the numbers equal to 1 and 3 should be replaced by 2. | 2 | 7 | import java.util.Scanner;
public class x52A {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int[] nums = new int[4];
for(int a=0;a<n;a++){
nums[sc.nextInt()]++;
}
if(nums[3]>=nums[2]&&nums[3]>=nums[1]){
System.out.printf("%d",nums[1]+nums[2]);
System.exit(0);
}
else if(nums[2]>=nums[3]&&nums[2]>=nums[1]){
System.out.printf("%d",nums[1]+nums[3]);
System.exit(0);
}
else System.out.printf("%d",nums[3]+nums[2]);
System.exit(0);
}
}
| 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 of integers a1, a2, ..., an (1 ≤ ai ≤ 3).
Output
Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal.
Examples
Input
9
1 3 2 2 2 1 1 2 3
Output
5
Note
In the example all the numbers equal to 1 and 3 should be replaced by 2. | 2 | 7 | n = int(input())
a = list(map(int, input().split()))
print(n - max(a.count(1), max(a.count(2), a.count(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 of integers a1, a2, ..., an (1 ≤ ai ≤ 3).
Output
Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal.
Examples
Input
9
1 3 2 2 2 1 1 2 3
Output
5
Note
In the example all the numbers equal to 1 and 3 should be replaced by 2. | 2 | 7 | import java.util.Scanner;
public class Sequence {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int f = in.nextInt();
int con = 0,con1=0,con2=0,conta=0,conta2=0,conta3=0;
for (int i = 0; i < f; i++) {
String s = in.next();
if (s.equals("1")) {con++;
} if (s.equals("2")) {con1++;
} if (s.equals("3")) {con2++;
}if (s.equals("1")||s.equals("3")) {
conta++;
} if (s.equals("2")||s.equals("3")) {
conta2++;
} if (s.equals("2")||s.equals("1")) {
conta3++;
}
}
if (con1>=con && con1>=con2) {//2 es mayor
System.out.println(""+conta);
}else if (con>=con1 && con>=con2) {//1 es mayor
System.out.println(""+conta2);
}else if (con2>=con && con2>=con1) {// 3 es mayor
System.out.println(""+conta3);
}
}
} | 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 of integers a1, a2, ..., an (1 ≤ ai ≤ 3).
Output
Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal.
Examples
Input
9
1 3 2 2 2 1 1 2 3
Output
5
Note
In the example all the numbers equal to 1 and 3 should be replaced by 2. | 2 | 7 | N = int(raw_input())
nums = map(int,raw_input().split())
a = nums.count(1)
b = nums.count(2)
c = nums.count(3)
print min([a+b,b+c,a+c]) | 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 of integers a1, a2, ..., an (1 ≤ ai ≤ 3).
Output
Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal.
Examples
Input
9
1 3 2 2 2 1 1 2 3
Output
5
Note
In the example all the numbers equal to 1 and 3 should be replaced by 2. | 2 | 7 | n=input()
A=map(int,raw_input().split())
cnt=[0]*3
for a in A:
cnt[a-1]+=1
s=max(cnt)
print n-s | 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 of integers a1, a2, ..., an (1 ≤ ai ≤ 3).
Output
Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal.
Examples
Input
9
1 3 2 2 2 1 1 2 3
Output
5
Note
In the example all the numbers equal to 1 and 3 should be replaced by 2. | 2 | 7 | import java.util.Random;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.PrintWriter;
import java.io.InputStreamReader;
import java.io.File;
import java.math.BigInteger;
public class Task{
static final boolean readFromFile = false;
static final String fileInputName = "input.txt",
fileOutputName = "output.txt";
public static void main(String args[]){
FileInputStream fileInputStream;
FileOutputStream fileOutputStream;
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
if (readFromFile){
try{
fileInputStream = new FileInputStream(new File(fileInputName));
fileOutputStream = new FileOutputStream(new File(fileOutputName));
}catch (FileNotFoundException e){
throw new RuntimeException(e);
}
}
PrintWriter out = new PrintWriter((readFromFile)?fileOutputStream:outputStream);
InputReader in = new InputReader((readFromFile)?fileInputStream:inputStream);
Solver s = new Solver(in, out);
s.solve();
out.close();
}
}
class Solver{
private PrintWriter out;
private InputReader in;
public void solve(){
int n = in.nextInt();
int a[] = new int[4];
for (int i=0;i<n;i++){
int b= in.nextInt();
a[b]++;
}
int sum = a[1]+a[2]+a[3];
int ans = Math.min(sum-a[1],sum-a[2]);
ans = Math.min(ans,sum-a[3]);
out.println(ans);
}
Solver(InputReader in, PrintWriter out){
this.in = in;
this.out = out;
}
}
class InputReader{
StringTokenizer tok;
BufferedReader buf;
InputReader(InputStream in){
tok = null;
buf = new BufferedReader(new InputStreamReader(in));
}
InputReader(FileInputStream in){
tok = null;
buf = new BufferedReader(new InputStreamReader(in));
}
public String next(){
while (tok==null || !tok.hasMoreTokens()){
try{
tok = new StringTokenizer(buf.readLine());
}catch (IOException e){
throw new RuntimeException(e);
}
}
return tok.nextToken();
}
public int nextInt(){
return Integer.parseInt(next());
}
public long nextLong(){
return Long.parseLong(next());
}
public double nextDouble(){
return Double.parseDouble(next());
}
public float nextFloat(){
return Float.parseFloat(next());
}
public String nextLine(){
try{
return buf.readLine();
}catch (IOException e){
return null;
}
}
} | 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 of integers a1, a2, ..., an (1 ≤ ai ≤ 3).
Output
Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal.
Examples
Input
9
1 3 2 2 2 1 1 2 3
Output
5
Note
In the example all the numbers equal to 1 and 3 should be replaced by 2. | 2 | 7 | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.math.*;
public class Test {
public BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
public PrintWriter output = new PrintWriter(System.out, true);
public static StringTokenizer st = new StringTokenizer("");
private String nextString() throws IOException{
while (!st.hasMoreElements()) {
st = new StringTokenizer(input.readLine());
}
return st.nextToken();
}
private int nextInt() throws IOException{
return Integer.valueOf(nextString());
}
private byte nextByte() throws IOException{
return Byte.valueOf(nextString());
}
private Long nextLong() throws IOException{
return Long.valueOf(nextString());
}
/////////////////// START /////////////////////////
public void poehali() throws IOException{
int n = nextInt();
int a[] = new int[4];
for (int i = 0; i < n; i++) {
a[nextByte()]++;
}
System.out.println(n-Math.max(Math.max(a[1], a[2]), a[3]));
}
////////////////////// MAIN ///////////////////////
public static void main(String[] args) throws IOException {
new Test().poehali();
}
}
| 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 of integers a1, a2, ..., an (1 ≤ ai ≤ 3).
Output
Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal.
Examples
Input
9
1 3 2 2 2 1 1 2 3
Output
5
Note
In the example all the numbers equal to 1 and 3 should be replaced by 2. | 2 | 7 | a = raw_input()
a = raw_input()
def cnt(x):
return len([1 for i in a if i == x])
s = cnt('1') + cnt('2') + cnt('3')
ans = s
ans = min(ans , s - cnt('1'))
ans = min(ans , s - cnt('2'))
ans = min(ans , s - cnt('3'))
print(ans)
| 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 of integers a1, a2, ..., an (1 ≤ ai ≤ 3).
Output
Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal.
Examples
Input
9
1 3 2 2 2 1 1 2 3
Output
5
Note
In the example all the numbers equal to 1 and 3 should be replaced by 2. | 2 | 7 | import java.util.*;
import java.io.*;
public class Main implements Runnable {
public void solve() throws IOException {
int N = nextInt();
int[] a = new int[3];
for(int i = 0; i < N; i++) a[nextInt() - 1]++;
Arrays.sort(a);
System.out.println(a[0] + a[1]);
}
//-----------------------------------------------------------
public static void main(String[] args) {
new Main().run();
}
public void print1Int(int[] a){
for(int i = 0; i < a.length; i++)
System.out.print(a[i] + " ");
System.out.println();
}
public void print2Int(int[][] a){
for(int i = 0; i < a.length; i++){
for(int j = 0; j < a[0].length; j++){
System.out.print(a[i][j] + " ");
}
System.out.println();
}
}
public void run() {
try {
in = new BufferedReader(new InputStreamReader(System.in));
tok = null;
solve();
in.close();
} catch (IOException e) {
System.exit(0);
}
}
public String nextToken() throws IOException {
while (tok == null || !tok.hasMoreTokens()) {
tok = new StringTokenizer(in.readLine());
}
return tok.nextToken();
}
public int nextInt() throws IOException {
return Integer.parseInt(nextToken());
}
public long nextLong() throws IOException {
return Long.parseLong(nextToken());
}
public double nextDouble() throws IOException {
return Double.parseDouble(nextToken());
}
BufferedReader in;
StringTokenizer tok;
} | 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 of integers a1, a2, ..., an (1 ≤ ai ≤ 3).
Output
Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal.
Examples
Input
9
1 3 2 2 2 1 1 2 3
Output
5
Note
In the example all the numbers equal to 1 and 3 should be replaced by 2. | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
int main() {
int i = 0, X, N, A[3] = {};
cin >> N;
while (i < N) {
cin >> X;
++A[X - 1];
++i;
};
X = ((A[0] > ((A[1] > A[2]) ? (A[1]) : (A[2])))
? (A[0])
: (((A[1] > A[2]) ? (A[1]) : (A[2]))));
cout << (N - X);
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 of integers a1, a2, ..., an (1 ≤ ai ≤ 3).
Output
Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal.
Examples
Input
9
1 3 2 2 2 1 1 2 3
Output
5
Note
In the example all the numbers equal to 1 and 3 should be replaced by 2. | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
int n, t;
int a[4];
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
int x;
cin >> x;
a[x]++;
}
t = max(t, max(a[3], max(a[1], a[2])));
cout << n - t << 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 of integers a1, a2, ..., an (1 ≤ ai ≤ 3).
Output
Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal.
Examples
Input
9
1 3 2 2 2 1 1 2 3
Output
5
Note
In the example all the numbers equal to 1 and 3 should be replaced by 2. | 2 | 7 | #include <bits/stdc++.h>
using namespace std;
int a[1234567], r[1234567], rr[1234567];
int n, m, k, x, y, b = 0, q, p;
int main() {
cin >> n;
m = n;
while (m--) {
cin >> x;
a[x]++;
}
cout << n - max(a[1], max(a[2], a[3]));
}
| CPP |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.