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 | n=int(input())
List=list(input().split())
List=list(map(int,List))
minimum_replacement=None
for i in range(1,4):
count=0
for j in range(n):
if List[j]!=i:
count +=1
if minimum_replacement is None:
minimum_replacement=count
elif count<minimum_replacement:
minimum_replacement=count
print(minimum_replacement)
| 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.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) throws IOException {
//MScanner sc = new MScanner(System.in);
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
PrintWriter pw=new PrintWriter(System.out);
int n=Integer.parseInt(br.readLine());
StringTokenizer st=new StringTokenizer(br.readLine());
int ones=0;int twos=0;int ths=0;
for(int i=0;i<n;i++) {
int x=Integer.parseInt(st.nextToken());
if(x==1)ones++;
if(x==2)twos++;
if(x==3)ths++;
}
pw.println(Math.min(Math.min(twos+ths,ones+ths),twos+ones));
pw.close();
pw.flush();
}
} | 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 | def sequence(lst):
a = lst.count(1)
b = lst.count(2)
c = lst.count(3)
if a > b and a > c:
return len(lst) - a
elif b > a and b > c:
return len(lst) - b
elif c > a and c > b:
return len(lst) - c
elif a == b == c:
return len(lst) - a
elif a == 0 and b == c or b == 0 and a == c or c == 0 and a == b:
return len(lst) - max(a, b, c)
return len(lst) - max(a, b, c)
n = int(input())
d = [int(i) for i in input().split()]
print(sequence(d))
| 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 Counter
def convert(arr):
arr = arr.split(" ")
for i in range(len(arr)):
arr[i] = int(arr[i])
return arr
t = int(input())
s = input()
n_num = convert(s)
n = len(n_num)
data = Counter(n_num)
get_mode = dict(data)
mode = [k for k, v in get_mode.items() if v == max(list(data.values()))]
ans = t - get_mode[mode[0]]
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 |
from collections import Counter
n = int(input())
l = list(map(int, input().split()))
cc = Counter(l)
vals = list(cc.values())
print(n - max(vals)) | 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.util.Arrays;
import java.util.StringTokenizer;
/**
*
* @author Prateep
*/
public class JavaApplication1 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws IOException {
// TODO code application logic here
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
PrintWriter out = new PrintWriter(outputStream);
TaskB solver = new TaskB();
solver.solve(1, in, out);
out.close();
}
}
class TaskB{
public void solve(int testNumber, InputReader in, PrintWriter out) throws IOException{
int n=in.nextInt();
int[] num=new int[3];
for(int i=0;i<n;i++)num[in.nextInt()-1]++;
Arrays.sort(num);
out.println(num[0]+num[1]);
}
}
class InputReader {
private BufferedReader reader;
private StringTokenizer tokenizer;
private BufferedReader br;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream));
tokenizer = null;
}
public String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public String nextWhole() throws IOException{
br=new BufferedReader(new InputStreamReader(System.in));
return br.readLine();
}
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 reader.readLine();
}catch (IOException e){
throw new RuntimeException(e);
}
}
}
class Pair<A, B> {
private A first;
private B second;
public Pair() {
super();
}
public Pair(A first, B second) {
super();
this.first = first;
this.second = second;
}
@Override
public int hashCode() {
int hashFirst = first != null ? first.hashCode() : 0;
int hashSecond = second != null ? second.hashCode() : 0;
return (hashFirst + hashSecond) * hashSecond + hashFirst;
}
@Override
public boolean equals(Object other) {
if (other instanceof Pair) {
Pair otherPair = (Pair) other;
return
(( this.first == otherPair.first ||
( this.first != null && otherPair.first != null &&
this.first.equals(otherPair.first))) &&
( this.second == otherPair.second ||
( this.second != null && otherPair.second != null &&
this.second.equals(otherPair.second))) );
}
return false;
}
@Override
public String toString()
{
return "("+first+","+second+")";
}
public A getFirst() {
return first;
}
public void setFirst(A first){
this.first=first;
}
public B getSecond(){
return second;
}
public void setSecond(B second){
this.second=second;
}
}
| 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 main() {
int n;
scanf("%d", &n);
int vec[4] = {0};
for (int i = 0; i < n; i++) {
int a;
scanf("%d", &a);
vec[a]++;
}
int x = vec[1] + vec[2];
int y = vec[1] + vec[3];
int z = vec[3] + vec[2];
if (x > y) x = y;
if (x > z) x = z;
printf("%d\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 | n=int(input())
l=list(map(int,input().split()))
a=l.count(1)
b=l.count(2)
c=l.count(3)
print(n-max(a,b,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 d, n, k = 0, b = 0, l = 0, a, i;
int main() {
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%d", &a);
if (a == 1) {
k++;
} else if (a == 2) {
l++;
} else {
b++;
}
}
d = (k > l) ? k : l;
d = (d > b) ? d : b;
cout << n - d << 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;
cin >> n;
vector<int> a(3);
int t;
for (int i = 0; i < n; i += 1) {
cin >> t;
a[t - 1] += 1;
}
sort(a.begin(), a.end());
cout << a[0] + a[1] << "\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 | from collections import Counter
n = int(input())
s = Counter(input().split())
print(n - s.most_common(1)[0][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 | import java.util.Scanner;
public class Ishu
{
public static void main(String[] args)
{
Scanner scan=new Scanner(System.in);
int n,i,j;
int[] a=new int[1000000];
int[] no=new int[3];
n=scan.nextInt();
for(i=0;i<n;++i)
{
a[i]=scan.nextInt();
++no[a[i]-1];
}
for(i=0;i<3;++i)
for(j=0;j<2;++j)
if(no[j]>no[j+1])
{
no[j]=no[j]+no[j+1];
no[j+1]=no[j]-no[j+1];
no[j]=no[j]-no[j+1];
}
System.out.println((no[0]+no[1]));
}
} | 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.lang.*;
import java.io.*;
import java.util.*;
import java.math.*;
public class Solution implements Runnable{
private static BufferedReader br = null;
private static PrintWriter out = null;
private static StringTokenizer stk = null;
public static void main(String[] args) {
br = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
(new Thread(new Solution())).start();
}
private void loadLine() {
try {
stk = new StringTokenizer(br.readLine());
}
catch (IOException e) {
e.printStackTrace();
}
}
private String nextLine() {
try {
return br.readLine();
}
catch (IOException e) {
e.printStackTrace();
}
return null;
}
private Integer nextInt() {
while (stk==null||!stk.hasMoreTokens()) loadLine();
return Integer.parseInt(stk.nextToken());
}
private Long nextLong() {
while (stk==null||!stk.hasMoreTokens()) loadLine();
return Long.parseLong(stk.nextToken());
}
private String nextWord() {
while (stk==null||!stk.hasMoreTokens()) loadLine();
return (stk.nextToken());
}
private Double nextDouble() {
while (stk==null||!stk.hasMoreTokens()) loadLine();
return Double.parseDouble(stk.nextToken());
}
public void run() {
int n = nextInt();
int[] arr = new int[n];
for (int i = 0; i < n; ++i) {
arr[i] = nextInt();
}
int c1 = 0;
int c2 = 0;
int c3 = 0;
for (int i = 0; i < n; ++i) {
if (arr[i] == 1) {
++c1;
}
else if (arr[i] == 2) {
++c2;
}
else {
++c3;
}
}
int res = Integer.MAX_VALUE;
res = Math.min(res, c1+c2);
res = Math.min(res, c1+c3);
res = Math.min(res, c3+c2);
out.println(res);
out.flush();
}
}
| 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() {
ios::sync_with_stdio(0);
int n;
cin >> n;
int a[4];
memset(a, 0, sizeof(a));
int x;
int cnt = n;
while (cnt--) {
cin >> x;
a[x]++;
}
int ans = max(a[1], max(a[2], a[3]));
ans = n - ans;
cout << ans << 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 | # -*- coding: utf-8 -*-
import sys
def hh(a,b):
if a>b:
return a
else:
return b
if __name__ == '__main__':
num= map(int,sys.stdin.readline().split())
lit1=[]
lit1 = map(int,sys.stdin.readline().split())
a = lit1.count(1)
b = lit1.count(2)
c = lit1.count(3)
d = hh(a,b)
d = hh(d,c)
print num[0]-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 | import statistics
x = int(input())
seq = input().split()
seq = [int(i) for i in seq]
occ1 = seq.count(1)
occ2 = seq.count(2)
occ3 = seq.count(3)
print (x-max(occ1,occ2,occ3)) | 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()]
one=two=three=0
for x in a:
if x==1:
one+=1
if x==2:
two+=1
if x==3:
three+=1
y=max(one,two,three)
print(one+two+three-y) | 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 = input()
s = raw_input().split()
print n - max(s.count('1'),s.count('2'),s.count('3'))
| PYTHON |
52_A. 123-sequence | There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other.
Input
The first line contains an integer n (1 ≤ n ≤ 106). The second line contains a sequence 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.Scanner;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) {
SpeedScanner speedScanner = new SpeedScanner();
PrintWriter out = new PrintWriter(System.out);
taskSolver(speedScanner, out);
out.close();
}
public static void taskSolver(SpeedScanner speedScanner, PrintWriter out) {
int n = speedScanner.nextInt();
int one=0,two=0,three=0,a,result=999999999;
for (int i = 0 ; i < n; i++){
a = speedScanner.nextInt();
if (a==1)
one++;
else if (a==2)
two++;
else
three++;
}
if (one+two <= result)
result = one+two;
if (one+three <= result)
result = one+three;
if (two+three <= result)
result = two+three;
out.print(result);
}
public static class SpeedScanner {
BufferedReader br;
StringTokenizer st;
public SpeedScanner() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String nextToken() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(nextToken());
}
long nextLong() {
return Long.parseLong(nextToken());
}
double nextDouble() {
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 | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int a[n];
int one = 0, two = 0, three = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
if (a[i] == 1)
one++;
else if (a[i] == 2)
two++;
else
three++;
}
cout << n - max(one, max(two, three)) << 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 | n=int(raw_input())
l=[int(x) for x in raw_input().split()]
print min(n-l.count(1),n-l.count(2),n-l.count(3)) | PYTHON |
52_A. 123-sequence | There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other.
Input
The first line contains an integer n (1 ≤ n ≤ 106). The second line contains a sequence 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 Posledov {
/**
* @param args
*/
int[] arr = new int[4];
static StreamTokenizer st;
private int nextInt() throws IOException{
st.nextToken();
return (int) st.nval;
}
public void go() throws IOException{
st = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
int n = nextInt();
for (int i = 0; i < n; i++) {
int a = nextInt();
arr[a]++;
}
if ((arr[1] >= arr[2]) & (arr[1] >= arr[3])) {
System.out.println(arr[2] + arr[3]);
} else if ((arr[2] >= arr[3]) & (arr[2] >= arr[1])) {
System.out.println(arr[1] + arr[3]);
} else if ((arr[3] >= arr[1]) & (arr[3] >= arr[2])) {
System.out.println(arr[1] + arr[2]);
}
}
public static void main(String[] args) throws IOException{
// TODO Auto-generated method stub
Posledov start = new Posledov();
start.go();
}
} | 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
n = int(raw_input())
c = Counter(map(int, raw_input().split()))
print min(map(lambda x:n-x, c.values()))
| 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.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[3];
for (int i = 0; i < n; i++) {
a[nextByte()-1]++;
}
System.out.println(n-Math.max(Math.max(a[0], a[1]), a[2]));
}
////////////////////// 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 | n=int(input())
alist=list(map(int,input().split()))
a=alist.count(1)
b=alist.count(2)
c=alist.count(3)
print(min(a+b,b+c,a+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;
const double PI = acos(-1.0);
const long long INF = 1000 * 1000 * 1000 + 7;
const long long LINF = INF * (long long)INF;
const int MAX = 1000 * 1000 + 47;
int C[3];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
for (int i = (0); i < (n); i++) {
int a;
cin >> a;
a--;
C[a]++;
}
int ans = min(C[0] + C[1], min(C[1] + C[2], C[0] + C[2]));
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 | items = int(raw_input())
line = raw_input().strip().split()
x = []
for i in line:
x.append(int(i))
count = [0,0,0]
for i in range(3):
count[i] = x.count(i+1)
print sum(count)-max(count)
| 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 Codeforces {
static StreamTokenizer in = new StreamTokenizer(new BufferedReader
(new InputStreamReader(System.in)));
// static PrintWriter out = new PrintWriter(System.out);
public static void main(String[] args) throws IOException{
in.nextToken();
int n = (int)in.nval;
int[] a = new int[n];
int a1 = 0, a2 = 0, a3 = 0;
for (int i = 0; i<n; i++){
in.nextToken();
a[i] = (int)in.nval;
if (a[i] == 1) a1++;
else
if (a[i] == 2) a2++;
else
if (a[i] == 3) a3++;
}
if (a1+a2 <= a2+a3 && a1+a2<=a1+a3){
System.out.println(a1+a2);
}
else
if (a1+a3 <= a1+a2 && a1+a3 <= a2+a3){
System.out.println(a1+a3);
}
else
System.out.print(a2+a3);
// out.flush();
}
}
| 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()
s=raw_input()
print n-max(s.count(str(i))for i in[1,2,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;
signed main() {
long long n;
cin >> n;
long long arr[n];
long long count[4] = {0};
for (long long i = 0; i < n; i++) {
cin >> arr[i];
count[arr[i]]++;
}
long long max = 0;
for (long long i = 0; i < 4; i++) {
if (count[i] > max) max = count[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.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.StringTokenizer;
public class Test {
public BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
public PrintWriter pw = new PrintWriter(new OutputStreamWriter(System.out), true);
public 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.parseInt(nextString());
}
private byte nextByte() throws IOException{
return Byte.parseByte(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()]++;
}
pw.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 | n = int(raw_input())
a = raw_input().split(' ')
c = [0,0,0]
for i in range(n):
if a[i] == "1":
c[0] += 1
elif a[i] == "2":
c[1] += 1
else:
c[2] += 1
print min( c[0] + c[1], c[0] + c[2], c[1] + c[2] )
| 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 main() {
int i, j;
int t;
int a = 0, b = 0, c = 0;
cin >> t;
for (i = 0; i < t; i++) {
cin >> j;
if (j == 1) a++;
if (j == 2) b++;
if (j == 3) c++;
}
int d;
d = a > b ? a : b;
d = d > c ? d : c;
cout << t - d;
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())
arr = list(map(int,input().split()))
arr.sort()
a = arr.count(1)
b = arr.count(2)
c = arr.count(3)
r1 = a + b
r2 = b + c
r3 = a + c
print(min(r1 , r2 , r3))
| 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 -*-
def main():
n = int(raw_input())
s = [0, 0, 0]
for i in raw_input().split():
s[int(i)-1] += 1
print n - max(s[0], max(s[1], s[2]))
return 0
if __name__ == '__main__':
main()
| 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.io.InputStreamReader;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.InputStream;
public class A {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
PrintWriter out = new PrintWriter(outputStream);
Task solver = new Task();
solver.solve(in, out);
out.close();
}
}
class Task {
public void solve(InputReader in, PrintWriter out) {
int n = in.nextInt();
int[] a = new int[n];
int[] b = new int[3];
for (int i = 0; i < n; i++) {
a[i] = in.nextInt();
if (a[i] < 2) b[0]++;
else if (a[i] > 2) b[2]++;
else b[1]++;
}
Arrays.sort(b);
out.println(b[0] + b[1]);
}
}
class InputReader {
public BufferedReader reader;
public StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream), 32768);
tokenizer = null;
}
public String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
} | 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 main() {
int n, max = 0;
int c[4] = {0};
scanf("%d", &n);
for (int i = 0; i < n; i++) {
int a;
scanf("%d", &a);
c[a]++;
if (c[a] > c[max]) max = a;
}
printf("%d\n", n - c[max]);
}
| CPP |
52_A. 123-sequence | There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other.
Input
The first line contains an integer n (1 ≤ n ≤ 106). The second line contains a sequence 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())
count1 = count2 = count3 = 0
input_str = input()
input_list = input_str.split(' ')
for i in range(n):
number = int(input_list[i])
if number == 1:
count1 += 1
elif number == 2:
count2 += 1
else:
count3 += 1
rez = []
rez.append(count1 + count2)
rez.append(count2 + count3)
rez.append(count3 + count1)
print(str(min(rez)))
| 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.util.*;
import java.math.*;
import static java.lang.Math.*;
public class Main implements Runnable {
StreamTokenizer in;
BufferedReader reader;
PrintWriter out;
StringTokenizer tok;
boolean timus = System.getProperty("ONLINE_JUDGE")!=null;
boolean codeforces = true;
final double eps = 1e-9;
public static void main(String[] args) throws Exception {
new Thread(new Main()).start();
}
@Override
public void run() {
try {
if (codeforces) {
reader = new BufferedReader(new InputStreamReader(System.in));
in = new StreamTokenizer(reader);
out= new PrintWriter (new OutputStreamWriter(System.out));
tok = new StringTokenizer("");
solve();
out.flush();
} else
if (!timus) {
long begMem = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory();
long t1 = System.currentTimeMillis();
reader = new BufferedReader(new InputStreamReader(System.in));
in = new StreamTokenizer(reader);
out= new PrintWriter (new OutputStreamWriter(System.out));
tok = new StringTokenizer("");
solve();
long endMem = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory();
out.flush();
long t2 = System.currentTimeMillis();
System.out.println("Time:"+(t2-t1));
System.out.println("Memory:"+(endMem-begMem));
System.out.println("Total memory: " + (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()));
} else {
reader = new BufferedReader(new FileReader("input.txt"));
in = new StreamTokenizer(reader);
out= new PrintWriter (new FileWriter("output.txt"));
tok = new StringTokenizer("");
solve();
out.flush();
out.close();
}
}
catch (Exception ex) {
System.out.println("fail");
System.exit(1);
}
}
public class Chess {
String coord;
public Chess(String s){
this.coord=s;
}
public int toInteger(char s) {
if (s=='a'||s=='A') return 1;
else if (s=='b'||s=='B') return 2;
else if (s=='c'||s=='C') return 3;
else if (s=='d'||s=='D') return 4;
else if (s=='e'||s=='E') return 5;
else if (s=='f'||s=='F') return 6;
else if (s=='g'||s=='G') return 7;
else if (s=='h'||s=='H') return 8;
else return -1;
}
public String toString(int s) {
if (s==1) return "a";
else if (s==2) return "b";
else if (s==3) return "c";
else if (s==4) return "d";
else if (s==5) return "e";
else if (s==6) return "f";
else if (s==7) return "g";
else if (s==8) return "h";
else return "0";
}
public pair getPair() {
String j="";
j+=coord.charAt(1);
pair p = new pair(toInteger(coord.charAt(0)),Integer.parseInt(j));
if (p.x!=-1)
return p; else
return new pair(0,0);
}
public String returnPair(int a,int b) {
return toString(a)+b;
}
}
public int nextInt() throws Exception {
in.nextToken();
return (int) in.nval;
}
public String next() throws Exception {
in.nextToken();
return in.sval;
}
public String nextLine() throws Exception {
return reader.readLine();
}
public String nextString() throws Exception {
while (!tok.hasMoreTokens())
tok = new StringTokenizer(reader.readLine());
return tok.nextToken();
}
public long nextLong() throws Exception {
return Long.parseLong(nextString());
}
public double nextDouble() throws Exception {
in.nextToken();
return in.nval;
}
public class pair {
int x;
int y;
public pair(int x, int y) {
this.x=x;
this.y=y;
}
}
public int gcd(int a, int b) {
if (a== 0||b==0) return 1;
if (a<b) {
int c=b;
b=a;
a=c;
}
while (a%b!=0) {
a =a%b;
if (a<b) {
int c=b;
b=a;
a=c;
}
}
return b;
}
public int pow(int a, int n) {
if (n==0) return 1;
int k=n, b=1, c=a;
while (k!=0) {
if (k%2==0) {
k/=2;
c*=c;
} else {
k--;
b*=c;
}
}
return b;
}
public int lcm(int a, int b) {
return a*b/gcd(a,b);
}
public class pairs implements Comparable<pairs> {
int x;
int y;
public pairs(int x, int y) {
this.x=x;
this.y=y;
}
@Override
public int compareTo(pairs obj) {
if (this.x<((pairs)obj).x) return 1;
else if (this.x==(obj).x&&this.y<(obj).y) return 1;
else if (this.x==(obj).x&&this.y==(obj).y)return 0; else
return -1;
}
}
public class Graf {
int [][] a;
int [] colors;
ArrayList <String> points = new ArrayList<String>();
LinkedList <Integer> queue = new LinkedList <Integer>();
boolean cycle;
int numberOfCycle;
public Graf(int [][]a,String s[]) {
this.a=new int [s.length][s.length];
this.a=a;
this.colors=new int [s.length];
for (int i=0; i<s.length;i++) {
this.colors[i]=0;
this.points.add(s[i]);
}
}
public void bfs(int i) {
this.queue.add(i);
while (!this.queue.isEmpty())
{
i = this.queue.pop();
for (int j=0; j<this.points.size();j++) {
if (this.a[i][j]==1&&!this.queue.contains(j)) {
this.a[i][j]=0;
this.a[j][i]=0;
this.queue.addLast(j);
}
}
}
}
public void dfs(int i) {
this.colors[i]=1;
for (int j=0; j<this.colors.length;j++) {
if (this.a[i][j]==1&&this.colors[j]==0) {
this.colors[j]=1;
this.a[i][j]=0;
this.a[j][i]=0;
dfs(j);
} else if (this.a[i][j]==1&&this.colors[j]==1) {
this.cycle=true;
this.numberOfCycle++;
}
}
this.colors[i]=2;
}
}
public int[] findPrimes(int x) {
boolean[] erat = new boolean[x-1];
List<Integer> t = new ArrayList<Integer>();
int l=0, j=0;
for (int i=2;i<x; i++) {
if (erat[i-2]) continue;
t.add(i);
l++;
j=i*2;
while (j<x) {
erat[j-2]=true;
j+=i;
}
}
int[] primes = new int[l];
Iterator<Integer> iterator = t.iterator();
for (int i = 0; iterator.hasNext(); i++) {
primes[i]=iterator.next().intValue();
}
return primes;
}
public void solve() throws Exception {
int n = nextInt();
int count1=0;
int count2=0;
int count3=0;
int a[] = new int [n];
for (int i=0; i<n;i++) {
a[i]=nextInt();
if (a[i]==1) {
count1++;
} else if (a[i]==2) count2++; else if (a[i]==3) count3++;
}
out.println(min(min(count1+count2,count2+count3),count1+count3));
}
}
| 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 = (int)(1e3 + 1e1);
const double PI = acos(-1.0);
long long n, z, q, w, e;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> z;
if (z == 1) q++;
if (z == 2) w++;
if (z == 3) e++;
}
cout << min(q, min(w, e)) +
(q + w + e - max(q, max(w, e)) - min(w, min(q, e)));
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
N = int(input())
Counter = Counter(list(map(int, input().split())))
print(N - max(Counter.values()))
# Hope the best for Ravens
# Never give up
| 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 length(int k) {
int c = 0;
while (k) {
k /= 10;
c++;
}
return c;
}
int bigmod(string s, int k) {
int i, rem = 0;
for (i = 0; i < s.size(); i++) {
rem = (rem * 10 + s[i] - '0') % k;
}
return rem;
}
void bigdiv(string s, int k) {
char q[20];
int i, r = 0, j = 0, d = 0, x;
string a;
for (i = 0; i < s.size(); i++) {
d = r * 10 + s[i] - '0';
x = d / k;
if (!(j == 0 && x == 0)) {
q[j] = x + 48;
j++;
}
r = d % k;
}
if (j == 0)
cout << '0';
else
for (i = 0; i < j; i++) cout << q[i];
}
int main() {
int maxx = 0, n, i;
cin >> n;
int a[n];
for (int i = 0; i < n; i++) cin >> a[i];
int b[4] = {0};
for (i = 0; i < n; i++) {
b[a[i]]++;
maxx = max(maxx, b[a[i]]);
}
cout << n - 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, c = 0, c2 = 0, c3 = 0, max = 0;
cin >> n;
int a[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
if (a[i] == 1) {
c++;
}
if (a[i] == 2) {
c2++;
}
if (a[i] == 3) {
c3++;
}
}
int p[] = {c, c2, c3};
for (int i = 0; i < 3; i++) {
if (p[i] > max) {
max = p[i];
}
}
cout << n - max;
}
| CPP |
52_A. 123-sequence | There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other.
Input
The first line contains an integer n (1 ≤ n ≤ 106). The second line contains a sequence 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 inf = 0x3f3f3f3f;
const double eps = 1e-6;
template <typename A, typename B>
ostream& operator<<(ostream& os, const pair<A, B>& p) {
return os << p.first << ',' << p.second;
}
template <typename T>
struct point {
T x, y;
point(T xx = 0, T yy = 0) : x(xx), y(yy) {}
T len2() const { return x * x + y * y; }
double len() const { return sqrt(double(len2())); }
bool operator==(const point<T>& p) const { return x == p.x && y == p.y; }
};
template <typename T>
point<T> operator+(const point<T>& a, const point<T>& b) {
return point<T>(a.x + b.x, a.y + b.y);
}
template <typename T>
point<T> operator-(const point<T>& a, const point<T>& b) {
return point<T>(a.x - b.x, a.y - b.y);
}
template <typename T>
T scal(const point<T>& a, const point<T>& b) {
return a.x * b.x + a.y * b.y;
}
template <typename T>
T vect(const point<T>& a, const point<T>& b) {
return a.x * b.y - a.y * b.x;
}
template <typename T>
ostream& operator<<(ostream& os, const point<T>& p) {
return os << '(' << p.x << ',' << p.y << ')';
}
int main() {
int n;
cin >> n;
int z[] = {0, 0, 0, 0};
for (int i = 0; i < n; i++) {
int x;
scanf("%d", &x);
z[x]++;
}
int v[] = {z[2] + z[3], z[1] + z[2], z[1] + z[3]};
sort(v, v + 3);
cout << v[0] << 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 | n = int(input())
numbers = list(map(int, input().split()))
a = numbers.count(1)
b = numbers.count(2)
c = numbers.count(3)
print(n - max(a,b,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, num1, num2, num3 = int(input()), 0, 0, 0
for item in [int(item) for item in input().split(' ')]:
if item == 1:
num1 += 1
elif item == 2:
num2 += 1
else:
num3 += 1
if num1 < num2:
t = num1
num1 = num2
num2 = t
if num1 < num3:
t = num1
num1 = num3
num3 = t
print(num2 + num3) | 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, *a;
int main() {
int n1 = 0, n2 = 0, n3 = 0;
cin >> n;
a = (int*)malloc(n * sizeof(int));
for (int i = 0; i < n; i++) {
cin >> a[i];
if (a[i] == 1)
n1++;
else if (a[i] == 2)
n2++;
else
n3++;
}
cout << n - max(max(n1, n2), n3);
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 dust i have come dust i will be
n=int(input())
a=list(map(int,input().split()))
uno=0
dos=0
tres=0
for i in range(n):
if a[i]==1:
uno+=1
elif a[i]==2:
dos+=1
else:
tres+=1
print(uno+dos+tres-max(uno,dos,tres)) | 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 one = 0, two = 0, three = 0;
for (int i = 0; i < n; i++) {
if (a[i] == 1) one++;
if (a[i] == 2) two++;
if (a[i] == 3) three++;
}
cout << n - max(one, max(two, three));
}
| CPP |
52_A. 123-sequence | There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other.
Input
The first line contains an integer n (1 ≤ n ≤ 106). The second line contains a sequence 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()))[:n]
b=a.count(1)
z=a.count(2)
c=a.count(3)
print(n-max(b,c,z))
| 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>
int num[5];
int main() {
int n, i, Num, max;
scanf("%d", &n);
num[1] = num[2] = num[3] = 0;
for (i = 0; i < n; i++) {
scanf("%d", &Num);
num[Num]++;
}
max = num[1];
if (num[2] > max) max = num[2];
if (num[3] > max) max = num[3];
printf("%d\n", 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.util.*;
import java.io.*;
public class CF52A {
BufferedReader br;
PrintWriter out;
StringTokenizer st;
boolean eof;
void solve() throws IOException {
int n = nextInt();
int[] arr = new int[n];
for(int i = 0; i < n; i++) {
arr[i] = nextInt();
}
int[] hist = new int[3];
for(int i = 0; i < n; i++)
hist[arr[i] - 1]++;
int res = Integer.MAX_VALUE;
for(int i = 0; i < 3; i++)
res = Math.min(res, n - hist[i]);
print(res);
}
private void println(Object o) {
System.out.println(o);
}
private void print(Object o) {
System.out.print(o);
}
public CF52A() throws IOException {
br = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
solve();
out.close();
}
public static void main(String[] args) throws IOException {
new CF52A();
}
public String nextToken() {
while (st == null || !st.hasMoreTokens()) {
try {
st = new StringTokenizer(br.readLine());
} catch (Exception e) {
eof = true;
return null;
}
}
return st.nextToken();
}
public String nextString() {
try {
return br.readLine();
} catch (IOException e) {
eof = true;
return null;
}
}
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());
}
} | 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.*;
import java.io.*;
public class Main {
public static void main(String[] args) throws Exception {
BufferedReader s = new BufferedReader(new InputStreamReader(System.in));
int n;
String line;
StringTokenizer st;
n = Integer.parseInt(s.readLine());
int one=0, two=0, three=0, temp;
line = s.readLine();
st = new StringTokenizer(line, " ");
for(int i=0; i<n; i++) {
temp = Integer.parseInt(st.nextToken());
if(temp==3) three++;
else if(temp==2) two++;
else one++;
}
if(three>=two && three>=one) System.out.println(n-three);
else if(two>=three && two>=one) System.out.println(n-two);
else System.out.println(n-one);
}
}
| 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()
a = [int(j) for j in raw_input().split(' ')]
# for i in a:
# b=a.count(i)
# x.append(b)
x=[a.count(1),a.count(2),a.count(3)]
m=max(x)
print n-m
| 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=raw_input()
print n-max(a.count(i)for i in'123') | 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;
template <typename... T>
void scan(T&... args) {
((cin >> args), ...);
}
template <typename... T>
void print(T... args) {
((cout << args), ...);
}
class Solution_To_Problem {
int n, x;
int count1, count2, count3, m;
public:
void solution_function() {
scan(n);
count1 = count2 = count3 = 0;
for (int i = 0; i < n; i++) {
scan(x);
if (x == 1)
++count1;
else if (x == 2)
++count2;
else
++count3;
}
m = max(max(count1, count2), count3);
print(n - m, '\n');
}
} Solution;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
Solution.solution_function();
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() {
long long int i, j, k, l, n;
cin >> n;
int a[n];
long long int b[3] = {0};
for (i = 0; i < n; i++) {
cin >> a[i];
b[a[i] - 1]++;
}
sort(b, b + 3);
cout << b[0] + b[1] << "\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 | import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;
public class TestA {
static InputStreamReader inp = new InputStreamReader(System.in);
static BufferedReader in = new BufferedReader(inp);
static boolean test = false;
static PrintWriter writer = new PrintWriter(System.out);
static String testDataFile = "testdata.txt";
BufferedReader reader = null;
public TestA() throws Throwable {
if(test){
reader = new BufferedReader(new FileReader(new File(testDataFile)));
}
}
private void solve() throws Throwable, IOException {
int count = readInteger();
int[] readIntegers = readIntegers();
int[] counter = new int[3];
for (int i = 0; i < readIntegers.length; i++) {
counter[readIntegers[i] - 1] ++;
}
int max = 0;
for (int i = 0; i < counter.length; i++) {
max = Math.max(max, counter[i]);
}
System.out.println(readIntegers.length - max);
}
/**
* The I/O method of reading
*/
int id = -1;
public String readLine() throws IOException {
id++;
if (test)
return reader.readLine();
else
return in.readLine();
}
/**
* read a single integer should be a full line
*/
private int readInteger() throws NumberFormatException, IOException {
return Integer.valueOf(readLine());
}
/**
* Read one line and split contents to an int array
*/
private int[] readIntegers() throws Exception{
String[] split = readLine().split(" ");
int[] list = new int[split.length];
for (int i = 0; i < list.length; i++) {
list[i] = Integer.parseInt(split[i]);
}
return list;
}
/**
* Entry point
*/
public static void main(String[] args) throws Throwable{
new TestA().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 | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
int one = 0;
int two = 0;
int three = 0;
int in;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> in;
switch (in) {
case 1: {
one++;
} break;
case 2: {
two++;
} break;
case 3: {
three++;
} break;
}
}
int mx = max(max(one, two), three);
cout << n - mx << 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;
cin >> n;
int arr[n + 1];
int a = 0, b = 0, c = 0;
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
for (int i = 0; i < n; i++) {
if (arr[i] == 1)
a++;
else if (arr[i] == 2)
b++;
else
c++;
}
int mx = max(c, max(a, b));
cout << n - mx << 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 | n = int(input())
l1 = [int(x) for x in input().split()]
l2 = set(l1)
c = []
for x in l2:
c.append(l1.count(x))
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>
int main() {
int A = 0, M, N, i, B = 0, C = 0, sum;
scanf("%d", &N);
for (i = 1; i <= N; i++) {
scanf("%d", &M);
if (M == 1) {
A++;
}
if (M == 2) {
B++;
}
if (M == 3) {
C++;
}
}
if (A >= B && A >= C) {
sum = B + C;
}
if (B >= A && B >= C) {
sum = A + C;
}
if (C >= A && C >= B) {
sum = A + B;
}
printf("%d\n", sum);
}
| 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
n=int(input())
arr=list(map(int,input().split()))
c=Counter(arr)
v=sorted(dict(c).values())
print(n-v[-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 | import java.io.*;
import java.util.*;
public class Task {
public static void main(String[] args) {
solve();
}
static void solve() {
int n = nextInt();
int[] a = nextAi(n);
int[] counts = new int[3];
for (int i = 0; i < n; ++i) {
counts[a[i] - 1]++;
}
System.out.println(n
- Math.max(counts[0], Math.max(counts[1], counts[2])));
}
/************************************************************************************/
static InputStream is = System.in;
static private byte[] buffer = new byte[1024];
static private int lenbuf = 0, ptrbuf = 0;
static private int readByte() {
if (lenbuf == -1)
throw new InputMismatchException();
if (ptrbuf >= lenbuf) {
ptrbuf = 0;
try {
lenbuf = is.read(buffer);
} catch (IOException e) {
throw new InputMismatchException();
}
if (lenbuf <= 0)
return -1;
}
return buffer[ptrbuf++];
}
static private boolean isSpace(int c) {
return !(c >= 33 && c <= 126);
}
static private int read() {
int b;
while ((b = readByte()) != -1 && isSpace(b))
;
return b;
}
static private double nextDouble() {
return Double.parseDouble(nextString());
}
static private char nextChar() {
return (char) read();
}
static private String nextString() {
int b = read();
StringBuilder sb = new StringBuilder();
while (!(isSpace(b))) {
sb.appendCodePoint(b);
b = readByte();
}
return sb.toString();
}
static private char[] nextString(int n) {
char[] buf = new char[n];
int b = read(), p = 0;
while (p < n && !(isSpace(b))) {
buf[p++] = (char) b;
b = readByte();
}
return n == p ? buf : Arrays.copyOf(buf, p);
}
static private int nextInt() {
int num = 0, b;
boolean minus = false;
while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
;
if (b == '-') {
minus = true;
b = readByte();
}
while (true) {
if (b >= '0' && b <= '9') {
num = num * 10 + (b - '0');
} else {
return minus ? -num : num;
}
b = readByte();
}
}
static private long nextLong() {
long num = 0;
int b;
boolean minus = false;
while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
;
if (b == '-') {
minus = true;
b = readByte();
}
while (true) {
if (b >= '0' && b <= '9') {
num = num * 10 + (b - '0');
} else {
return minus ? -num : num;
}
b = readByte();
}
}
static private int[] nextAi(int n) {
int[] a = new int[n];
for (int i = 0; i < n; i++)
a[i] = nextInt();
return a;
}
static private Integer[] nextAi1(int n) {
Integer[] a = new Integer[n];
for (int i = 0; i < n; i++)
a[i] = nextInt();
return a;
}
}
| 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;
long n, x, a, b, c;
int main() {
scanf("%ld", &n);
a = b = c = 0;
for (long i = 1; i <= n; i++) {
scanf("%ld", &x);
if (x == 1)
a++;
else if (x == 2)
b++;
else
c++;
}
printf("%ld", n - max(c, max(a, b)));
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())
l=list(map(int,input().split()))
x=l.count(1)
y=l.count(3)
z=l.count(2)
print(n-max(x,y,z))
| 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 = input()
s = raw_input()
print n - max(s.count('1'),s.count('2'),s.count('3')) | PYTHON |
52_A. 123-sequence | There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other.
Input
The first line contains an integer n (1 ≤ n ≤ 106). The second line contains a sequence 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 | /**
* Created by IntelliJ IDEA.
* User: shakhov
* Date: 15.06.2011
* Time: 15:22:46
* To change this template use File | Settings | File Templates.
*/
//6
//86 402 133 524 405 610 6 4 1
import java.io.*;
import java.util.*;
public class CodeForces {
public void solve() throws IOException {
int n=nextInt();
int arr[]={0,0,0};
for(int i=0;i<n;i++){
int c=nextInt();
if(c==1){
arr[0]++;
} else if(c==2){
arr[1]++;
} else {
arr[2]++;
}
}
Arrays.sort(arr);
out.print(arr[0]+arr[1]);
}
private BufferedReader reader;
private StringTokenizer tokenizer;
private String separator;
public PrintWriter out;
public static void main(String[] args) {
new CodeForces().run(new InputStreamReader(System.in), new OutputStreamWriter(System.out));
}
public void run(Reader reader, Writer writer) {
try {
this.reader = new BufferedReader(reader);
out = new PrintWriter(writer);
tokenizer = new StringTokenizer("");
separator = System.getProperty("line.separator");
separator = Character.toString(separator.charAt(separator.length() - 1));
long t1 = System.currentTimeMillis();
solve();
out.flush();
reader.close();
writer.close();
long t2 = System.currentTimeMillis();
System.err.println("Time = " + (t2 - t1));
} catch (Exception e) {
e.printStackTrace();
System.exit(1);
}
}
int nextInt() throws IOException {
return Integer.parseInt(nextToken());
}
long nextLong() throws IOException {
return Long.parseLong(nextToken());
}
double nextDouble() throws IOException {
return Double.parseDouble(nextToken());
}
String nextToken() throws IOException {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
tokenizer = new StringTokenizer(reader.readLine());
}
return tokenizer.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, a = int(input()), input().split()
print(sum(sorted([a.count('1'), a.count('2'), a.count('3')])[:2]))
| 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 | q=int(input())
a = [int(x) for x in input().split()]
n=[0,0,0]
for i in range(q):
n[a[i]-1]+=1
print(q-max(n)) | 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, p = 0, q = 0, v = 0;
cin >> n;
int a[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = 0; i < n; i++) {
if (a[i] == 1) {
v++;
} else if (a[i] == 2) {
p++;
} else {
q++;
}
}
int w = max(v, max(p, q));
if (w == v) {
cout << p + q << endl;
} else if (w == p) {
cout << v + q << endl;
} else {
cout << p + v << 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[1000000];
int num[3];
int main() {
int n;
cin >> n;
for (int i = 0; i < n; ++i) cin >> a[i];
for (int i = 0; i < n; ++i) num[a[i] - 1]++;
int ans = n;
for (int i = 0; i < 3; ++i) {
ans = min(ans, num[i] + num[(i + 1) % 3]);
}
cout << ans << 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 | import java.io.*;
import java.util.*;
public class MAIN{
private static BufferedReader reader = null;
private static BufferedWriter writer = null;
public static void main(String[] args) throws Exception{
reader = new BufferedReader(new InputStreamReader(System.in));
String[] s = reader.readLine().split(" ");
int n = Integer.parseInt(s[0]);
s = reader.readLine().split(" ");
int dp[] = {0,0,0};
for(int i=0;i<n;++i){
++dp[Integer.parseInt(s[i])-1];
}
System.out.println(getSum(dp) - dp[getMaxIndex(dp)]);
}
private static class IntIntPair{
int first;
int second;
public IntIntPair(int first, int second) {
this.first = first;
this.second = second;
}
public IntIntPair getInversePair(){
return new IntIntPair(
this.second,
this.first
);
}
public boolean equals(IntIntPair p){
return p.first == this.first && p.second == this.second;
}
}
private static class StringStringPair{
String first;
String second;
public StringStringPair(String first, String second) {
this.first = first;
this.second = second;
}
public StringStringPair getInversePair(){
return new StringStringPair(
this.second,
this.first
);
}
public boolean equals(StringStringPair p){
return p.first.equals(this.first) && p.second.equals(this.second);
}
}
private static class StringIntPair{
String first;
int second;
public StringIntPair(String first, int second) {
this.first = first;
this.second = second;
}
public boolean equals(StringIntPair p){
return p.first.equals(this.first) && p.second == this.second;
}
}
private static List<List<Integer>> getCombinations(int[] a, int count){
List<List<Integer>> ret = new ArrayList<>(0);
if(a == null || a.length > 64 || count <= 0 || count > a.length){
return null;
} else {
long lim = (1L<<a.length);
for(long i=0;i<lim;++i){
List<Integer> poss = getBitPositionList(i);
if(poss.size() == count){
List<Integer> list = new ArrayList<>(0);
for(int j=0;j< poss.size();++j){
list.add(a[poss.get(j)]);
}
ret.add(list);
}
}
}
return ret;
}
private static int getBitCount(long n){
int onCount = 0;
for(long i=0L;i<64L;++i){
if((n&(1L<<i)) != 0){
++onCount;
}
}
return onCount;
}
private static List<Integer> getBitPositionList(long n){
List<Integer> idxs = new ArrayList<>(0);
for(long i=0L;i<64L;++i){
if((n&(1L<<i)) != 0){
idxs.add(((int) i));
}
}
return idxs;
}
private static IntIntPair getIrreducibleFraction(int x, int y){
int min = (x <= y) ? x : y;
for(int i=2; i<=min; ++i){
while (x%i==0 && y%i==0){
x = x/i;
y = y/i;
}
}
return new IntIntPair(x,y);
}
private static int getDigitSumInBase(int n, int b){
int sum = 0;
while (true){
sum += n%b;
n = n/b;
if(n==0){
break;
}
}
return sum;
}
private static List<Integer> getSegmentedPrimes(int start, int end){
List<Integer> ret = new ArrayList<>(0);
List<Integer> primes = getPrimes(((int) Math.ceil(Math.sqrt(end))));
boolean[] flags = new boolean[(end-start+1)+1];
for(int i=0; i< flags.length; ++i){
flags[i] = true;
}
for(int i=0;i< primes.size();++i){
int lLim = (start / primes.get(i)) * primes.get(i);
while (lLim< start) {
lLim += primes.get(i);
}
for (int j = lLim; j <= end; j += primes.get(i)){
flags[j- start] = false;
}
}
for(int i = start; i<= end; ++i){
if(flags[i- start]){
ret.add(i);
}
}
return ret;
}
private static List<Integer> getPrimes(int n){
List<Integer> primes = new ArrayList<>(0);
boolean[] flags = new boolean[n+1];
for(int i=0; i<flags.length; ++i){
flags[i] = true;
}
flags[0] = false;
flags[1] = false;
for(int i=2;i*i<=n;++i){
if(flags[i]){
for(int j = i*i; j <= n; j += i){
flags[j] = false;
}
}
}
for(int i=0, len = n+1; i < len; ++i){
if(flags[i]){
primes.add(i);
}
}
return primes;
}
private static boolean isPrime(int n){
if(n<=1){
return false;
} else if(n==2){
return true;
} else {
for(int i=2;i<n;++i){
if(n%i == 0){
return false;
}
}
}
return true;
}
private static void displayArray(int[] A, String header){
System.out.println(header);
for (int i=0;i<A.length; ++i){
System.out.println(A[i]);
}
}
private static void displayList(List<Integer> L, String header){
System.out.println(header);
for (int i=0;i<L.size(); ++i){
System.out.println(L.get(i));
}
}
private static void swap(boolean[] arr, int i1, int i2){
boolean tmp = arr[i1];
arr[i1] = arr[i2];
arr[i2] = tmp;
}
private static int getMaxIndex(int[] a){
int MAX = Integer.MIN_VALUE;
int ret = 0;
for(int i=0;i<a.length;++i){
if(a[i] >= MAX){
MAX = a[i];
ret = i;
}
}
return ret;
}
private static int getSum(int[] a){
int sum = 0;
for(int i=0; i<a.length;++i){
sum += a[i];
}
return sum;
}
} | 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()))
one=0
two=0
three=0
for i in a:
if(i==1):
one+=1
elif(i==2):
two+=1
elif(i==3):
three+=1
one_two=one+two
one_three=one+three
two_three=two+three
print(min(one_two,one_three,two_three))
| PYTHON3 |
52_A. 123-sequence | There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other.
Input
The first line contains an integer n (1 ≤ n ≤ 106). The second line contains a sequence 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())
seq = [int(i) for i in input().split(' ')]
count = [seq.count(1), seq.count(2), seq.count(3)]
print(abs(max(count)-n))
| 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.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[3];
for (int i = 0; i < n; i++) {
a[nextByte()-1]++;
}
a[0] = Math.max(a[0], a[1]);
a[1] = Math.max(a[0], a[2]);
System.out.println(n-a[1]);
}
////////////////////// 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 | import java.awt.Point;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.math.MathContext;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Deque;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Random;
import java.util.Set;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.TreeSet;
import javax.swing.text.StyledEditorKit.ItalicAction;
import static java.lang.Double.*;
import static java.lang.Integer.*;
import static java.math.BigInteger.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;
public class Main implements Runnable {
private void solve() throws IOException {
// long start = System.currentTimeMillis();
readData();
processing();
}
private void processing() {
}
private void readData() throws IOException {
n = nextInt();
int[] a = new int[4];
fill(a, 0);
for (int i = 0; i < n; ++i) {
++a[nextInt()];
}
int sum = 0;
int mv = 0;
for (int i = 0; i < 4; ++i) {
sum += a[i];
mv = max(mv, a[i]);
}
println(sum - mv);
}
private int n;
private int k;
private int c;
private int[] holidays;
public static void main(String[] args) throws InterruptedException {
new Thread(null, new Runnable() {
public void run() {
new Main().run();
}
}, "1", 1 << 24).start();
}
// @Override
public void run() {
try {
boolean onlineJudge = System.getProperty("ONLINE_JUDGE") != null;
reader = onlineJudge ? new BufferedReader(new InputStreamReader(
System.in)) : new BufferedReader(
new FileReader("input.txt"));
writer = onlineJudge ? new PrintWriter(new BufferedWriter(
new OutputStreamWriter(System.out))) : new PrintWriter(
new BufferedWriter(new FileWriter("output.txt")));
Locale.setDefault(Locale.US);
tokenizer = null;
solve();
writer.flush();
} catch (Exception error) {
error.printStackTrace();
System.exit(1);
}
}
private BufferedReader reader;
private PrintWriter writer;
private StringTokenizer tokenizer;
private void println() {
writer.println();
}
private void print(long value) {
writer.print(value);
}
private void println(long value) {
writer.println(value);
}
private void print(char ch) {
writer.print(ch);
}
private void println(String s) {
writer.println(s);
}
private void print(String s) {
writer.print(s);
}
private void print(int value) {
writer.print(value);
}
private void println(int value) {
writer.println(value);
}
private void printf(String f, double d) {
writer.printf(f, d);
}
private int nextInt() throws IOException {
return Integer.parseInt(nextToken());
}
private long nextLong() throws IOException {
return Long.parseLong(nextToken());
}
private double nextDouble() throws IOException {
return Double.parseDouble(nextToken());
}
private String nextToken() throws IOException {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
tokenizer = new StringTokenizer(reader.readLine());
}
return tokenizer.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=int(input())
arr = [int(i) for i in input().split()]
min=arr.count(2)+arr.count(3)
if min>(arr.count(1)+arr.count(3)):
min=arr.count(1)+arr.count(3)
if min>(arr.count(1)+arr.count(2)):
min=(arr.count(1)+arr.count(2))
print(min)
| 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>
int main() {
int n, c = 0;
scanf("%d", &n);
int a[3];
int i;
for (i = 0; i < 3; i++) a[i] = 0;
for (i = 0; i < n; i++) {
int x;
scanf("%d", &x);
if (x == 1)
a[0]++;
else if (x == 2)
a[1]++;
else
a[2]++;
}
int max = 0;
if (a[0] >= a[1] && a[0] >= a[2])
max = 0;
else if (a[1] >= a[0] && a[1] >= a[2])
max = 1;
else
max = 2;
for (i = 0; i < 3; i++)
if (i != max) c += a[i];
printf("%d\n", c);
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;
void scanint(int &x) {
register int c = getchar();
x = 0;
int neg = 0;
for (; ((c < 48 || c > 57) && c != '-'); c = getchar())
;
if (c == '-') {
neg = 1;
c = getchar();
}
for (; c > 47 && c < 58; c = getchar()) {
x = (x << 1) + (x << 3) + c - 48;
}
if (neg) x = -x;
}
int main() {
std::ios::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
int i, x, a[3] = {0, 0, 0};
for (i = 0; i < n; i++) {
cin >> x;
a[x - 1]++;
}
sort(a, a + 3);
cout << a[0] + a[1] << 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 |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class A {
public static void main(String[] args) throws IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
in.readLine();
String[] S = in.readLine().split(" ");
int[] A = new int[3];
for (int i = 0; i < S.length; i++)
A[S[i].charAt(0) - '1']++;
int ans = 0;
for (int i = 0; i < 3; i++)
ans = Math.max(ans, A[i]);
System.out.println(S.length - 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;
int n, s[1000000];
int main() {
scanf("%d", &n);
for (int x, i = 1; i <= n; i++) scanf("%d", &x), s[x]++;
cout << n - max(s[1], max(s[2], s[3]));
}
| 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 | __author__ = 'dwliv_000'
n=int(input())
c={}
c[1]=0
c[2]=0
c[3]=0
s=input().split()
for j in s:
c[int(j)]+=1
print(n-max(c.values())) | 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=input().split()
s1=s2=s3=0
for i in range(0,len(a)):
if int(a[i])==1:
s1+=1
elif int(a[i])==2:
s2+=1
else:
s3+=1
if s1==max(s1,s2,s3):
print(s2+s3)
elif s2==max(s1,s2,s3):
print(s1+s3)
else:
print(s1+s2) | 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.util.*;
import java.math.*;
public class Z implements Runnable{
BufferedReader in;
StringTokenizer st;
PrintWriter out;
String FileName = "input";
void solve() throws IOException{
int n = nextInt();
int[] a = new int[4];
for(int i = 0; i < n; i++)
a[nextInt()]++;
if(a[1] > a[2] && a[1] > a[3])
out.print(a[2] + a[3]);
else
if(a[2] > a[3])
out.print(a[1] + a[3]);
else
out.print(a[1] + a[2]);
}
public void run() {
try {
in = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
eat("");
solve();
out.close();
in.close();
} catch (IOException ex) {
throw new RuntimeException(ex);
}
}
void eat(String s) {
st = new StringTokenizer(s);
}
String next() throws IOException {
while (!st.hasMoreTokens()) {
String line = in.readLine();
if (line == null) {
return null;
}
eat(line);
}
return st.nextToken();
}
int nextInt() throws IOException {
return Integer.parseInt(next());
}
long nextLong() throws IOException {
return Long.parseLong(next());
}
double nextDouble() throws IOException {
return Double.parseDouble(next());
}
public static void main(String[] args) {
Locale.setDefault(Locale.US);
new Thread(new Z()).start();
}
}
| 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.*;
public class A
{
public static void main(String[] args)
{
Scanner inp = new Scanner(System.in);
int a[] = new int[3];
int n = inp.nextInt();
String st;
for(int i = 0 ; i < n ; i++)
{
st = inp.next();
if(st.equals("1")) a[0]++;
else if(st.equals("2"))a[1]++;
else a[2]++;
}
Arrays.sort(a);
System.out.println(a[0] + a[1]);
}
}
| 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 Change{
public static int change(int n, int elem[]){
int [] c = {0,0,0};
for (int i = 0; i < n; i++){
switch(elem[i]){
case 1:c[0]++;break;
case 2:c[1]++;break;
case 3:c[2]++;break;
}
}
int max ;
if ( (c[0] >= c[1]) && (c[0] >= c[2]))
max = c[0];
else{
if ( (c[1] >= c[0]) && (c[1] >= c[2]))
max = c[1];
else
max = c[2];
}
return n - max;
}
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int [] elem = new int [(int)Math.pow(10,6)];
for (int i = 0; i < n; i++){
elem[i] = sc.nextInt();
}
System.out.println(change(n,elem));
}
}
| 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;
map<int, int> d;
for (int i = 0; i < n; ++i) {
int in;
scanf("%d", &in);
d[in]++;
}
if (d.size() == 1) {
cout << 0 << endl;
} else if (d.size() == 2) {
int ans = 10000000;
for (auto it = d.begin(); it != d.end(); it++) {
ans = min(ans, it->second);
}
cout << ans << endl;
} else {
cout << min(d[1] + d[2], min(d[2] + d[3], d[1] + d[3])) << 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 | n=int(input())
l=[int(x) for x in input().split()]
one=l.count(1)
two=l.count(2)
print(n-max(one, two, n-one-two)) | 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().strip().split()[:n]))
a1=l.count(1)
a2=l.count(2)
a3=l.count(3)
if a1>=a2 and a1>=a3:print(a3+a2)
elif a2>=a1 and a2>=a3:print(a1+a3)
elif a3>=a2 and a3>=a1:print(a1+a2)
else:
print(n-(max(a1,a3,a2))) | 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 | 'use strict'
let N = +readline()
let lll = readline().split(' ').map(v => parseInt(v))
let c = [0, 0, 0]
for (let i = 0; i < N; i++) {
c[lll[i] - 1]++
}
print(c[0] + c[1] + c[2] - Math.max(c[0], c[1], c[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 main() {
int n, a1 = 0, a2 = 0, a3 = 0, i;
cin >> n;
int arr[n];
for (i = 0; i < n; i++) cin >> arr[i];
for (i = 0; i < n; i++) {
if (arr[i] == 1)
a1++;
else if (arr[i] == 2)
a2++;
else
a3++;
}
int res;
res = min(a1 + a2, min(a2 + a3, a1 + a3));
cout << res;
}
| 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 mas[3] = {0, 0, 0};
int tmp;
for (int i = 0; i < n; ++i) {
cin >> tmp;
mas[tmp - 1]++;
}
sort(mas, mas + 3);
cout << mas[0] + mas[1];
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.Arrays;
import java.util.Scanner;
public class Q {
public static void main(String[]args){
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int[]A = new int[n];
for (int i = 0; i<n;i++){
A[i] = sc.nextInt();
}
int q1 = 0;
int q2 = 0;
int q3 = 0;
for (int i = 0; i<n; i++){
if (A[i]==1){q1++;}
if (A[i]==2){q2++;}
if (A[i]==3){q3++;}
}
int []AAA = new int[]{q1, q2, q3};
Arrays.sort(AAA);
System.out.println(n-AAA[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 | # Codeforces Testing Round #1
# Problem A -- 123-sequence
n = input()
a = map(int, raw_input().split())
print n - max(a.count(1), max(a.count(2), a.count(3))) | PYTHON |
52_A. 123-sequence | There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other.
Input
The first line contains an integer n (1 ≤ n ≤ 106). The second line contains a sequence 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())
int_arr = [int(num) for num in input().split()]
counts_dict = {}
for num in int_arr:
counts_dict[num] = counts_dict.get(num, 0) + 1
print(n - max(counts_dict.values())) | 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;
long long a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w,
x, y, z, ed, maxi, maxj, mini, minj, sum, res;
long long aa[100007], bb[10007];
long double d1, d2, d3, d4, d5, d6, d7, d8, d9, d0;
string s1, s2, s3, s4, s5, s6, s7, s8, s9, s0;
set<long long> sl1, sl2, sl3;
set<string> ss1, ss2, ss3;
char c1, c2;
map<string, long long> msl1, msl2, msl3;
map<string, string> mss1, mss2, mss3;
map<char, long long> mcl1, mcl2, mcl3;
map<long long, long long> mll1, mll2, mll3;
int main() {
cin >> n;
for (i = 1; i <= n; i++) {
cin >> x;
if (x == 1) a++;
if (x == 2) b++;
if (x == 3) c++;
}
if (a >= b && a >= c)
cout << b + c << endl;
else if (b >= a && b >= c)
cout << a + c << endl;
else if (c >= a && c >= b)
cout << a + b << 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 | n=int(input());s=input().split()
print(min(n-s.count('1'),n-s.count('2'),n-s.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 ar[5];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
int ans = n, mx = 0;
while (n--) {
int a;
cin >> a;
ar[a]++;
}
for (int i = 1; i <= 3; i++) mx = max(mx, ar[i]);
cout << ans - mx << 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>
using namespace std;
int main() {
int n;
cin >> n;
int n1 = n;
int count1 = 0;
int count2 = 0;
int count3 = 0;
while (n1--) {
int g;
cin >> g;
if (g == 1)
count1++;
else if (g == 2)
count2++;
else if (g == 3)
count3++;
}
int x1 = max(count1, count2);
int x = max(x1, count3);
int answer = n - x;
cout << abs(answer) << endl;
return 0;
}
| CPP |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.