Search is not available for this dataset
name
stringlengths
2
112
description
stringlengths
29
13k
source
int64
1
7
difficulty
int64
0
25
solution
stringlengths
7
983k
language
stringclasses
4 values
52_A. 123-sequence
There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. Input The first line contains an integer n (1 ≤ n ≤ 106). The second line contains a sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 3). Output Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. Examples Input 9 1 3 2 2 2 1 1 2 3 Output 5 Note In the example all the numbers equal to 1 and 3 should be replaced by 2.
2
7
n=int(input()) l=[int(x) for x in input().split()] d=[l.count(i) for i in set(l)] print(n-max(d))
PYTHON3
52_A. 123-sequence
There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. Input The first line contains an integer n (1 ≤ n ≤ 106). The second line contains a sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 3). Output Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. Examples Input 9 1 3 2 2 2 1 1 2 3 Output 5 Note In the example all the numbers equal to 1 and 3 should be replaced by 2.
2
7
import java.util.*; public class Sequ { 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
import java.util.*; public class team { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int i,max=-1,no; int a[]=new int[n]; int c[]={0,0,0}; for(i=0;i<n;i++) { a[i]=sc.nextInt(); c[a[i]-1]+=1; } for(i=0;i<3;i++) { if(c[i]>max) { max=c[i]; } } n=n-max; System.out.println(n); } }
JAVA
52_A. 123-sequence
There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. Input The first line contains an integer n (1 ≤ n ≤ 106). The second line contains a sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 3). Output Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. Examples Input 9 1 3 2 2 2 1 1 2 3 Output 5 Note In the example all the numbers equal to 1 and 3 should be replaced by 2.
2
7
n=int(input()) l=[int(x) for x in input().split(' ')] d=[l.count(i) for i in set(l)] print(n-max(d))
PYTHON3
52_A. 123-sequence
There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. Input The first line contains an integer n (1 ≤ n ≤ 106). The second line contains a sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 3). Output Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. Examples Input 9 1 3 2 2 2 1 1 2 3 Output 5 Note In the example all the numbers equal to 1 and 3 should be replaced by 2.
2
7
num=int(input()) arr=[0]*9 arr=input().split() for i in range (num): arr[i]=int(arr[i]) one=0 two=0 three=0 for k in range (num): if arr[k]==1: one+=1 if arr[k]==2: two+=1 if arr[k]==3: three+=1 find=max(one,two,three) print (num-find)
PYTHON3
52_A. 123-sequence
There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. Input The first line contains an integer n (1 ≤ n ≤ 106). The second line contains a sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 3). Output Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. Examples Input 9 1 3 2 2 2 1 1 2 3 Output 5 Note In the example all the numbers equal to 1 and 3 should be replaced by 2.
2
7
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a[n], b[3]; for (int i = 0; i < 3; i++) b[i] = 0; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n; i++) { if (a[i] == 1) b[0]++; else if (a[i] == 2) b[1]++; else b[2]++; } if (b[0] > b[1] && b[0] > b[2]) cout << b[1] + b[2]; else if (b[1] > b[0] && b[1] > b[2]) cout << b[0] + b[2]; else if (b[2] > b[1] && b[2] > b[0]) cout << b[1] + b[0]; else if (n == 2 && a[1] != a[0]) cout << "1"; else if (n == 2 && a[0] == a[1]) cout << "0"; else cout << b[1] + b[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
#include <bits/stdc++.h> using namespace std; int main() { int n, x, a = 0, b = 0, c = 0, max1; cin >> n; for (int i = 0; i < n; i++) { cin >> x; if (x == 1) a++; else if (x == 2) b++; else c++; } max1 = max(a, b); max1 = max(max1, c); cout << n - max1 << 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 = input() mas = map(int, raw_input().split()) print N - max([mas.count(i) for i in xrange(1, 4)])
PYTHON
52_A. 123-sequence
There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. Input The first line contains an integer n (1 ≤ n ≤ 106). The second line contains a sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 3). Output Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. Examples Input 9 1 3 2 2 2 1 1 2 3 Output 5 Note In the example all the numbers equal to 1 and 3 should be replaced by 2.
2
7
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.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 a[] = new int[4]; for (int i = 0; i < n; i++) { a[nextByte()]++; } pw.println(n-Math.max(Math.max(a[1], a[2]), a[3])); } ////////////////////// MAIN /////////////////////// public static void main(String[] args) throws IOException { new Test().poehali(); } }
JAVA
52_A. 123-sequence
There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. Input The first line contains an integer n (1 ≤ n ≤ 106). The second line contains a sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 3). Output Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. Examples Input 9 1 3 2 2 2 1 1 2 3 Output 5 Note In the example all the numbers equal to 1 and 3 should be replaced by 2.
2
7
n=int(input()) a=list(map(int,input().split()))[:n] x=a.count(1) y=a.count(2) z=a.count(3) print(n-max(x,y,z))
PYTHON3
52_A. 123-sequence
There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. Input The first line contains an integer n (1 ≤ n ≤ 106). The second line contains a sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 3). Output Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. Examples Input 9 1 3 2 2 2 1 1 2 3 Output 5 Note In the example all the numbers equal to 1 and 3 should be replaced by 2.
2
7
cases = int(input()) arr = list(map(int, input().split())) mx = max(arr.count(1), arr.count(2), arr.count(3)) print(cases-mx)
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, x, maxx, counter[4]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; for (int i = 0; i < n; i++) { cin >> x; counter[x]++; } for (int i = 1; i <= 3; i++) { maxx = max(maxx, counter[i]); } n -= maxx; cout << n << "\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, t = int(raw_input()), raw_input() a, b = t.count('1'), t.count('2') print n - max(a, b, n - a - b)
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.Scanner; public class Sequence123 { public static void main(String[] args) { Scanner scan= new Scanner(System.in); int n=scan.nextInt(); int[] a =new int[n]; int o=0,t=0,th=0; for(int i=0;i<n;i++) { a[i]=scan.nextInt(); if(a[i]==1) o++; else if(a[i]==2) t++; else th++; } int x=Math.max(Math.max(o,t), th); System.out.println(n-x); } }
JAVA
52_A. 123-sequence
There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. Input The first line contains an integer n (1 ≤ n ≤ 106). The second line contains a sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 3). Output Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. Examples Input 9 1 3 2 2 2 1 1 2 3 Output 5 Note In the example all the numbers equal to 1 and 3 should be replaced by 2.
2
7
import java.io.*; import java.util.*; public class A implements Runnable { private void solve() throws IOException { int n = nextInt(); int[] a = new int[3]; for (int i = 0; i < n; i++) { a[nextInt() - 1]++; } int ans = 0; for (int i : a) { ans = Math.max(ans, i); } System.out.println(n - ans); } public static void main(String[] args) { new Thread(new A()).start(); } BufferedReader br; StringTokenizer st; public void run() { Locale.setDefault(Locale.US); try { br = new BufferedReader(new InputStreamReader(System.in)); solve(); } catch (Throwable e) { e.printStackTrace(); System.exit(239); } } String nextToken() { while (st == null || !st.hasMoreTokens()) { try { st = new StringTokenizer(br.readLine()); } catch (Exception e) { return "0"; } } return st.nextToken(); } int nextInt() { return Integer.parseInt(nextToken()); } }
JAVA
52_A. 123-sequence
There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. Input The first line contains an integer n (1 ≤ n ≤ 106). The second line contains a sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 3). Output Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. Examples Input 9 1 3 2 2 2 1 1 2 3 Output 5 Note In the example all the numbers equal to 1 and 3 should be replaced by 2.
2
7
import java.util.*; public class java { public static void main(String args[]) { Scanner in=new Scanner(System.in); int n=in.nextInt(),c=0,cnt=0,count=0; int arr[]=new int[n]; for(int i=0;i<n;i++) { arr[i]=in.nextInt(); if(arr[i]==1) { c++; } else if(arr[i]==2) { cnt++; } else { count++; } } int max=Math.max(c,cnt); max=Math.max(max,count); System.out.println(n-max); } }
JAVA
52_A. 123-sequence
There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. Input The first line contains an integer n (1 ≤ n ≤ 106). The second line contains a sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 3). Output Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. Examples Input 9 1 3 2 2 2 1 1 2 3 Output 5 Note In the example all the numbers equal to 1 and 3 should be replaced by 2.
2
7
import sys if __name__=="__main__": n=int(sys.stdin.readline()) l=[]; d={}; a=sys.stdin.readline().strip().split(" ") for i in a: d[i]=d.get(i,0)+1; l=list(d.values()); l.remove(max(l)); print(sum(l));
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; using ll = long long; constexpr ll mod = 1e9 + 7; int main() { ios::sync_with_stdio(0); cin.tie(0); ll n; cin >> n; vector<ll> A(n); for (auto& _a : A) cin >> _a; int cnt[4] = {}; for (int x : A) ++cnt[x]; ll ans = max({cnt[1], cnt[2], cnt[3]}); n -= ans; cout << n << '\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
raw_input() s = raw_input().split() p = [0,0,0,0] for x in s: p[int(x)] += 1 print len(s) - max(p[1],p[2],p[3])
PYTHON
52_A. 123-sequence
There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. Input The first line contains an integer n (1 ≤ n ≤ 106). The second line contains a sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 3). Output Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. Examples Input 9 1 3 2 2 2 1 1 2 3 Output 5 Note In the example all the numbers equal to 1 and 3 should be replaced by 2.
2
7
import java.io.*; import java.util.Arrays; import java.util.Scanner; public class Solution { public static void main(String[] args) { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int one=0; int two=0; int three=0; for(int i=0;i<n;i++) { int v=sc.nextInt(); if(v==1) one++; else if(v==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 { 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; cin >> n; int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } int c1 = 0, c2 = 0, c3 = 0; for (int i = 0; i < n; i++) { if (a[i] == 1) { c1++; } else if (a[i] == 2) { c2++; } else { c3++; } } cout << n - max(c1, max(c2, c3)); }
CPP
52_A. 123-sequence
There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. Input The first line contains an integer n (1 ≤ n ≤ 106). The second line contains a sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 3). Output Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. Examples Input 9 1 3 2 2 2 1 1 2 3 Output 5 Note In the example all the numbers equal to 1 and 3 should be replaced by 2.
2
7
#include <bits/stdc++.h> int main() { int n; std::cin >> n; std::vector<int> v(4); int max_freq{}; for (int i{0}, x; i < n; ++i) { std::cin >> x; max_freq = std::max(max_freq, ++v[x]); } std::cout << n - max_freq << std::endl; }
CPP
52_A. 123-sequence
There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. Input The first line contains an integer n (1 ≤ n ≤ 106). The second line contains a sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 3). Output Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. Examples Input 9 1 3 2 2 2 1 1 2 3 Output 5 Note In the example all the numbers equal to 1 and 3 should be replaced by 2.
2
7
import java.util.*; public class A { public static void main(String args[]) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int arr[] = new int[n]; int one = 0; int two = 0; int three = 0; for(int i=0; i<n; i++){ arr[i] = sc.nextInt(); if(arr[i]==1){ one++; } if(arr[i]==2){ two++; } if(arr[i]==3){ three++; } } int max = Math.max(Math.max(one, two), three); System.out.println(n-max); sc.close(); } }
JAVA
52_A. 123-sequence
There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. Input The first line contains an integer n (1 ≤ n ≤ 106). The second line contains a sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 3). Output Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. Examples Input 9 1 3 2 2 2 1 1 2 3 Output 5 Note In the example all the numbers equal to 1 and 3 should be replaced by 2.
2
7
A = [0] * 1000001 N = int(input()) L = list(map(int, input().split())) for l in L: A[l] += 1 print(N - max(A))
PYTHON3
52_A. 123-sequence
There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. Input The first line contains an integer n (1 ≤ n ≤ 106). The second line contains a sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 3). Output Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. Examples Input 9 1 3 2 2 2 1 1 2 3 Output 5 Note In the example all the numbers equal to 1 and 3 should be replaced by 2.
2
7
import java.util.Scanner; public class CodeForces2 { public static void main(String[] args) { // BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int[] arr = new int[n]; int a =0, b=0,c=0; for (int i = 0; i < arr.length; i++) { arr[i] = sc.nextInt(); if(arr[i] == 1){ a++; }else if(arr[i] == 2){ b++; }else if(arr[i] == 3){ c++; } } int max = Math.max(c, Math.max(a, b)); if(max == a) System.out.println(b+c); else if(max == b) System.out.println(a+c); else if(max == c) System.out.println(a+b); } }
JAVA
52_A. 123-sequence
There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. Input The first line contains an integer n (1 ≤ n ≤ 106). The second line contains a sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 3). Output Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. Examples Input 9 1 3 2 2 2 1 1 2 3 Output 5 Note In the example all the numbers equal to 1 and 3 should be replaced by 2.
2
7
a=int(input()) v=input().split() x=v.count("1") y=v.count('2') z=v.count('3') g=max(x,y,z) l=x+y+z-g print(l)
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()) counts = 4 * [0] for a in map(int, input().split()): counts[a] += 1 result = n - max(counts) print(result)
PYTHON3
52_A. 123-sequence
There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. Input The first line contains an integer n (1 ≤ n ≤ 106). The second line contains a sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 3). Output Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. Examples Input 9 1 3 2 2 2 1 1 2 3 Output 5 Note In the example all the numbers equal to 1 and 3 should be replaced by 2.
2
7
n = int(input()) a = [int(s) for s in input().split(' ')] a_dict = {} for x in a: if x in a_dict.keys(): a_dict[x] += 1 else: a_dict[x] = 1 ans = n - a_dict[max(a_dict, key=lambda x: a_dict[x])] 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
import java.util.*; import java.io.*; import java.util.Date; public class Code{ public static void main(String [] args) { Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int c1=0,c2=0,c3=0; int arr[]=new int[n]; for(int i=0;i<n;i++) { arr[i]=sc.nextInt(); if(arr[i]==1) { c1++; } else if(arr[i]==2) { c2++; } else { c3++; } } int arr1[]=new int[3]; arr1[0]=c1; arr1[1]=c2; arr1[2]=c3; Arrays.sort(arr1); System.out.println(arr1[0]+arr1[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.*; import java.util.stream.Collectors; public class Sequence { public static void main(String [] args) { Scanner input = new Scanner(System.in); int n = input.nextInt(); List<Integer> numbers = new ArrayList<>(); for(int i = 0; i < n; i++) numbers.add(input.nextInt()); Map<Integer, Long> numbersCounter = numbers.stream() .collect(Collectors.groupingBy(Integer::intValue, Collectors.counting())); System.out.println(n - Collections.max(numbersCounter.values())); } }
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 min { public static void main(String args[]) { Scanner in=new Scanner(System.in); int n=in.nextInt(); int a[]=new int[n]; int c1=0,c2=0,c3=0; for(int i=0;i<n;i++) { a[i]=in.nextInt(); if(a[i]==1) c1++; if(a[i]==2) c2++; if(a[i]==3) c3++; } int max=Math.max(c1,Math.max(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
#include <bits/stdc++.h> int main() { int n; scanf("%d", &n); int a[n], i, x = 0, y = 0, z = 0; for (i = 1; i <= n; i++) { scanf("%d", &a[i]); if (a[i] == 1) x++; if (a[i] == 2) y++; if (a[i] == 3) z++; } if (x >= y && x >= z) printf("%d", n - x); else if (y >= z && y >= x) printf("%d", n - y); else if (z >= x && z >= y) printf("%d", n - 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
#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]; } sort(a, a + n); int count = 1; int temp = 1; for (int i = 0; i < n - 1; i++) { if (a[i] == a[i + 1]) { temp++; if (temp > count) { count = temp; } } else { if (temp > count) { count = temp; } temp = 1; } } cout << n - count; }
CPP
52_A. 123-sequence
There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. Input The first line contains an integer n (1 ≤ n ≤ 106). The second line contains a sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 3). Output Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. Examples Input 9 1 3 2 2 2 1 1 2 3 Output 5 Note In the example all the numbers equal to 1 and 3 should be replaced by 2.
2
7
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; vector<int> a(3); for (int i = 1; i <= N; i++) { int m; cin >> m; a[m - 1]++; } sort(a.begin(), a.end()); cout << a[0] + a[1] << endl; }
CPP
52_A. 123-sequence
There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. Input The first line contains an integer n (1 ≤ n ≤ 106). The second line contains a sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 3). Output Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. Examples Input 9 1 3 2 2 2 1 1 2 3 Output 5 Note In the example all the numbers equal to 1 and 3 should be replaced by 2.
2
7
import java.util.*; public class x { public static void main(String args[]) { Scanner obj=new Scanner(System.in); int n,p,a=0,b=0,c=0,d=0,i; n=obj.nextInt(); for (i=0;i<n;i++) { p=obj.nextInt(); if (p==1) { a++; continue; } if (p==2) { b++; continue; } if (p==3) { c++; continue; } } if (a>=b && a>=c) d=b+c; else if(b>=a && b>=c) d=a+c; else d=a+b; System.out.print(d); } }
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 Trying { public static void main (String[] args) { Scanner enter = new Scanner(System.in); int n = enter.nextInt(), repeat[] = new int [3], max = 0, pos = 0; enter.nextLine(); String sequence = enter.nextLine(); for(int i = 0 ; i < 2*n ; i+=2) { repeat[sequence.charAt(i)-49]++; } for(int i = 0 ; i < 3 ; i++) if(repeat[i] > max){pos = i;max = repeat[i];} System.out.println(repeat[(pos+1)%3] + repeat[(pos+2)%3]); } }
JAVA
52_A. 123-sequence
There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. Input The first line contains an integer n (1 ≤ n ≤ 106). The second line contains a sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 3). Output Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. Examples Input 9 1 3 2 2 2 1 1 2 3 Output 5 Note In the example all the numbers equal to 1 and 3 should be replaced by 2.
2
7
n = int(input()) a = [int(x) for x in input().split()] answer = [0, 0, 0] for i in a: answer[i - 1] += 1 print(n - max(answer))
PYTHON3
52_A. 123-sequence
There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. Input The first line contains an integer n (1 ≤ n ≤ 106). The second line contains a sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 3). Output Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. Examples Input 9 1 3 2 2 2 1 1 2 3 Output 5 Note In the example all the numbers equal to 1 and 3 should be replaced by 2.
2
7
#include <bits/stdc++.h> using namespace std; int main() { int n, cnt1 = 0, cnt2 = 0, cnt3 = 0; cin >> n; int s[n], i; for (i = 0; i < n; i++) { cin >> s[i]; if (s[i] == 1) ++cnt1; if (s[i] == 2) ++cnt2; if (s[i] == 3) ++cnt3; } int temp0, temp; temp0 = max(cnt1, cnt2); temp = max(temp0, cnt3); cout << (cnt1 + cnt2 + cnt3) - temp << 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; signed main() { cout.tie(0), cin.tie(0), ios::sync_with_stdio(0); long long n, temp; cin >> n; long long cnt1 = 0, cnt2 = 0, cnt3 = 0; for (long long i = 0; i < n; i++) { cin >> temp; if (temp == 1) cnt1++; else if (temp == 2) cnt2++; else cnt3++; } cout << n - max(max(cnt1, cnt2), cnt3); 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> #pragma GCC optimize(5) int main() { std::ios::sync_with_stdio(false); std::map<int, int> map; register int n; std::cin >> n; for (register int i = 1; i <= n; ++i) { int t; std::cin >> t; ++map[t]; } int max = 0; for (const auto &i : map) max = std::max(max, i.second); std::cout << n - max << std::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> int main() { int i, j, arr, ma = 0, s[3] = {0}; scanf("%d", &j); for (i = 0; i < j; i++) { scanf("%d", &arr); if (arr == 1) s[0]++; else if (arr == 2) s[1]++; else if (arr == 3) s[2]++; } ma = (s[0] > s[1]) ? (s[0] > s[2]) ? s[0] : s[2] : (s[1] > s[2]) ? s[1] : s[2]; printf("%d", s[0] + s[1] + s[2] - ma); 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 sys n = int(sys.stdin.readline()) s = map(int, sys.stdin.readline().rstrip().split(' ')) counts = [ None, 0, 0, 0 ] for i in range(len(s)): counts[s[i]] += 1 m = min(counts[1]+counts[2], counts[1]+counts[3], counts[2]+counts[3]) print(m)
PYTHON
52_A. 123-sequence
There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. Input The first line contains an integer n (1 ≤ n ≤ 106). The second line contains a sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 3). Output Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. Examples Input 9 1 3 2 2 2 1 1 2 3 Output 5 Note In the example all the numbers equal to 1 and 3 should be replaced by 2.
2
7
#include <bits/stdc++.h> using namespace std; int main() { int n, a = 0, b = 0, c = 0, max = 0; cin >> n; int data[n]; for (int i = 0; i < n; i++) { cin >> data[i]; if (data[i] == 1) { a++; } else if (data[i] == 2) { b++; } else if (data[i] == 3) { c++; } } int arr[] = {a, b, c}; for (int i = 0; i < 3; i++) { if (arr[i] > max) { max = arr[i]; } } cout << n - max << 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
//package com.company; import java.util.*; public class Main { public static int findMax(int[] list) { int currentMax = 0; for (int i = 0; i < list.length; i ++) { if (list[i] > currentMax) { currentMax = list[i]; } } return currentMax; } public static int mainFunction() { Scanner inputReceiver = new Scanner(System.in); int n = inputReceiver.nextInt(); int[] hashTable = new int[4]; for (int i = 0; i < n; i ++) { hashTable[inputReceiver.nextInt()] += 1; } int maxVal = findMax(hashTable); return Arrays.stream(hashTable).sum() - maxVal; } public static void main(String[] args) { System.out.println(mainFunction()); } }
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, m, s, i, l = 0, k = 0, j = 0, t = 0, p = 0, max = 0; cin >> n; int a[n]; for (i = 0; i < n; i++) { k++; cin >> a[i]; if (a[i] == 1) { l++; } if (a[i] == 2) { j++; } if (a[i] == 3) { t++; } if (l > j) { max = l; } if (j > max) { max = j; } else if (t > max) { max = t; } } cout << (n - max) << 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=input() s=input() x=s.count('1') y=s.count('2') z=s.count('3') s=[x,y,z] s.sort() print(s[0]+s[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 main() { int a; int num[3] = {0}; int n; cin >> n; for (int i = 0; i < n; i++) { cin >> a; num[a - 1]++; } if (num[0] >= num[1] && num[0] >= num[2]) { printf("%d\n", n - num[0]); } else if (num[1] >= num[0] && num[1] >= num[2]) { printf("%d\n", n - num[1]); } else { printf("%d\n", n - num[2]); } return 0; }
CPP
52_A. 123-sequence
There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. Input The first line contains an integer n (1 ≤ n ≤ 106). The second line contains a sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 3). Output Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. Examples Input 9 1 3 2 2 2 1 1 2 3 Output 5 Note In the example all the numbers equal to 1 and 3 should be replaced by 2.
2
7
# Codeforces Testing Round 1 # Problem A: 123-sequence def replace(n, sequence): num1 = 0 num2 = 0 num3 = 0 for i in xrange(n): if (sequence[i] == 1): num1 += 1 elif (sequence[i] == 2): num2 += 1 else: num3 += 1 if (max(num1, num2, num3) == num1): return n - num1 elif (max(num1, num2, num3) == num2): return n - num2 else: return n - num3 n = raw_input() n = int(n) sequence = [] list = raw_input("").split(' ') for i in xrange(n): list[i] = int(list[i]) sequence += [list[i]] print replace(n, sequence)
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=list(map(int,input().split())) a=l.count(1) b=l.count(2) c=l.count(3) if(a>=b and a>=c): print(b+c) elif(b>=a and b>=c): print(a+c) else: print(a+b)
PYTHON3
52_A. 123-sequence
There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. Input The first line contains an integer n (1 ≤ n ≤ 106). The second line contains a sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 3). Output Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. Examples Input 9 1 3 2 2 2 1 1 2 3 Output 5 Note In the example all the numbers equal to 1 and 3 should be replaced by 2.
2
7
import java.io.*; import java.util.*; public class Main { void solve() throws IOException { int n = nextInt(); int[] arr = new int[3]; for( int i = 0; i < n; i++ ) arr[nextInt()-1]++; int max = Math.max(Math.max(arr[0], arr[1]), arr[2]); out.println(n-max); out.close(); } private static final String INPUT_FILE = "inp.txt"; public static void main(String[] args) throws IOException { //if (new File(INPUT_FILE).exists()) // System.setIn(new FileInputStream(INPUT_FILE)); new Main().solve(); } private BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); private PrintWriter out = new PrintWriter(System.out);; private StringTokenizer st = new StringTokenizer(""); String nextToken() throws IOException { while (!st.hasMoreTokens()) { st = new StringTokenizer(in.readLine()); } return st.nextToken(); } int nextInt() throws IOException { return Integer.parseInt(nextToken()); } long nextLong() throws IOException { return Long.parseLong(nextToken()); } double nextDouble() throws IOException { return Double.parseDouble(nextToken()); } String nextLine() throws IOException { st = new StringTokenizer(""); return in.readLine(); } boolean EOF() throws IOException { while (!st.hasMoreTokens()) { String s = in.readLine(); if (s == null) { return true; } st = new StringTokenizer(s); } return false; } }
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 = map(int, raw_input().split()) print n - max([a.count(x) for x in range(1, 4)])
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 gcd(int a, int b) { if (b == 0) return a; else return gcd(b, a % b); } int LCM(int a, int b) { return (a * b) / gcd(a, b); } long long fast_exp(long long base, long long exp) { long long res = 1; while (exp > 0) { if (exp % 2 == 1) res = ((res % 1000000007) * (base % 1000000007)) % 1000000007; base = ((base % 1000000007) * (base % 1000000007)) % 1000000007; exp /= 2; } return res % 1000000007; } void print_interator(set<int>& a) { for (auto it = a.begin(); it != a.end(); it++) { cout << *it << " "; } } int sum_vec(vector<int>& a) { int s = 0; for (int i = 0; i < a.size(); i++) { s += a[i]; } return s; } int maximum(vector<int>& a) { int ans = a[0]; for (int i = 1; i < a.size(); i++) { ans = max(ans, a[i]); } return ans; } int minimum(vector<int>& a) { int ans = a[0]; for (int i = 1; i < a.size(); i++) { ans = min(ans, a[i]); } return ans; } int main() { cin.tie(0); ios_base::sync_with_stdio(0); int c1 = 0, c2 = 0, c3 = 0; long long n; cin >> n; long long a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; if (a[i] == 1) c1++; else if (a[i] == 2) c2++; else if (a[i] == 3) c3++; } if (c1 >= c2 && c1 >= c3) cout << (n - c1); else if (c2 >= c1 && c2 >= c3) cout << (n - c2); else cout << (n - c3); return 0; }
CPP
52_A. 123-sequence
There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. Input The first line contains an integer n (1 ≤ n ≤ 106). The second line contains a sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 3). Output Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. Examples Input 9 1 3 2 2 2 1 1 2 3 Output 5 Note In the example all the numbers equal to 1 and 3 should be replaced by 2.
2
7
cnt = [0]*4 N = int(raw_input()) for a in map(int,raw_input().split()): cnt[a]+=1 print N-max(cnt)
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=input() o=l.count('1') t=l.count('2') th=l.count('3') l=[o,t,th] l.sort() print(l[0]+l[1])
PYTHON3
52_A. 123-sequence
There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. Input The first line contains an integer n (1 ≤ n ≤ 106). The second line contains a sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 3). Output Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. Examples Input 9 1 3 2 2 2 1 1 2 3 Output 5 Note In the example all the numbers equal to 1 and 3 should be replaced by 2.
2
7
import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.util.Arrays; import java.util.StringTokenizer; import static java.lang.Math.*; public class Solution implements Runnable{ public static void main(String[] args) { new Thread(new Solution()).start(); } public void run(){ try{ solve(); } catch (Exception e) { System.exit(1); } } private BufferedReader cin; private PrintWriter cout; private StringTokenizer tok = null; private String next() throws Exception{ while (tok == null || !tok.hasMoreTokens()){ tok = new StringTokenizer(cin.readLine()); } return tok.nextToken(); } private int nextInt() throws Exception{ return Integer.parseInt(next()); } private void solve() throws Exception{ cin = new BufferedReader(new InputStreamReader(System.in)); cout = new PrintWriter(new OutputStreamWriter(System.out)); int n = nextInt(); int a[] = new int[3]; for (int i = 0; i < n; ++i){ int x = nextInt(); if (x == 1) a[0]++; if (x == 2) a[1]++; if (x == 3) a[2]++; } Arrays.sort(a); cout.print(a[0] + a[1]); cout.close(); } }
JAVA
52_A. 123-sequence
There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. Input The first line contains an integer n (1 ≤ n ≤ 106). The second line contains a sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 3). Output Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. Examples Input 9 1 3 2 2 2 1 1 2 3 Output 5 Note In the example all the numbers equal to 1 and 3 should be replaced by 2.
2
7
import java.io.*; import java.util.*; public class A { public static void main(String args[]) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); PrintWriter out = new PrintWriter(System.out); int n = Integer.parseInt(br.readLine()); StringTokenizer s = new StringTokenizer(br.readLine()); int[] arr = {0, 0, 0}; for (int i = 0; i < n; i++) { arr[Integer.parseInt(s.nextToken()) - 1]++; } out.println(n - (Math.max(arr[0], Math.max(arr[1], arr[2])))); out.flush(); out.close(); } }
JAVA
52_A. 123-sequence
There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. Input The first line contains an integer n (1 ≤ n ≤ 106). The second line contains a sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 3). Output Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. Examples Input 9 1 3 2 2 2 1 1 2 3 Output 5 Note In the example all the numbers equal to 1 and 3 should be replaced by 2.
2
7
# 123-sequence from collections import Counter n = int(raw_input()) count = Counter(x for x in raw_input().split()) print n-count.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
n = int(input()) ai = list(map(int,input().split())) dic = {} for i in ai: if i not in dic: dic[i] = 1 else: dic[i] += 1 #print(dic) print(n - max(dic.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 main() { ::ios::sync_with_stdio(false); long long n, cnt1 = 0, cnt2 = 0, cnt3 = 0, max = 0; int num[1000010]; cin >> n; for (int i = 0; i < n; i++) { cin >> num[i]; if (num[i] == 1) cnt1++; if (num[i] == 2) cnt2++; if (num[i] == 3) cnt3++; } max = cnt1; if (max < cnt2) max = cnt2; if (max < cnt3) max = cnt3; cout << n - max << 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()) daf = list(map(int, input().split())) num1 = daf.count(1) num2 = daf.count(2) num3 = daf.count(3) num = max(num1, num2, num3) print(n - num)
PYTHON3
52_A. 123-sequence
There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. Input The first line contains an integer n (1 ≤ n ≤ 106). The second line contains a sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 3). Output Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. Examples Input 9 1 3 2 2 2 1 1 2 3 Output 5 Note In the example all the numbers equal to 1 and 3 should be replaced by 2.
2
7
from collections import Counter l=[] n=int(input()) c=Counter(list(map(int,input().split()))) for key,value in c.items():l.append(value) if len(l)==1:print(0) elif len(l)==2:print(min(l[0],l[1])) else:print(min(l[0]+l[1],l[0]+l[2],l[1]+l[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.util.*; import java.io.*; public class Seq { public static void main(String[]args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(br.readLine()); String input = br.readLine(); StringTokenizer tk = new StringTokenizer(input); int[] arr = new int[3]; for(int i=0; i<n; i++) { int hold = Integer.parseInt(tk.nextToken()); arr[hold-1]++; } int sub = Math.max(Math.max(arr[0],arr[1]),arr[2]); System.out.println(n-sub); } }
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 sys import math import itertools import functools import collections import operator import fileinput import copy ORDA = 97 def ii(): return int(input()) def mi(): return map(int, input().split()) def li(): return [int(i) for i in input().split()] def lcm(a, b): return abs(a * b) // math.gcd(a, b) def revn(n): return str(n)[::-1] def dd(): return collections.defaultdict(int) def ddl(): return collections.defaultdict(list) def sieve(n): if n < 2: return list() prime = [True for _ in range(n + 1)] p = 3 while p * p <= n: if prime[p]: for i in range(p * 2, n + 1, p): prime[i] = False p += 2 r = [2] for p in range(3, n + 1, 2): if prime[p]: r.append(p) return r def divs(n, start=1): r = [] for i in range(start, int(math.sqrt(n) + 1)): if (n % i == 0): if (n / i == i): r.append(i) else: r.extend([i, n // i]) return r def divn(n, primes): divs_number = 1 for i in primes: if n == 1: return divs_number t = 1 while n % i == 0: t += 1 n //= i divs_number *= t def prime(n): if n == 2: return True if n % 2 == 0 or n <= 1: return False sqr = int(math.sqrt(n)) + 1 for d in range(3, sqr, 2): if n % d == 0: return False return True def convn(number, base): newnumber = 0 while number > 0: newnumber += number % base number //= base return newnumber def cdiv(n, k): return n // k + (n % k != 0) n = ii() arr = li() brr = [0] * 4 for i in arr: brr[i] += 1 print(n - max(brr))
PYTHON3
52_A. 123-sequence
There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. Input The first line contains an integer n (1 ≤ n ≤ 106). The second line contains a sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 3). Output Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. Examples Input 9 1 3 2 2 2 1 1 2 3 Output 5 Note In the example all the numbers equal to 1 and 3 should be replaced by 2.
2
7
import java.io.*; import java.util.*; import static java.lang.Math.*; public class timelly { final boolean text = true; BufferedReader in; PrintWriter out; StringTokenizer tok = new StringTokenizer(""); void init() throws IOException { if (text) { in = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(System.out); } else { in = new BufferedReader(new FileReader("input.txt")); out = new PrintWriter("output.txt"); } } String readString() throws IOException { while (!tok.hasMoreTokens()) { tok = new StringTokenizer(in.readLine()); } return tok.nextToken(); } int readInt() throws IOException { return Integer.parseInt(readString()); } long readLong() throws IOException { return Long.parseLong(readString()); } double readDouble() throws IOException { return Double.parseDouble(readString()); } void debug(Object o) { System.err.println(o.toString()); } void run() { try { long t1 = System.currentTimeMillis(); init(); solve(); out.close(); long t2 = System.currentTimeMillis(); debug("Time = " + (t2 - t1)); } catch (Exception e) { throw new RuntimeException(e); } } public static void main(String[] args) { (new timelly()).run(); } void solve() throws IOException { int n= readInt(); int a[]= new int[5]; for (int i=0; i<n; i++) a[readInt()]++; out.println(n-max(max(a[1],a[2]),a[3])); } }
JAVA
52_A. 123-sequence
There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. Input The first line contains an integer n (1 ≤ n ≤ 106). The second line contains a sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 3). Output Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. Examples Input 9 1 3 2 2 2 1 1 2 3 Output 5 Note In the example all the numbers equal to 1 and 3 should be replaced by 2.
2
7
import java.util.Scanner; public class test{ public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int n = Integer.valueOf(scanner.nextLine()); String sequence = scanner.nextLine(); int counter1 = 0; int counter2 = 0; int counter3 = 0; for (int index = 0; index < sequence.length(); index += 2) { String ch = sequence.substring(index, index + 1); if (ch.equals("1")) counter1++; else if (ch.equals("2")) counter2++; } counter3 = n - (counter1 + counter2); int max = Math.max(counter1, counter2); max = Math.max(max, counter3); System.out.println(String.valueOf((n - max))); scanner.close(); } }
JAVA
52_A. 123-sequence
There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. Input The first line contains an integer n (1 ≤ n ≤ 106). The second line contains a sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 3). Output Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. Examples Input 9 1 3 2 2 2 1 1 2 3 Output 5 Note In the example all the numbers equal to 1 and 3 should be replaced by 2.
2
7
n = int(raw_input()) arr = map(int, raw_input().split()) a, b, c = arr.count(1), arr.count(2), arr.count(3) print min(a+b, a+c, b+c)
PYTHON
52_A. 123-sequence
There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. Input The first line contains an integer n (1 ≤ n ≤ 106). The second line contains a sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 3). Output Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. Examples Input 9 1 3 2 2 2 1 1 2 3 Output 5 Note In the example all the numbers equal to 1 and 3 should be replaced by 2.
2
7
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; /** * Created by wencan on 2015/6/4. */ public class Sequence123 { public static void main(String[] args) throws IOException { Sequence123 sequence123 = new Sequence123(); System.out.println(sequence123.resolve()); } private int resolve() throws IOException { ReaderByFastSplit reader = new ReaderByFastSplit(System.in,' '); int n = reader.nextInt(); int[] num = new int[3]; for (int i = 0; i < 3; i++) { num[i] = 0; } for (int i = 0; i < n; i++) { num[reader.nextInt() - 1]++; } reader.close(); int temp; for (int i = 0; i < 3; i++) { for (int j = i; j < 2; j++) { if (num[j] > num[j + 1]) { temp = num[j]; num[j] = num[j + 1]; num[j+1] = temp; } } } return num[0] + num[1]; } class ReaderByFastSplit { BufferedReader bufferedReader; char delimiter; String aline; int begin; int end; boolean lastToken = true; public ReaderByFastSplit(InputStream inputStream, char delimiter) throws IOException { this.bufferedReader = new BufferedReader(new InputStreamReader(inputStream)); this.delimiter = delimiter; this.aline = this.bufferedReader.readLine(); this.begin = 0; this.end = -1; } public String next() throws IOException { while(!this.hasMoreToken()) { this.aline = this.bufferedReader.readLine(); } return this.nextToken(); } private String nextToken() { return this.aline.substring(this.begin, this.end); } private boolean hasMoreToken() { this.begin = this.end + 1; this.end = this.aline.indexOf(this.delimiter, this.begin); if(this.end > 0 && this.lastToken) { return true; } else if(this.lastToken) { this.lastToken = false; this.end = this.aline.length(); return true; } else { this.lastToken = true; this.end = -1; return false; } } public void close() throws IOException { this.bufferedReader.close(); } public int nextInt() throws IOException { return Integer.parseInt(this.next()); } } }
JAVA
52_A. 123-sequence
There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. Input The first line contains an integer n (1 ≤ n ≤ 106). The second line contains a sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 3). Output Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. Examples Input 9 1 3 2 2 2 1 1 2 3 Output 5 Note In the example all the numbers equal to 1 and 3 should be replaced by 2.
2
7
#include <bits/stdc++.h> using namespace std; int main() { int n; ios_base::sync_with_stdio(false); cin >> n; int cnt1 = 0, cnt2 = 0, cnt3 = 0; for (int i = 0; i < n; i++) { int h; cin >> h; if (h == 1) cnt1++; if (h == 2) cnt2++; if (h == 3) cnt3++; } cout << min(cnt1 + cnt2, min(cnt2 + cnt3, cnt1 + cnt3)); 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(raw_input()) nums = map(int,raw_input().split()) print "%d" % (N-max(nums.count(1),nums.count(2),nums.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> int main() { long long int tes, i, b = 0, c = 0, d = 0; int a; scanf("%I64d", &tes); for (i = 0; i < tes; i++) { scanf("%d", &a); if (a == 1) b++; else if (a == 2) c++; else d++; } if (b >= c && b >= d) printf("%I64d\n", c + d); else if (c >= b && c >= d) printf("%I64d\n", b + d); else if (d >= b && d >= c) printf("%I64d\n", b + c); return 0; }
CPP
52_A. 123-sequence
There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. Input The first line contains an integer n (1 ≤ n ≤ 106). The second line contains a sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 3). Output Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. Examples Input 9 1 3 2 2 2 1 1 2 3 Output 5 Note In the example all the numbers equal to 1 and 3 should be replaced by 2.
2
7
#include <bits/stdc++.h> using namespace std; long long a, b[1000005], cnt[4]; int main() { cin >> a; for (int i = 1; i <= a; i++) { cin >> b[i]; cnt[b[i]]++; } cout << a - max(cnt[1], max(cnt[2], cnt[3])); }
CPP
52_A. 123-sequence
There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. Input The first line contains an integer n (1 ≤ n ≤ 106). The second line contains a sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 3). Output Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. Examples Input 9 1 3 2 2 2 1 1 2 3 Output 5 Note In the example all the numbers equal to 1 and 3 should be replaced by 2.
2
7
import java.util.Scanner; import java.util.StringTokenizer; /** * * @author Mohamed Ibrahim (MIM) */ public class Sequence123 { public static void main(String[] args) { Scanner s=new Scanner(System.in); s.nextLine(); String nums=s.nextLine(); int[] sums=new int[3]; sums[0]=sums[1]=sums[2]=0; StringTokenizer st=new StringTokenizer(nums); int cur=0; while(st.hasMoreTokens()){ cur=Integer.parseInt(st.nextToken()); // System.out.println(cur); if(cur==1)sums[0]++; else if(cur==2)sums[1]++; else if(cur==3)sums[2]++; } int ret=sums[0]+sums[1]+sums[2]; // System.out.println(ret); int max=Math.max(Math.max(sums[0], sums[1]), sums[2]); ret-=max; // System.out.println(); System.out.println(ret); } }
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
var n=Number(readline()); var w=readline().split(" ").map(Number); var q={1:0, 2:0, 3:0}; for (var i=0; i<n; i++) { q[w[i]]+=1; } print(n-Math.max(q[1], q[2], q[3]));
JAVA
52_A. 123-sequence
There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. Input The first line contains an integer n (1 ≤ n ≤ 106). The second line contains a sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 3). Output Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. Examples Input 9 1 3 2 2 2 1 1 2 3 Output 5 Note In the example all the numbers equal to 1 and 3 should be replaced by 2.
2
7
o = input() s = raw_input() L = list(s) a1 = L.count('1') a2 = L.count('2') a3 = L.count('3') max1 = max(a1, a2, a3) print(len(L) - L.count(" ") - max1)
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
#coding: utf-8 def main(): N = input() inp = map(int, raw_input().split()) ans = sorted([inp.count(i) for i in set(inp)] + [0], reverse=True) print sum(ans[1:]) main()
PYTHON
52_A. 123-sequence
There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. Input The first line contains an integer n (1 ≤ n ≤ 106). The second line contains a sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 3). Output Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. Examples Input 9 1 3 2 2 2 1 1 2 3 Output 5 Note In the example all the numbers equal to 1 and 3 should be replaced by 2.
2
7
import java.util.Scanner; public class ProblemA { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); int a[] = { 0, 0, 0 }; int num; for (int i = 0; i < n; i++) { num = in.nextInt(); --num; ++a[num]; } int max= Math.max(a[0], Math.max(a[1], a[2])); System.out.println(n - max); } }
JAVA
52_A. 123-sequence
There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. Input The first line contains an integer n (1 ≤ n ≤ 106). The second line contains a sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 3). Output Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. Examples Input 9 1 3 2 2 2 1 1 2 3 Output 5 Note In the example all the numbers equal to 1 and 3 should be replaced by 2.
2
7
import static java.util.Arrays.deepToString; import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; import java.io.PrintStream; import java.io.PrintWriter; import java.util.StringTokenizer; public class Main { static void solve() throws Exception { int n = nextInt(); int[] a = new int[n]; for(int i = 0; i < n; i++) { a[i] = nextInt(); } int k = 3; int ans = Integer.MAX_VALUE; for(int i = 1; i <= k; i++) { int cnt = 0; for(int j = 0; j < n; j++) { if(a[j] == i) { cnt++; } } ans = Math.min(ans, n - cnt); } out.println(ans); } static BufferedReader br; static StringTokenizer tokenizer; static PrintWriter out; static void debug(Object... a) { System.err.println(deepToString(a)); } static int nextInt() throws IOException { return Integer.parseInt(next()); } static String next() throws IOException { while (tokenizer == null || !tokenizer.hasMoreTokens()) { String line = br.readLine(); if (line == null) { return null; } tokenizer = new StringTokenizer(line); } return tokenizer.nextToken(); } static long nextLong() throws IOException { return Long.parseLong(next()); } static double nextDouble() throws IOException { return Double.parseDouble(next()); } public static void main(String[] args) { try { File file = new File("stupid_rmq.in"); InputStream input = System.in; OutputStream output = System.out; if (file.canRead()) { input = (new FileInputStream(file)); output = (new PrintStream("stupid_rmq.out")); } br = new BufferedReader(new InputStreamReader(input)); out = new PrintWriter(output); solve(); out.close(); br.close(); } catch (Throwable e) { e.printStackTrace(); System.exit(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.*; import java.util.stream.IntStream; import java.lang.Math; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); if(n == 1){ System.out.println(0); } else if(n ==2 ){ System.out.println(); System.out.println(1); } else if (n == 3){ System.out.println(); System.out.println(2); }else { Map<Integer, Integer> map = new HashMap<>(); for (int i = 0; i < n; i++) { int nums = in.nextInt(); if (map.containsKey(nums)) { map.put(nums, map.get(nums) + 1); } else { map.put(nums, 1); } } int max = 0; for (int i = 1; i <= map.size(); i++) { if (map.get(i) > max) { max = map.get(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
#include <bits/stdc++.h> using namespace std; int main() { float a, c; cin >> a; const int b = a; int A[b], B[3]; for (int i = 0; i < 3; i++) { B[i] = 0; } for (int i = 0; i < b; i++) { cin >> A[i]; } for (int i = 0; i < b; i++) { B[A[i] - 1]++; } c = 0; for (int i = 0; i < 3; i++) { if (B[i] > c) { c = B[i]; } } cout << a - c; }
CPP
52_A. 123-sequence
There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. Input The first line contains an integer n (1 ≤ n ≤ 106). The second line contains a sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 3). Output Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. Examples Input 9 1 3 2 2 2 1 1 2 3 Output 5 Note In the example all the numbers equal to 1 and 3 should be replaced by 2.
2
7
#include <bits/stdc++.h> using namespace std; int n, x[4], y, i; int main() { ios::sync_with_stdio(false); cin >> n; for (i = 0; i < n; i++) { cin >> y; x[y]++; } sort(x + 1, x + 4); cout << n - x[3]; }
CPP
52_A. 123-sequence
There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. Input The first line contains an integer n (1 ≤ n ≤ 106). The second line contains a sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 3). Output Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. Examples Input 9 1 3 2 2 2 1 1 2 3 Output 5 Note In the example all the numbers equal to 1 and 3 should be replaced by 2.
2
7
import java.io.BufferedReader; import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.StringTokenizer; public class A52 { public static void main (String args[]){ FastScanner in = new FastScanner(System.in); int n = in.nextInt(); int a[] = new int[4]; for(int i = 0 ; i < n ;i++){ a[in.nextInt()]++; } System.out.println(n - Math.max(Math.max(a[1], a[2]),a[3])); } } class FastScanner { BufferedReader br; StringTokenizer st; public FastScanner(File f) { try { br = new BufferedReader(new FileReader(f)); } catch (FileNotFoundException e) { e.printStackTrace(); } } public FastScanner(InputStream f) { br = new BufferedReader(new InputStreamReader(f)); } String next() { while (st == null || !st.hasMoreTokens()) { String s = null; try { s = br.readLine(); } catch (IOException e) { e.printStackTrace(); } if (s == null) return null; st = new StringTokenizer(s); } return st.nextToken(); } boolean hasMoreTokens() { while (st == null || !st.hasMoreTokens()) { String s = null; try { s = br.readLine(); } catch (IOException e) { e.printStackTrace(); } if (s == null) return false; st = new StringTokenizer(s); } return true; } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } }
JAVA
52_A. 123-sequence
There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. Input The first line contains an integer n (1 ≤ n ≤ 106). The second line contains a sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 3). Output Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. Examples Input 9 1 3 2 2 2 1 1 2 3 Output 5 Note In the example all the numbers equal to 1 and 3 should be replaced by 2.
2
7
#include <bits/stdc++.h> int min(int a, int b) { return a < b ? a : b; } int main() { int n; scanf("%d", &n); int i, c[3]; memset(c, 0, sizeof(c)); for (i = 0; i < n; i++) { int a; scanf("%d", &a); a--; c[a]++; } printf("%d\n", min(c[0] + c[1], min(c[0] + c[2], c[1] + c[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(raw_input()) one=0 two=0 three=0 a=map(int,(raw_input()).split()) for i in a: if i==1: one+=1 elif i==2: two+=1 elif i==3: three+=1 print min(two+three,one+three,two+one)
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; const long long maxN = 1e6 + 5; const long long inf = 1e10; const long long mod = 1e9 + 7; long long n; long long f[4]; int main() { ios_base::sync_with_stdio(0); cin >> n; long long x; for (long long i = 1; i <= n; i++) { cin >> x; f[x]++; } long long res = min(f[1] + f[2], min(f[1] + f[3], f[2] + f[3])); cout << res; return 0; }
CPP
52_A. 123-sequence
There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. Input The first line contains an integer n (1 ≤ n ≤ 106). The second line contains a sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 3). Output Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. Examples Input 9 1 3 2 2 2 1 1 2 3 Output 5 Note In the example all the numbers equal to 1 and 3 should be replaced by 2.
2
7
n=int(input()) l=list(map(int,input().split())) v=list(set(l)) if len(v)==1: print('0') elif len(v)==2: c=0 for i in range(n): if l[i]==v[0]: c+=1 if c>n//2: print(n-c) else: print(c) else: a,b,c=0,0,0 for i in range(n): if l[i]==1: a+=1 elif l[i]==2: b+=1 else: c+=1 d=max(a,b,c) print(n-d)
PYTHON3
52_A. 123-sequence
There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. Input The first line contains an integer n (1 ≤ n ≤ 106). The second line contains a sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 3). Output Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. Examples Input 9 1 3 2 2 2 1 1 2 3 Output 5 Note In the example all the numbers equal to 1 and 3 should be replaced by 2.
2
7
import java.util.*; import java.io.*; import java.math.*; public class Main { static class Reader { private InputStream mIs;private byte[] buf = new byte[1024];private int curChar,numChars;public Reader() { this(System.in); }public Reader(InputStream is) { mIs = is;} public int read() {if (numChars == -1) throw new InputMismatchException();if (curChar >= numChars) {curChar = 0;try { numChars = mIs.read(buf);} catch (IOException e) { throw new InputMismatchException();}if (numChars <= 0) return -1; }return buf[curChar++];} public String nextLine(){int c = read();while (isSpaceChar(c)) c = read();StringBuilder res = new StringBuilder();do {res.appendCodePoint(c);c = read();}while (!isEndOfLine(c));return res.toString() ;} public String s(){int c = read();while (isSpaceChar(c)) c = read();StringBuilder res = new StringBuilder();do {res.appendCodePoint(c);c = read();}while (!isSpaceChar(c));return res.toString();} public long l(){int c = read();while (isSpaceChar(c)) c = read();int sgn = 1;if (c == '-') { sgn = -1 ; c = read() ; }long res = 0; do{ if (c < '0' || c > '9') throw new InputMismatchException();res *= 10 ; res += c - '0' ; c = read();}while(!isSpaceChar(c));return res * sgn;} public int i(){int c = read() ;while (isSpaceChar(c)) c = read();int sgn = 1;if (c == '-') { sgn = -1 ; c = read() ; }int res = 0;do{if (c < '0' || c > '9') throw new InputMismatchException();res *= 10 ; res += c - '0' ; c = read() ;}while(!isSpaceChar(c));return res * sgn;} public double d() throws IOException {return Double.parseDouble(s()) ;} public boolean isSpaceChar(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public boolean isEndOfLine(int c) { return c == '\n' || c == '\r' || c == -1; } } /////////////////////////////////////////////////////////////////////////////////////////// // RRRRRRRRR AAA HHH HHH IIIIIIIIIIIII LLL // // RR RRR AAAAA HHH HHH IIIIIIIIIII LLL // // RR RRR AAAAAAA HHH HHH III LLL // // RR RRR AAA AAA HHHHHHHHHHH III LLL // // RRRRRR AAA AAA HHHHHHHHHHH III LLL // // RR RRR AAAAAAAAAAAAA HHH HHH III LLL // // RR RRR AAA AAA HHH HHH IIIIIIIIIII LLLLLLLLLLLL // // RR RRR AAA AAA HHH HHH IIIIIIIIIIIII LLLLLLLLLLLL // /////////////////////////////////////////////////////////////////////////////////////////// public static void main(String[] args)throws IOException { PrintStream out= new PrintStream(System.out); Reader sc=new Reader(); int n=sc.i(); int arr[]=new int[4]; for(int i=0;i<n;i++) arr[sc.i()]++; System.out.println(n-Math.max(arr[1],Math.max(arr[2],arr[3]))); } }
JAVA
52_A. 123-sequence
There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. Input The first line contains an integer n (1 ≤ n ≤ 106). The second line contains a sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 3). Output Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. Examples Input 9 1 3 2 2 2 1 1 2 3 Output 5 Note In the example all the numbers equal to 1 and 3 should be replaced by 2.
2
7
n = int(input()) A = input() print(n - max(A.count(a) for a in '123'))
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 b[4], c, n, l = 0, a, i; int main() { scanf("%d", &n); for (i = 0; i < n; i++) { scanf("%d", &a); b[a]++; } cout << n - max(b[1], max(b[2], b[3])) << endl; return 0; }
CPP
52_A. 123-sequence
There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. Input The first line contains an integer n (1 ≤ n ≤ 106). The second line contains a sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 3). Output Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. Examples Input 9 1 3 2 2 2 1 1 2 3 Output 5 Note In the example all the numbers equal to 1 and 3 should be replaced by 2.
2
7
n = int(input()) a = [int(x) for x in 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
n=input() A=raw_input() print n-max(A.count(str(x)) for x in xrange(1,4))
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.*; import java.math.*; public class test1A { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); in.nextLine(); char[] c = in.nextLine().toCharArray(); int ones = 0; int twos = 0; int threes = 0; for(int i=0; i<n; i++){ int ai = c[i*2] - 48; if(ai==1) ones++; else if(ai==2) twos++; else threes++; } if(ones >= twos && ones >= threes) System.out.println(twos+threes); else if(twos >= ones && twos >= threes) System.out.println(ones+threes); else System.out.println(ones+twos); } }
JAVA
52_A. 123-sequence
There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. Input The first line contains an integer n (1 ≤ n ≤ 106). The second line contains a sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 3). Output Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. Examples Input 9 1 3 2 2 2 1 1 2 3 Output 5 Note In the example all the numbers equal to 1 and 3 should be replaced by 2.
2
7
n=int(input()) l=input() if(l.count('1')>=l.count('2') and l.count('1')>=l.count('3')): print(l.count('2')+l.count('3')) elif(l.count('2')>=l.count('1') and l.count('2')>=l.count('3')): print(l.count('3')+l.count('1')) else: print(l.count('1')+l.count('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
#include <bits/stdc++.h> using namespace std; int f() { int n; cin >> n; vector<int> v(3); for (int i = 0; i < n; i++) { int t; cin >> t; v[t - 1]++; } int maxI = distance(v.begin(), max_element(v.begin(), v.end())); int res = 0; for (int i = 0; i < 3; i++) { if (i != maxI) res += v[i]; } return res; } int main() { cout << f() << "\n"; return 0; }
CPP
52_A. 123-sequence
There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. Input The first line contains an integer n (1 ≤ n ≤ 106). The second line contains a sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 3). Output Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. Examples Input 9 1 3 2 2 2 1 1 2 3 Output 5 Note In the example all the numbers equal to 1 and 3 should be replaced by 2.
2
7
import java.util.*; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int n = scanner.nextInt(); int count1 = 0; int count2 =0; int count3 =0; for(int i =0; i<n;i++){ int a = scanner.nextInt(); if(a==1){ count1++; }else if(a==2){ count2++; }else{ count3++; } } ArrayList<Integer> largest = new ArrayList<>(); largest.add(count1); largest.add(count2); largest.add(count3); int biggest = largest.indexOf(Collections.max(largest)); if(biggest==0){ System.out.println(count2+count3); }else if(biggest==1){ System.out.println(count3+count1); }else{ System.out.println(count1+count2); } } }
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 statistics import mode tot = int(input()) num = list(map(int, input().strip().split())) max_num = mode(num) z = 0 for i in num: if i == max_num: z += 1 print(tot-z)
PYTHON3
52_A. 123-sequence
There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. Input The first line contains an integer n (1 ≤ n ≤ 106). The second line contains a sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 3). Output Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. Examples Input 9 1 3 2 2 2 1 1 2 3 Output 5 Note In the example all the numbers equal to 1 and 3 should be replaced by 2.
2
7
import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Collections; import java.util.Scanner; public class A { public static void main(String[] args){ try{ // Scanner scanner = new Scanner(System.in); BufferedReader read=new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(read.readLine()); String input[] = new String[n]; input = read.readLine().split(" "); int result = 0; ArrayList<Integer> count = new ArrayList<Integer>(); for(int i=0;i<3;i++){ count.add(0); } for(int i=0;i<n;i++){ // input[i] = scanner.nextInt(); count.set(Integer.parseInt(input[i])-1,count.get(Integer.parseInt(input[i])-1)+1); } int idxMax = count.indexOf(Collections.max(count)); for(int i=0;i<3;i++){ if(i!=idxMax){ result += count.get(i); } } System.out.println(result); }catch(Exception e){ e.printStackTrace(); } } }
JAVA
52_A. 123-sequence
There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. Input The first line contains an integer n (1 ≤ n ≤ 106). The second line contains a sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 3). Output Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. Examples Input 9 1 3 2 2 2 1 1 2 3 Output 5 Note In the example all the numbers equal to 1 and 3 should be replaced by 2.
2
7
import java.util.Scanner; import java.io.BufferedReader; import java.io.InputStreamReader; public class T1 { public static void main(String args[]){ Scanner sc=new Scanner(new BufferedReader(new InputStreamReader(System.in))); int n=sc.nextInt(); int a[]=new int[4]; for(int i=0;i<n;i++){ a[sc.nextInt()]++; } int max=-2; for(int i=1;i<=3;i++){ if(a[i]>max) max=a[i]; } System.out.println(n-max); } }
JAVA
52_A. 123-sequence
There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. Input The first line contains an integer n (1 ≤ n ≤ 106). The second line contains a sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 3). Output Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. Examples Input 9 1 3 2 2 2 1 1 2 3 Output 5 Note In the example all the numbers equal to 1 and 3 should be replaced by 2.
2
7
#include <bits/stdc++.h> using namespace std; long n; int a = 0, b = 0, c = 0; void solve() { cin >> n; int tmp; for (long i = (0); i < (n); i++) { cin >> tmp; switch (tmp) { case 1: a++; break; case 2: b++; break; case 3: c++; break; } } if (a >= b && a >= c) cout << (b + c) << endl; else if (b > a && b >= c) cout << (a + c) << endl; else if (c > a && c > b) cout << (a + b) << endl; } int main(int argc, char *argv[]) { solve(); 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 sys n = int(sys.stdin.readline()) idxs = map(int, sys.stdin.readline().split(' ')) count = [0,0,0] for i in idxs: count[i-1] += 1 count.sort() print count[0]+count[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
n=input() v=map(int,raw_input().split()) print n-max(len([x for x in v if x==1]),len([x for x in v if x==2]),len([x for x in v if x==3]))
PYTHON