CF BUDDY
← Problems·

1203E · Boxers

1500 · greedy, sortings

Problem: There are nn boxers, the weight of the ii-th boxer is aia_i. Each of them can change the weight by no more than 11 before the competition (the weight cannot become equal to zero, that is, it must remain positive). Weight is always an integer number.

It is necessary to choose the largest boxing team in terms of the number of people, that all the boxers' weights in the team are different (i.e. unique).

Write a program that for given current values ​aia_i will find the maximum possible number of boxers in a team.

It is possible that after some change the weight of some boxer is 150001150001 (but no more).

Input Format: The first line contains an integer nn (1n1500001 \le n \le 150000) — the number of boxers. The next line contains nn integers a1,a2,,ana_1, a_2, \dots, a_n, where aia_i (1ai1500001 \le a_i \le 150000) is the weight of the ii-th boxer.

Output Format: Print a single integer — the maximum possible number of people in a team.

Note: In the first example, boxers should not change their weights — you can just make a team out of all of them.

In the second example, one boxer with a weight of 11 can be increased by one (get the weight of 22), one boxer with a weight of 44 can be reduced by one, and the other can be increased by one (resulting the boxers with a weight of 33 and 55, respectively). Thus, you can get a team consisting of boxers with weights of 5,4,3,2,15, 4, 3, 2, 1.

Sample Cases

Case 1

Input

4
3 2 4 1

Output

4

Case 2

Input

6
1 1 1 4 4 4

Output

5

Similar problems

00:00:00
Loading editor…
Welcome! I'm your coding tutor for this problem. Use the chips below to reveal stored hints or get AI feedback on your code. I'll guide you step by step — never giving away the solution.

Sign in to unlock AI tutor feedback