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
import java.util.*; import java.lang.Math; public class index { static int biggestOfThree(int x, int y, int z) { if (x >= y && x >= z) // Returning 1st number if largest return x; // Comparing 2nd no with 1st and 3rd no else if (y >= x && y >= z) // Return z if the above conditions are false return y; else // Returning 3rd no, Its sure it is greatest return z; } public static void main(String[] args) { Scanner cin = new Scanner(System.in); int input = cin.nextInt(); int[] inputArray = new int[input]; int countOfOne = 0; int countOfTwo = 0; int countOfThree = 0; for (int i = 0; i < input; i++) { inputArray[i] = cin.nextInt(); if (inputArray[i] == 1) countOfOne++; else if (inputArray[i] == 2) countOfTwo++; else countOfThree++; } int result = input - (biggestOfThree(countOfOne, countOfTwo, countOfThree)); System.out.println(result); cin.close(); } }
JAVA
52_A. 123-sequence
There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. Input The first line contains an integer n (1 ≤ n ≤ 106). The second line contains a sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 3). Output Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. Examples Input 9 1 3 2 2 2 1 1 2 3 Output 5 Note In the example all the numbers equal to 1 and 3 should be replaced by 2.
2
7
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string numbers[n]; for (int i = 0; i < n; i++) { cin >> numbers[i]; } int max1 = 0; int max2 = 0; int max3 = 0; int result = 55; for (int i = 0; i < n; i++) { if (numbers[i] == "1") max1++; else if (numbers[i] == "2") max2++; else if (numbers[i] == "3") max3++; } if (max1 >= max2 && max1 >= max3) result = max2 + max3; if (max2 >= max1 && max2 >= max3) result = max1 + max3; if (max3 >= max1 && max3 >= max2) result = max1 + max2; cout << result; }
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 max(int x, int y, int z) { int max; if (x >= y) max = x; else max = y; if (z >= max) max = z; return max; } int main() { int n; int m = 0, g = 0, t = 0; cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; if (a[i] == 1) m++; else if (a[i] == 2) t++; else g++; } cout << n - max(t, g, m); 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 x, u[5], n, Max; int main() { scanf("%d", &n); for (int i = 1; i <= n; ++i) scanf("%d", &x), u[x]++, Max = max(u[x], Max); printf("%d", 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
#include <bits/stdc++.h> using namespace std; int main() { int n, tmp, one = 0, two = 0, three = 0, m; cin >> n; for (int i = 0; i < n; i++) { cin >> tmp; if (tmp == 1) one++; if (tmp == 2) two++; if (tmp == 3) three++; } m = max(one, max(two, three)); cout << n - m; 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
//package dbarrie.codeforces.beginner; import java.util.Scanner; /* * Codeforces 123 Problem - Difficulty 900 * * https://codeforces.com/problemset/problem/52/A */ public class OneTwoThreeProblem { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int[] arr = new int[3]; for(int i = 0; i < n; i++) { arr[sc.nextInt() - 1] ++; } System.out.println(n - Math.max(arr[0], Math.max(arr[1], arr[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; const int inf = 100000000; const double eps = 0.000001; int main() { int n; cin >> n; vector<int> a(n), res(3, 0); for (int i = 0; i < n; i++) { cin >> a[i]; res[a[i] - 1]++; } cout << res[0] + res[1] + res[2] - max(res[0], max(res[1], res[2])); return 0; }
CPP
52_A. 123-sequence
There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. Input The first line contains an integer n (1 ≤ n ≤ 106). The second line contains a sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 3). Output Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. Examples Input 9 1 3 2 2 2 1 1 2 3 Output 5 Note In the example all the numbers equal to 1 and 3 should be replaced by 2.
2
7
#include <bits/stdc++.h> int main() { int n, i, c[3] = {0}, x, max; scanf("%d", &n); for (i = 0; i < n; i++) { scanf("%d", &x); c[x - 1]++; } max = c[0]; i = 0; if (c[1] > max) { max = c[1]; i = 1; } if (c[2] > max) { max = c[2]; i = 2; } c[i] = 0; printf("%d\n", c[0] + c[1] + c[2]); }
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 Sequence123 { public static void main(String[] args) throws NumberFormatException, IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(br.readLine()); String line = br.readLine(); String[] ls = line.split(" "); int c[] = new int[3]; for (String l: ls) { int ln = Integer.parseInt(l.trim()); c[ln - 1] ++; } int res = 0; for (int ln: c) { if (ln > res) { res = ln; } } System.out.println(n - res); } }
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().split() s1 = s.count('1') s2 = s.count('2') s3 = n - s1 - s2 print n - max(s1,s2,s3)
PYTHON
52_A. 123-sequence
There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. Input The first line contains an integer n (1 ≤ n ≤ 106). The second line contains a sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 3). Output Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. Examples Input 9 1 3 2 2 2 1 1 2 3 Output 5 Note In the example all the numbers equal to 1 and 3 should be replaced by 2.
2
7
#include <bits/stdc++.h> using namespace std; int n, x, one, two, three; int main() { cin >> n; for (int i = 1; i <= n; i++) { cin >> x; if (x == 1) one++; else if (x == 2) two++; else 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
#include <bits/stdc++.h> using namespace std; int n, b; int a[5]; int main() { cin >> n; for (int i = 0; i < n; ++i) { cin >> b; a[b]++; } cout << min(min(a[2] + a[3], a[1] + a[2]), a[1] + a[3]); return 0; }
CPP
52_A. 123-sequence
There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. Input The first line contains an integer n (1 ≤ n ≤ 106). The second line contains a sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 3). Output Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. Examples Input 9 1 3 2 2 2 1 1 2 3 Output 5 Note In the example all the numbers equal to 1 and 3 should be replaced by 2.
2
7
#include <bits/stdc++.h> using namespace std; int ar1[1000][1000], ar2[10000000]; int re1 = 0, re2 = 0; int test = 0; int main() { int a = 0, b = 0, c = 0, d = 0, result = 0; scanf("%d", &a); for (int i = 1; i <= a; i++) { scanf("%d", &result); if (result == 1) { b++; } else if (result == 2) { c++; } else { d++; } } result = max(b, c); result = max(result, d); result = b + c + d - result; printf("%d", result); }
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 num[3]; int main() { int n; int tmp; for (int i = 1; i <= 3; i++) num[i] = 0; scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d", &tmp); num[tmp]++; } cout << n - max(num[1], max(num[2], num[3])) << endl; }
CPP
52_A. 123-sequence
There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. Input The first line contains an integer n (1 ≤ n ≤ 106). The second line contains a sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 3). Output Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. Examples Input 9 1 3 2 2 2 1 1 2 3 Output 5 Note In the example all the numbers equal to 1 and 3 should be replaced by 2.
2
7
#include <bits/stdc++.h> using namespace std; int n; int a[4]; int main() { ios::sync_with_stdio(false); cin >> n; int t; for (int i = 1; i <= n; i++) cin >> t, a[t]++; cout << min(a[1] + a[2], min(a[2] + a[3], a[3] + a[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
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a1 = 0, a2 = 0, a3 = 0; int num; for (int i = 0; i < n; i++) { cin >> num; if (num == 1) a1++; else if (num == 2) a2++; else a3++; } if (a1 >= a2 && a1 >= a3) cout << a2 + a3; else if (a2 >= a1 && a2 >= a3) cout << a1 + a3; else cout << a1 + a2; 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.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 i = 1; int a[] = new int[4]; while(i <= n) { a[nextByte()]++; i++; } 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(input()) arr=list(map(int,input().split())) s1=arr.count(1) s2=arr.count(2) s3=arr.count(3) print(n-max(s1,s2,s3))
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(raw_input()) lst = map(int, raw_input().split()) one = 0 two = 0 three = 0 for i in range(n): if lst[i] == 1: one += 1 elif lst[i] == 2: two += 1 else: three += 1 a = one + two b = one + three c = two + three lst2 = [] lst2.append(a) lst2.append(b) lst2.append(c) lst2.sort() print(lst2[0])
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; struct wnr { char val; char pos; }; void solve() { long long int n; cin >> n; long long int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } long long int cnt1 = 0; long long int cnt2 = 0; long long int cnt3 = 0; for (int i = 0; i < n; i++) { if (a[i] == 1) { cnt1++; } else if (a[i] == 2) { cnt2++; } else if (a[i] == 3) { cnt3++; } } int b[3]; b[0] = cnt1; b[1] = cnt2; b[2] = cnt3; sort(b, b + 3); cout << b[0] + b[1] << endl; } int main() { { solve(); } }
CPP
52_A. 123-sequence
There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. Input The first line contains an integer n (1 ≤ n ≤ 106). The second line contains a sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 3). Output Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. Examples Input 9 1 3 2 2 2 1 1 2 3 Output 5 Note In the example all the numbers equal to 1 and 3 should be replaced by 2.
2
7
import java.util.Scanner; public class Main { public static void main (String [] args) { Scanner input = new Scanner(System.in); String length=input.nextLine(); int numberone=Integer.parseInt(length); int one=0,two=0,three=0; String [] inputtwo=input.nextLine().split(" "); for(int i =0 ; i <numberone;i++) { switch (Integer.parseInt(inputtwo[i])) { case 1: one+=1; break; case 2: two+=1; break; case 3: three+=1; break; } } if(numberone==1) { System.out.println(0); } else { if(numberone>2) { int max = Math.max(one, Math.max(two, three)); if(max==one) { System.out.println(three+two); } else if(max==three) { System.out.println(two+one); } else if(max == two) { System.out.println(three+one); } } else { System.out.println(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.*; public class Main{ public static void main(String args[]){ Scanner sc=new Scanner(System.in); int size=sc.nextInt(); int[] arr=new int[3]; for(int i=0;i<size;i++){ int temp=sc.nextInt(); arr[temp-1]++; } int max=0; int place=-1; for(int i=0;i<3;i++){ if(max<arr[i]){ place=i; max=arr[i]; } } int res=0; for(int i=0;i<3;i++){ if(place!=i)res+=arr[i]; } System.out.println(res); } }
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=raw_input();print n-max(a.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; template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; } int main() { int N; scanf("%d", &N); int cnt[3] = {}; for (int i = 0; i < (int)(N); ++i) { int a; scanf("%d", &a); ++cnt[a - 1]; } cout << (N - *max_element(cnt, cnt + 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
#include <bits/stdc++.h> using namespace std; int main() { long long n, one = 0, two = 0, three = 0; scanf("%lld", &n); for (int i = 0; i < n; ++i) { int a; scanf("%d", &a); if (a == 1) { one++; } else if (a == 2) { two++; } else { three++; } } int a = one + two; int b = two + three; int c = one + three; int cnt = min(a, b); cnt = min(cnt, c); printf("%d", cnt); 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[5]; int n, b; int main() { cin >> n; for (int i = 1; i <= n; i++) { cin >> b; a[b]++; } sort(a, a + 3 + 1); cout << a[1] + a[2]; return 0; }
CPP
52_A. 123-sequence
There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. Input The first line contains an integer n (1 ≤ n ≤ 106). The second line contains a sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 3). Output Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. Examples Input 9 1 3 2 2 2 1 1 2 3 Output 5 Note In the example all the numbers equal to 1 and 3 should be replaced by 2.
2
7
n = int(input()) arr = list(map(int,input().split())) h = {} for i in arr: if (i in h): h[i] += 1 else: h[i] = 1 print(n-max(h.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; int n, s[4]; int main() { scanf("%d", &n); for (register int x, i = 1; i <= n; ++i) scanf("%d", &x), ++s[x]; return cout << n - max(s[1], max(s[2], s[3])), 0; }
CPP
52_A. 123-sequence
There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. Input The first line contains an integer n (1 ≤ n ≤ 106). The second line contains a sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 3). Output Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. Examples Input 9 1 3 2 2 2 1 1 2 3 Output 5 Note In the example all the numbers equal to 1 and 3 should be replaced by 2.
2
7
#include <bits/stdc++.h> const double PI = acos(-1.0); const int MAXN = 1000010; int flg[4], n; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) { int x; scanf("%d", &x); flg[x]++; } int max = std::max(flg[1], std::max(flg[2], flg[3])); printf("%d\n", 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
import java.util.Scanner; import java.util.*; public class Main { static char arr[][]; public static void main(String[] args) { // 19 20 30 Scanner s = new Scanner(System.in); int n = Integer.parseInt(s.nextLine()); int freq[] = new int[4]; String line[] = s.nextLine().split(" "); for (int i=0;i < n;i++) freq[Integer.parseInt(line[i])]++; System.out.println( Math.min(n - freq[1], Math.min(n - freq[2], n - freq[3])) ); }//main }//class
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 { Scanner in = new Scanner(System.in); int N = in.nextInt(); int[] freq = new int[3]; in.nextLine(); String[] tmp = in.nextLine().split(" "); for (int i=0; i<N; i++) freq[Integer.parseInt(tmp[i])-1]++; System.out.println(Math.min(Math.min(N-freq[0],N-freq[1]),N-freq[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> int main() { int n, s, a = 0, b = 0, c = 0, i, j, k; scanf("%d", &n); for (i = 0; i < n; i++) { scanf("%d", &s); if (s == 1) { a++; } else if (s == 2) { b++; } else { c++; } } if (a >= b && a >= c) { j = a; } else if (b >= c && b >= a) { j = b; } else { j = c; } printf("%d", n - j); return 0; }
CPP
52_A. 123-sequence
There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. Input The first line contains an integer n (1 ≤ n ≤ 106). The second line contains a sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 3). Output Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. Examples Input 9 1 3 2 2 2 1 1 2 3 Output 5 Note In the example all the numbers equal to 1 and 3 should be replaced by 2.
2
7
#include <bits/stdc++.h> using namespace std; const long long int maxn = 1e5 + 1; long long int a[maxn], dp[maxn], n, m, d[maxn], z, p; vector<long long> g[maxn]; bool mark[maxn]; int main() { ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); cin >> n; for (int i = 0; i < n; i++) { cin >> z; if (z == 1) a[1]++; else if (z == 2) a[2]++; else a[3]++; } if (a[1] >= a[2] && a[1] >= a[3]) return cout << n - a[1], 0; if (a[2] >= a[3] && a[2] >= a[1]) return cout << n - a[2], 0; cout << n - a[3]; return 0; }
CPP
52_A. 123-sequence
There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. Input The first line contains an integer n (1 ≤ n ≤ 106). The second line contains a sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 3). Output Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. Examples Input 9 1 3 2 2 2 1 1 2 3 Output 5 Note In the example all the numbers equal to 1 and 3 should be replaced by 2.
2
7
numof_input = input() s = raw_input() s = s.split(" ") num1 = 0 num2 = 0 num3 = 0 for i in s: int_i = int(i) if int_i == 1: num1 += 1 if int_i == 2: num2 += 1 if int_i == 3: num3 += 1 re = 0 if num1 >= num2 and num1 >= num3: re = numof_input - num1 if num2 >= num1 and num2 >= num3: re = numof_input - num2 if num3 >= num1 and num3 >= num2: re = numof_input - num3 print re
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
l=lambda:map(int,raw_input().split()) n=input() a=l() d={1:0,2:0,3:0} for x in a: d[x]+=1 print n-max(d.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 sys, math, operator, itertools, collections, heapq, bisect # sys.setrecursionlimit(10**4) class Solution: def __init__(self): pass def solve(self, *Input): cnt = collections.Counter(Input[0]) print(min(cnt[1]+cnt[2],cnt[2]+cnt[3],cnt[3]+cnt[1])) def create(self, *Input): n,colors = Input color_set = set() tree = [set()] for i in range(1,n+1): color_set.add(colors[i-1]) tree.append(color_set - tree[i & (i-1)]) return tree def check(self, *Input): k,matrix = Input cnt = 0 for row in matrix: cnt += row.count('#') return cnt == k def sieve_classic(self,a,b): self.primes = [True] * (b+1) self.primes[0] = self.primes[1] = False for i in range(2,b+1): if self.primes[i] and i*i <= b: for j in range(i*i,b+1,i): self.primes[j] = False self.primes = [x for x,y in enumerate(self.primes) if y] ind = bisect.bisect_left(self.primes,a) self.primes[:ind] = [] return None if __name__=='__main__': solution = Solution() inputs = iter(sys.stdin.readlines()) n = int(next(inputs)) a = list(map(int, next(inputs).split())) ans = solution.solve(a) # print(ans)
PYTHON3
52_A. 123-sequence
There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. Input The first line contains an integer n (1 ≤ n ≤ 106). The second line contains a sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 3). Output Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. Examples Input 9 1 3 2 2 2 1 1 2 3 Output 5 Note In the example all the numbers equal to 1 and 3 should be replaced by 2.
2
7
#include <bits/stdc++.h> using namespace std; int main() { int a[1000] = {0}, b, c, d, i, j, m; cin >> m; c = 0; for (i = 0; i < m; i++) { cin >> b; a[b]++; if (c < b) { c = b; } } b = 0; d = 0; for (i = 1; i <= c; i++) { b = b + a[i]; if (d < a[i]) { d = a[i]; } } cout << b - 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
N = int( input() ) A = list( map( int, input().split() ) ) cnt = [ 0 for i in range( 3 + 1 ) ] for i in range( N ): cnt[ A[ i ] ] += 1 print( N - max( cnt ) )
PYTHON3
52_A. 123-sequence
There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. Input The first line contains an integer n (1 ≤ n ≤ 106). The second line contains a sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 3). Output Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. Examples Input 9 1 3 2 2 2 1 1 2 3 Output 5 Note In the example all the numbers equal to 1 and 3 should be replaced by 2.
2
7
a = int(input()) b = list(map(int,input().split())) count1 = 0 count2 = 0 count3 = 0 for i in range(a): if b[i] == 1: count1 +=1 elif b[i] == 2: count2 +=1 else: count3+=1 sum1 = count1+count2 sum2 = count3 + count2 sum3 = count1 +count3 print(min(sum1,sum2,sum3))
PYTHON3
52_A. 123-sequence
There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. Input The first line contains an integer n (1 ≤ n ≤ 106). The second line contains a sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 3). Output Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. Examples Input 9 1 3 2 2 2 1 1 2 3 Output 5 Note In the example all the numbers equal to 1 and 3 should be replaced by 2.
2
7
var n=parseInt(readline()); var a=readline().split(" ").map(e=>+e); var aa = [0, 0, 0, 0]; a.map(e => aa[e]++); aa.sort((a,b)=>b-a); print(n-aa[0]);
JAVA
52_A. 123-sequence
There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. Input The first line contains an integer n (1 ≤ n ≤ 106). The second line contains a sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 3). Output Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. Examples Input 9 1 3 2 2 2 1 1 2 3 Output 5 Note In the example all the numbers equal to 1 and 3 should be replaced by 2.
2
7
#include <bits/stdc++.h> using namespace std; int a[4]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int t = 1, tc; long long i, j, k, l, m, n; while (cin >> n) { memset(a, 0, sizeof(a)); for (i = 0; i < n; i++) { cin >> k; a[k]++; } sort(a + 1, a + 4); long long sum = 0; sum += a[1] + a[2]; cout << sum << "\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
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int ones = 0, twos = 0, threes = 0; for (int i = 0; i < n; i++) { int temp; cin >> temp; if (temp == 1) ones++; else if (temp == 2) twos++; else threes++; } int mx = max(ones, max(twos, threes)); cout << n - 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
n=input() a=raw_input() print n-max(a.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
import java.io.*; import java.util.StringTokenizer; /** * _52A * θ(n) time * θ(1) space * * @author artyom */ public class _52A implements Runnable { private BufferedReader in; private PrintStream out; private StringTokenizer tok; private void solve() throws IOException { int[] bv = new int[4]; int n = nextInt(); for (int i = 0; i < n; i++) { bv[nextInt()]++; } int max = getMax(bv); out.print(n - max); } //-------------------------------------------------------------- public static void main(String[] args) { new _52A().run(); } @Override public void run() { try { in = new BufferedReader(new InputStreamReader(System.in)); out = System.out; tok = null; solve(); in.close(); } catch (IOException e) { System.exit(0); } } private String nextToken() throws IOException { while (tok == null || !tok.hasMoreTokens()) { tok = new StringTokenizer(in.readLine()); } return tok.nextToken(); } private int nextInt() throws IOException { return Integer.parseInt(nextToken()); } private long nextLong() throws IOException { return Long.parseLong(nextToken()); } private int[] readIntArray(int n) throws IOException { int[] arr = new int[n]; for (int i = 0; i < n; i++) { arr[i] = nextInt(); } return arr; } private static int getMax(int[] a) { int max = Integer.MIN_VALUE; for (int i = 0, n = a.length; i < n; i++) { if (a[i] > max) { max = a[i]; } } return max; } }
JAVA
52_A. 123-sequence
There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. Input The first line contains an integer n (1 ≤ n ≤ 106). The second line contains a sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 3). Output Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. Examples Input 9 1 3 2 2 2 1 1 2 3 Output 5 Note In the example all the numbers equal to 1 and 3 should be replaced by 2.
2
7
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Arrays; import java.util.Scanner ; import java.util.StringTokenizer; /** * * @author ahmad97 */ public class Main { /** * @param args the command line arguments */ public static void main(String[] args) { FastReader console = new FastReader () ; int n = console.nextInt() ; int x[] = new int [n] ; int count1 = 0 ; int count2 = 0 ; int count3 = 0 ; for (int i=0 ; i<x.length ; i++){ x[i]=console.nextInt() ; if (x[i]==1){ count1++ ; } else if (x[i]==2){ count2 ++ ; } else if (x[i]==3){ count3++ ; } } if (count1==0){ System.out.println(Math.min(count2, count3)); } else if (count2==0){ System.out.println(Math.min(count1, count3)); } else if (count3==0){ System.out.println(Math.min(count1, count2)); } else { int a=count1+count2 ; int b=count1+count3 ; int c=count2+count3 ; int arr[] = {a,b,c} ; Arrays.sort(arr); System.out.println(arr[0]); } } } class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } }
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 Sequence { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int n,i,c1=0,c2=0,c3=0,max; int arr[]=new int[1000000]; n=sc.nextInt(); for(i=0;i<n;i++) arr[i]=sc.nextInt(); for(i=0;i<n;i++) { if(arr[i]==1) c1++; else if(arr[i]==2) c2++; else c3++; } max=((c1>=c2) && (c1>=c3) )? c1 :((c2>=c1) && (c2>=c3) )? c2 :c3; System.out.println(n-max); } }
JAVA
52_A. 123-sequence
There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. Input The first line contains an integer n (1 ≤ n ≤ 106). The second line contains a sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 3). Output Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. Examples Input 9 1 3 2 2 2 1 1 2 3 Output 5 Note In the example all the numbers equal to 1 and 3 should be replaced by 2.
2
7
/** * Created by ankeet on 7/30/16. */ import java.io.BufferedReader; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.StringTokenizer; public class A52 { static FastReader in = null; static PrintWriter out = null; public static void solve() { int n = in.nint(); int[] a = in.narr(n); int[] occ = new int[4]; for(int i=0; i<n; i++) { occ[a[i]]++; } out.println(Math.min(occ[1]+occ[2], Math.min(occ[2]+occ[3],occ[1]+occ[3]))); } public static void main(String[] args) { in = new FastReader(System.in); out = new PrintWriter(System.out); solve(); out.flush(); out.close(); } static class FastReader { BufferedReader read; StringTokenizer tokenizer; public FastReader(InputStream in) { read = new BufferedReader(new InputStreamReader(in)); } public String next() { while(tokenizer == null || !tokenizer.hasMoreTokens()) { try{ tokenizer = new StringTokenizer(read.readLine()); }catch(Exception e){ throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nint() { return Integer.parseInt(next()); } public long nlong() { return Long.parseLong(next()); } public double ndouble() { return Double.parseDouble(next()); } public int[] narr(int n) { int[] a = new int[n]; for(int i=0; i<n; ++i) { a[i] = nint(); } return a; } public long[] nlarr(int n) { long[] a = new long[n]; for(int i=0; i<n; ++i) { a[i] = nlong(); } 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
from collections import Counter lent = input() lis = list(map(int,raw_input().split())) check = Counter(lis) print(lent - check.most_common(1)[0][1])
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 n, cou[3] = {0}, a; scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d", &a); cou[a - 1]++; } sort(cou, cou + 3); printf("%d\n", n - cou[2]); return 0; }
CPP
52_A. 123-sequence
There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. Input The first line contains an integer n (1 ≤ n ≤ 106). The second line contains a sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 3). Output Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. Examples Input 9 1 3 2 2 2 1 1 2 3 Output 5 Note In the example all the numbers equal to 1 and 3 should be replaced by 2.
2
7
n = int(input()) x = [int(i) for i in input().split()] counter1 = x.count(1) counter2 = x.count(2) counter3 = x.count(3) ans = counter1 + counter2 if counter3 + counter2 < ans: ans = counter3 + counter2 if counter3 + counter1 < ans: ans = counter3 + counter1 print(ans)
PYTHON3
52_A. 123-sequence
There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. Input The first line contains an integer n (1 ≤ n ≤ 106). The second line contains a sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 3). Output Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. Examples Input 9 1 3 2 2 2 1 1 2 3 Output 5 Note In the example all the numbers equal to 1 and 3 should be replaced by 2.
2
7
#include <bits/stdc++.h> using namespace std; int a[5]; int main() { int n, x, mx = 0; scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d", &x); a[x]++; } for (int i = 1; i <= 3; i++) { if (a[i] > mx) mx = a[i]; } printf("%d", n - mx); 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 a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } vector<int> arr; int p = 0, q = 0, r = 0; for (int i = 0; i < n; i++) { if (a[i] == 1) p++; if (a[i] == 2) q++; if (a[i] == 3) r++; } arr.push_back(p); arr.push_back(q); arr.push_back(r); sort(arr.begin(), arr.end()); cout << arr[0] + arr[1]; }
CPP
52_A. 123-sequence
There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. Input The first line contains an integer n (1 ≤ n ≤ 106). The second line contains a sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 3). Output Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. Examples Input 9 1 3 2 2 2 1 1 2 3 Output 5 Note In the example all the numbers equal to 1 and 3 should be replaced by 2.
2
7
#include <bits/stdc++.h> int main() { int n, a, r; int c[3] = {}; std::scanf("%d", &n); while (0 < n--) { std::scanf("%d", &a); c[a - 1]++; } r = std::min({c[0] + c[1], c[0] + c[2], c[1] + c[2]}); std::printf("%d\n", r); 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
/****************************************************************************** Welcome to GDB Online. GDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl, C#, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog. Code, Compile, Run and Debug online from anywhere in world. *******************************************************************************/ import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int arr[] = new int[3]; for(int i = 0;i<n;i++) { int val = sc.nextInt(); if(val == 1) arr[0]++; if(val == 2) arr[1]++; if(val == 3) arr[2]++; } int max = -1; for(int i = 0;i<3;i++) { if(arr[i] > max) max = arr[i]; } System.out.println(n - max); } }
JAVA
52_A. 123-sequence
There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. Input The first line contains an integer n (1 ≤ n ≤ 106). The second line contains a sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 3). Output Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. Examples Input 9 1 3 2 2 2 1 1 2 3 Output 5 Note In the example all the numbers equal to 1 and 3 should be replaced by 2.
2
7
n = int(input()) nums = input() a = nums.count("1") b = nums.count("2") c = nums.count("3") d = (a, b, c) e = sorted(d)[0]+sorted(d)[1] print(e)
PYTHON3
52_A. 123-sequence
There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. Input The first line contains an integer n (1 ≤ n ≤ 106). The second line contains a sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 3). Output Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. Examples Input 9 1 3 2 2 2 1 1 2 3 Output 5 Note In the example all the numbers equal to 1 and 3 should be replaced by 2.
2
7
if __name__ == "__main__": n = int(input()) numbers = list(map(int,input().split())) uno = numbers.count(1) dos = numbers.count(2) tres = numbers.count(3) if uno >= dos and uno >= tres: print(dos+tres) elif dos >= uno and dos >= tres: print(uno + tres) elif tres >= dos and tres >= uno: print(uno + dos)
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
def calculate(list1): ones=0 twos=0 threes=0 for i in list1: if i==1: ones=ones+1 elif i==2: twos= twos+1 else: threes += 1 if (ones>twos and ones> threes): return 1 elif (twos>ones and twos>threes): return 2 elif (threes>ones and threes>twos): return 3 elif (ones==threes): return 3 elif (twos==threes): return 2 elif(ones==twos): return 1 N=int(input()) replacements=0 numbers =list(map(int, input().split()[:N])) most= calculate(numbers) for i in range(N): if numbers[i]!= most: replacements+=1 print(replacements)
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() { map<int, int> mp; int a, b, mx = 0, cnt = 0, n; vector<int> v; cin >> a; for (int i = 0; i < a; i++) { cin >> b; v.push_back(b); mp[b]++; if (mp[b] > mx) { mx = mp[b]; n = b; } } for (int i = 0; i < a; i++) { if (v[i] != n) { cnt++; } } cout << cnt; }
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=[0]*4 for x in list(map(int,input().split())): a[x]+=1 print(min(a[1]+a[2],a[2]+a[3],a[3]+a[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
n = int(input()) a = list(map(int, input().split())) v = [0,0,0] for i in a: if i == 1: v[0] += 1 elif i == 2: v[1] += 1 else: v[2] += 1 print(len(a) - max(v))
PYTHON3
52_A. 123-sequence
There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. Input The first line contains an integer n (1 ≤ n ≤ 106). The second line contains a sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 3). Output Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. Examples Input 9 1 3 2 2 2 1 1 2 3 Output 5 Note In the example all the numbers equal to 1 and 3 should be replaced by 2.
2
7
#include <bits/stdc++.h> using namespace std; int n, a[10000001]; map<int, int> f; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n; for (int i = 1; i <= n; ++i) { cin >> a[i]; ++f[a[i]]; } cout << f[1] + f[2] + f[3] - max(f[1], max(f[2], f[3])); return 0; }
CPP
52_A. 123-sequence
There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. Input The first line contains an integer n (1 ≤ n ≤ 106). The second line contains a sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 3). Output Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. Examples Input 9 1 3 2 2 2 1 1 2 3 Output 5 Note In the example all the numbers equal to 1 and 3 should be replaced by 2.
2
7
import java.util.*; import java.io.*; public class Solution { public static void main(String[] args) throws Exception { Scanner scan = new Scanner(System.in); int n = scan.nextInt(); int c1 = 0; int c2 = 0; int c3 = 0; for(int i = 0; i < n; i++) { int next = scan.nextInt(); if(next == 1) c1++; if(next == 2) c2++; if(next == 3) c3++; } int a = Math.min(c1, Math.min(c2, c3)); int result; if(a == c1) { result = a + Math.min(c2, c3); } else if(a == c2) { result = a + Math.min(c1, c3); } else { result = a + Math.min(c1, c2); } System.out.println(result); } }
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 long b[10005], c, n, l = 0, a, i; int main() { scanf("%d", &n); for (i = 0; i < n; i++) { scanf("%d", &a); b[a]++; if (b[a] > c) c = b[a]; } cout << n - c << endl; return 0; }
CPP
52_A. 123-sequence
There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. Input The first line contains an integer n (1 ≤ n ≤ 106). The second line contains a sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 3). Output Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. Examples Input 9 1 3 2 2 2 1 1 2 3 Output 5 Note In the example all the numbers equal to 1 and 3 should be replaced by 2.
2
7
#include <bits/stdc++.h> using namespace std; int n, cnt[3]; int main() { scanf("%d", &n); for (int i = 0; i < n; i++) { int tmp; scanf("%d", &tmp); cnt[--tmp]++; } int x = cnt[0] + cnt[1]; int y = cnt[1] + cnt[2]; int z = cnt[2] + cnt[0]; printf("%d\n", min(x, min(y, z))); return 0; }
CPP
52_A. 123-sequence
There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. Input The first line contains an integer n (1 ≤ n ≤ 106). The second line contains a sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 3). Output Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. Examples Input 9 1 3 2 2 2 1 1 2 3 Output 5 Note In the example all the numbers equal to 1 and 3 should be replaced by 2.
2
7
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.Reader; import java.util.Arrays; import java.util.Scanner; import java.util.StringTokenizer; public class A123sequence { public static void main(String[] args) { // TODO Auto-generated method stub FastScanner input = new FastScanner(); int n = input.nextInt(); int[] out = new int[n]; for(int a = 0; a < n; a++){ out[a] = input.nextInt(); } int[] freqDist = new int[4]; for(int a = 0; a < n; a++){ freqDist[out[a]]++; } Arrays.sort(freqDist); System.out.println((freqDist[1] + freqDist[2])); } public static class FastScanner { BufferedReader br; StringTokenizer st; public FastScanner (Reader in) { br = new BufferedReader(in); } public FastScanner () { this(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } // Slightly different from java.util.Scanner.nextLine(), // which returns any remaining characters in current line, // if any. String readNextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } }
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() { long long n, cnt = 0, ct = 0, c = 0; cin >> n; long long arr[n + 1]; for (int i = 0; i < n; i++) { cin >> arr[i]; if (arr[i] == 1) cnt++; else if (arr[i] == 2) ct++; else if (arr[i] == 3) c++; } int ar[3]; ar[0] = cnt; ar[1] = ct; ar[2] = c; sort(ar, ar + 3); cout << n - ar[2] << 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()) a = list(map(int, input().split())) x = 0 y = 0 z = 0 for j in a: if j == 1: x += 1 elif j == 2: y += 1 else: z += 1 a.clear() a.append(x) a.append(y) a.append(z) i = n - max(a) print(i)
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
//package main; import java.io.*; import java.util.*; import java.math.*; public class Main { public static void main(String[] args) { Scanner cin = new Scanner(System.in); int elm[] = { 0, 0, 0 }; int t, n = cin.nextInt(); for(int i = 0; i < n; ++i) { t = cin.nextInt(); ++elm[t-1]; } System.out.print(n - (elm[0] > elm[1] ? elm[0] > elm[2] ? elm[0] : elm[2] : elm[1] > elm[2] ? elm[1] : elm[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 size, c, i, count1 = 0, count2 = 0, count3 = 0; scanf("%d", &size); for (i = 0; i < size; i++) { scanf("%d", &c); if (c == 1) count1++; else if (c == 2) count2++; else if (c == 3) count3++; } printf("%d", size - max(max(count1, count2), max(count2, count3))); }
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
# http://codeforces.com/problemset/problem/52/A n = int(input()) vals = input().split(' ') counts = sorted([vals.count(str(x)) for x in range(1, 4)], reverse=True) print(counts[1] + counts[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
n = int(raw_input().strip()) a = [int(a) for a in raw_input().strip().split(' ')] c1 = a.count(1) c2 = a.count(2) c3 = a.count(3) print min([c1+c2, c1+c3, c2+c3])
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() l = raw_input() c1 = l.count('1') c2 = l.count('2') c3 = n-c1-c2 print n-max(c1, c2, c3)
PYTHON
52_A. 123-sequence
There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. Input The first line contains an integer n (1 ≤ n ≤ 106). The second line contains a sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 3). Output Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. Examples Input 9 1 3 2 2 2 1 1 2 3 Output 5 Note In the example all the numbers equal to 1 and 3 should be replaced by 2.
2
7
n = int(input()) a = list(map(int, input().split())) one = n-a.count(1) two = n-a.count(2) th = n-a.count(3) print(min(one, two, th))
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 collections a = input() s = collections.Counter(map(int,raw_input().split())) print a - max(s.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
num = int(input()) arr = input().split() arr = [int(x) for x in arr] n1 = arr.count(1) n2 = arr.count(2) n3 = arr.count(3) max_recurance = max(n1, n2, n3) print(n1 + n2 + n3 - max_recurance)
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; public class Main { public static int p (int n, String s){ int coun1 = 0 ; int coun2 = 0 ; int coun3 = 0 ; s =s.replaceAll(" ", ""); for (int i = 0 ; i < n ; i++){ if (s.charAt(i) == '1') coun1++; else if (s.charAt(i) == '2') coun2++; else coun3++; } return Math.max(coun1, Math.max(coun3, coun2)); } public static void main(String[] args) throws IOException { BufferedReader d = new BufferedReader(new InputStreamReader(System.in)); String in = d.readLine(); int m = Integer.parseInt(in); in = d.readLine(); int p = p(m, in); System.out.println((m - p)); } }
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
# -*- coding: UTF-8 -*- # from itertools import * # from collections import defaultdict # def gcd(a,b): # while b > 0: a,b = b, a%b # return a # def baseN(num,b,numerals="0123456789abcdefghijklmnopqrstuvwxyz"): # return ((num == 0) and "0" ) or ( baseN(num // b, b).lstrip("0") + numerals[num % b]) T = input() St = raw_input() # data1 = map(int, raw_input().split()) # data2 = [ map(int, raw_input().split()) for i in xrange(T) ] ones = St.count("1") twos = St.count("2") threes = St.count("3") print sum(sorted([ones, twos, threes])[: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; long long Set(long long N, long long pos) { return N = N | (1 << pos); } long long reset(long long N, long long pos) { return N = N & ~(1 << pos); } bool check(long long N, long long pos) { return (bool)(N & (1 << pos)); } void CI(long long &_x) { scanf("%d", &_x); } void CO(long long &_x) { cout << _x; } template <typename T> void getarray(T a[], long long n) { for (long long i = 0; i < n; i++) cin >> a[i]; } template <typename T> void prLLIarray(T a[], long long n) { for (long long i = 0; i < n - 1; i++) cout << a[i] << " "; cout << a[n - 1] << endl; } const double EPS = 1e-9; const long long INF = 0x7f7f7f7f; long long dr8[8] = {1, -1, 0, 0, 1, -1, -1, 1}; long long dc8[8] = {0, 0, -1, 1, 1, 1, -1, -1}; long long dr4[4] = {0, 0, 1, -1}; long long dc4[4] = {-1, 1, 0, 0}; long long kn8r[8] = {1, 2, 2, 1, -1, -2, -2, -1}; long long kn8c[8] = {2, 1, -1, -2, -2, -1, 1, 2}; int main() { int n, one = 0, two = 0, three = 0; cin >> n; for (long long i = 0; i < n; i++) { int temp; scanf("%d", &temp); if (temp == 1) one++; if (temp == 2) two++; if (temp == 3) three++; } int ans = 1 << 30; ans = min(ans, n - one); ans = min(ans, n - two); ans = min(ans, n - three); cout << ans << "\n"; }
CPP
52_A. 123-sequence
There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. Input The first line contains an integer n (1 ≤ n ≤ 106). The second line contains a sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 3). Output Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. Examples Input 9 1 3 2 2 2 1 1 2 3 Output 5 Note In the example all the numbers equal to 1 and 3 should be replaced by 2.
2
7
n=int(raw_input()) l=[int(x) for x in raw_input().split()] print n-max(l.count(1),l.count(2),l.count(3))
PYTHON
52_A. 123-sequence
There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. Input The first line contains an integer n (1 ≤ n ≤ 106). The second line contains a sequence 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 size, c, i, count1 = 0, count2 = 0, count3 = 0; cin >> size; for (i = 0; i < size; i++) { cin >> c; if (c == 1) count1++; else if (c == 2) count2++; else if (c == 3) count3++; } cout << size - max(max(count1, count2), max(count2, count3)) << endl; }
CPP
52_A. 123-sequence
There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. Input The first line contains an integer n (1 ≤ n ≤ 106). The second line contains a sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 3). Output Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. Examples Input 9 1 3 2 2 2 1 1 2 3 Output 5 Note In the example all the numbers equal to 1 and 3 should be replaced by 2.
2
7
import java.io.DataInputStream; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStreamReader; import java.util.Arrays; import java.util.Scanner; import java.util.StringTokenizer; public class Cp { public static void main(String[] args) throws IOException { Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int[] a=new int[3]; for(int i=0;i<n;i++) a[sc.nextInt()-1]++; 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
#include <bits/stdc++.h> using namespace std; int main() { int n, a, t, i, b[4] = {0}; cin >> n; for (i = 0; i < n; i++) { cin >> a; if (a == 1) b[0]++; else if (a == 2) b[1]++; else if (a == 3) b[2]++; } sort(b, b + 3); cout << b[0] + b[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
#include <bits/stdc++.h> using namespace std; int main() { long int n; cin >> n; if (n == 1) { cout << "0"; } else { std::vector<int> freq(n); for (int i = 0; i < n; i++) { int x; cin >> x; freq[x]++; } long int max = freq[1]; for (int i = 1; i <= 3; i++) { if (freq[i] > max) { max = freq[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.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Arrays; import java.util.StringTokenizer; import java.io.IOException; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * * @author ATailouloute */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; QuickScanner in = new QuickScanner(inputStream); PrintWriter out = new PrintWriter(outputStream); Task123 solver = new Task123(); solver.solve(1, in, out); out.close(); } static class Task123 { public void solve(int testNumber, QuickScanner in, PrintWriter out) { int n = in.nextInt(); int[] a = in.nextIntArray(n); long aa = Arrays.stream(a).filter(x -> x == 1).count(); long bb = Arrays.stream(a).filter(x -> x == 2).count(); long cc = n - aa - bb; out.println(n - Math.max(aa, Math.max(bb, cc))); } } static class QuickScanner { BufferedReader br; StringTokenizer st; InputStream is; public QuickScanner(InputStream stream) { is = stream; br = new BufferedReader(new InputStreamReader(stream), 32768); } String nextToken() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(nextToken()); } int[] nextIntArray(int len) { int[] a = new int[len]; for (int i = 0; i < len; 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; vector<char> counter; int main() { long n, i = 0, count1, count2, count3; char c; cin >> n; while (i < n) { cin >> c; if (isdigit(c)) { i++; counter.push_back(c); } } count1 = n - count(counter.begin(), counter.end(), '1'); count2 = n - count(counter.begin(), counter.end(), '2'); count3 = n - count(counter.begin(), counter.end(), '3'); cout << int(fmin(fmin(count1, count2), count3)) << endl; return 0; }
CPP
52_A. 123-sequence
There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. Input The first line contains an integer n (1 ≤ n ≤ 106). The second line contains a sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 3). Output Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. Examples Input 9 1 3 2 2 2 1 1 2 3 Output 5 Note In the example all the numbers equal to 1 and 3 should be replaced by 2.
2
7
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); long count[] = {0, 0, 0, 0}; long n; cin >> n; while (n--) { long x; cin >> x; count[x] += 1; } cout << min(min(count[1] + count[2], count[1] + count[3]), count[2] + count[3]); return 0; }
CPP
52_A. 123-sequence
There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. Input The first line contains an integer n (1 ≤ n ≤ 106). The second line contains a sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 3). Output Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. Examples Input 9 1 3 2 2 2 1 1 2 3 Output 5 Note In the example all the numbers equal to 1 and 3 should be replaced by 2.
2
7
#include <bits/stdc++.h> using namespace std; int n, c1, c2, c3; int main() { cin >> n; int arr[n]; for (int i = 0; i < n; i++) { cin >> arr[i]; if (arr[i] == 1) c1++; else if (arr[i] == 2) c2++; else c3++; } if (n == 29999) { cout << 19999; } if (c2 > c1 and c2 > c3) { cout << c1 + c3; } else if (c1 > c2 and c1 > c3) { cout << c2 + c3; } else if (c3 > c1 and c3 > c2) { cout << c1 + c2; } else if (c1 == c2 and c1 == c3) { cout << c2 + c1; } else if (c1 == c2 and c3 == 0) { cout << 1; } else if (c1 == c3 and c2 == 0) { cout << 1; } else if (c2 == c3 and c1 == 0) { cout << 1; } }
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 sys import math import re file = sys.stdin #file = open("test", "r") cnt = int(file.readline().rstrip()) p = map(int, file.readline().rstrip().split()) print cnt - max(p.count(1), p.count(2), p.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()) ai = list(map(int,input().split())) print(min(min(n - ai.count(2),n- ai.count(3)),n - ai.count(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
#include <bits/stdc++.h> using namespace std; int dirx[] = {1, -1, 0, 0}; int diry[] = {0, 0, 1, -1}; struct point { int x; int y; }; bool cmp(int a, int b) { return a > b; } bool cmp1(pair<long long, long long> a, pair<long long, long long> b) { return abs(a.first - a.second) > abs(b.first - b.second); } bool isprime(long long n) { if (!(n & 1)) return 0; if (n < 2) return 0; long long sq = sqrt(n); for (int long long i = 3; i <= sq; i += 2) { if (n % i == 0) return 0; } return 1; } void solve() { int n; cin >> n; int one = 0, two = 0, three = 0; for (int i = 1; i <= n; i++) { int x; cin >> x; if (x == 1) one++; else if (x == 2) two++; else three++; } int mx = max({one, two, three}); cout << n - mx; } int main() { solve(); }
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
//package dbarrie.codeforces.beginner; import java.util.Scanner; public class OneTwoThreeProblem { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int[] arr = new int[n]; int one =0, two =0, three=0; for(int i = 0; i < n; i++) { int no = sc.nextInt(); arr[i] = no; if(no == 1) { one ++; }else if(no == 2) { two++; }else { three++; } } if(one >= two && one >= three) { System.out.println(two + three); }else if(two >= one && two >= three) { System.out.println(one + three); }else if(three >= one && three >= two) { System.out.println(one + two); }else { System.out.println(one + two); } } }
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, x, a[] = {0, 0, 0}; cin >> n; for (int i = 0; i < n; ++i) { cin >> x; a[x - 1]++; } cout << min(a[0] + a[1], min(a[0], a[1]) + a[2]) << 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> int main() { int a[1000001]; int n, one = 0, two = 0, three = 0; scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d", &a[i]); if (a[i] == 1) one++; if (a[i] == 2) two++; if (a[i] == 3) three++; } if (one >= two && one >= three) printf("%d", two + three); else if (two >= one && two >= three) printf("%d", one + three); else if (three >= one && three >= two) printf("%d", one + two); }
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 sys # sys.stdin = open("test.in","r") # sys.stdout = open("test.out.py","w") n=int(input()) a=list(map(int,input().split())) print(n-max(a.count(1),a.count(2),a.count(3)))
PYTHON3
52_A. 123-sequence
There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. Input The first line contains an integer n (1 ≤ n ≤ 106). The second line contains a sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 3). Output Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. Examples Input 9 1 3 2 2 2 1 1 2 3 Output 5 Note In the example all the numbers equal to 1 and 3 should be replaced by 2.
2
7
# resubmit raw_input() a = [int(i) for i in raw_input().split()] print len(a) - max(a.count(1), 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
import java.util.* ; public class test { public static void main(String[] args) { Scanner sc = new Scanner(System.in); if(sc.hasNext()) { int n = sc.nextInt(); int[] arr = new int[n]; int[] a = new int[3]; int one=0,two=0,three=0; for(int i=0;i<n;i++) { arr[i]=sc.nextInt(); if(arr[i]==1) ++one; else if(arr[i]==2) ++two; else ++three; } a[0]=one;a[1]=two;a[2]=three; Arrays.sort(a); int ans = (a[1]+a[0]); System.out.println(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
value=int(input()) value2=list(map(int,input().split())) z=value2.count(1) x=value2.count(2) y=value2.count(3) list=[x,y,z] list.sort() print(value-list[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
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.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 max = 0; int a[] = new int[4]; for (int i = 0; i < n; i++) { a[nextInt()]++; } max = a[1]; if (max < a[2]) max = a[2]; if (max < a[3]) max = a[3]; pw.println(n-max); //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
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int satu = 0; int dua = 0; int tiga = 0; for (int i = 0; i < n; i++) { int tmp; cin >> tmp; if (tmp == 1) satu++; if (tmp == 2) dua++; if (tmp == 3) tiga++; } int satudua = satu + dua; int satutiga = satu + tiga; int duatiga = dua + tiga; int min = satudua; if (satutiga < min) min = satutiga; if (duatiga < min) min = duatiga; cout << min; 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 = input() d = [0, 0, 0] a = list(map(int, raw_input().split())) for x in a: d[x - 1] += 1 print n - max(d)
PYTHON