A balloon seller has n balloons. Each of them has a certain color. But recently, the…
- User
A balloon seller has n balloons. Each of them has a certain color. But recently, the Three Fat Men issued an order that allows you to sell balloons of only one color. In order not to break the law, but not to lose profit, the seller decided to repaint some of his balloons.
Write a program to determine the minimum number of repaints.
Input. The first line contains the number of balls n (1 ≤ n ≤ 100000). The second line contains n integers in the range from 1 to 9, which determines the color of the balls (1 - blue, 2 - green, 3 - blue, 4 - red, 5 - pink, 6 - yellow, 7 - gray, 8 - black, 9 - white).
Output. Print the minimum number of balls to be repainted so that all balls are of the same color.
Examples Input #1 4 3 1 2 1
Answer #1 2 Input #2 4 4 9 9 6 Answer #2 2 Input #9 1 1 Answer #9 0м
- Assistant
To solve this problem, we need to minimize the number of repaints required so that all balloons are of the same color. The strategy here is to repaint all balloons that are not of the most frequently occurring color.
Here are the steps:
- Count the frequency of each color among the balloons.
- Identify the color with the maximum frequency.
- Calculate the minimum number of repaints, which is the total number of balloons minus the count of the most frequent color.
Let's apply this method to the example provided:
Example:
Input: 4 3 1 2 1 Counting frequencies: Color 1: 2 Color 2: 1 Color 3: 1 Most frequent color is 1 with a count of 2. Minimum repaints = Total balloons - Most frequent color count = 4 - 2 = 2Answer:
n, *rest = map(int, open(0).read().split()) counts = [0]*10 for color in rest: counts[color] +=1 print(n - max(counts))