tinycodinglm / cf /cf-1003-A.jsonl
winapiadmin's picture
Upload folder using huggingface_hub
1f3a244 verified
|
Raw History Blame Contribute Delete
1.93 kB
opencode trace
System You are an expert competitive programmer. You solve problems by analyzing requirements, designing algorithms, and writing clean, efficient code.

You are an expert competitive programmer. You solve problems by analyzing requirements, designing algorithms, and writing clean, efficient code.

User

Problem: Polycarp's Pockets (Rating: 800)
Tags: implementation

Polycarp has $n$ coins, the value of the $i$-th coin is $a_i$. Polycarp wants to distribute all the coins between his pockets, but he cannot put two coins with the same value into the same pocket.

For example, if Polycarp has got six coins represented as an array $a = [1, 2, 4, 3, 3, 2]$, he can distribute the coins into two pockets as follows: $[1, 2, 3], [2, 3, 4]$.

Polycarp wants to distribute all the coins with the minimum number of used pockets. Help him to do that.

Input: The first line of the input contains one integer $n$ ($1 \le n \le 100$) — the number of coins.

The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 100$) — values of coins.

Output: Print only one integer — the minimum number of pockets Polycarp needs to distribute all the coins so no two coins with the same value are put into the same pocket.

Examples:
Input: 6
1 2 4 3 3 2
Output: 2

Input: 1
100
Output: 1

Assistant

We have to find the maximum number of elements with the same value (it can be done by counting). This number will be the answer because if there are no more than $$$k$$$ elements with the same value in the array it is obvious that we cannot use less than $$$k$$$ pockets, but we also doesn't need to use more than $$$k$$$ pockets because of the other values can be also distributed using $$$k$$$ pockets.
Overall complexity is $$$O(n + maxAi)$$$.