310937: CF1911F. Boxers

Memory Limit:256 MB Time Limit:0 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

F. Boxerstime limit per test3.0 smemory limit per test256 megabytesinputstandard inputoutputstandard output

There are $n$ boxers, the weight of the $i$-th boxer is $a_i$. Each of them can change the weight by no more than $1$ 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 ​$a_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 $150001$ (but no more).

Input

The first line contains an integer $n$ ($1 \le n \le 150000$) — the number of boxers. The next line contains $n$ integers $a_1, a_2, \dots, a_n$, where $a_i$ ($1 \le a_i \le 150000$) is the weight of the $i$-th boxer.

Output

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

ExamplesInput
4
3 2 4 1
Output
4
Input
6
1 1 1 4 4 4
Output
5
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 $1$ can be increased by one (get the weight of $2$), one boxer with a weight of $4$ can be reduced by one, and the other can be increased by one (resulting the boxers with a weight of $3$ and $5$, respectively). Thus, you can get a team consisting of boxers with weights of $5, 4, 3, 2, 1$.

Output

题目大意:
题目描述了有 n 个拳击手,每个拳击手的重量是 a_i。在比赛前,他们可以改变自己的重量,但改变的范围不超过 1(重量不能变成零,必须保持为正数)。需要选择一个最大的拳击队伍,使得队伍中所有拳击手的重量都不同(即唯一性)。

输入输出数据格式:
输入:
- 第一行包含一个整数 n (1 ≤ n ≤ 150000) —— 拳击手的数量。
- 下一行包含 n 个整数 a_1, a_2, …, a_n,其中 a_i (1 ≤ a_i ≤ 150000) 是第 i 个拳击手的重量。

输出:
- 打印一个整数 —— 队伍中可能的最大人数。

示例:
输入:
4
3 2 4 1
输出:
4

输入:
6
1 1 1 4 4 4
输出:
5

注意:
- 在第一个示例中,拳击手不需要改变他们的重量 —— 可以直接用他们所有人组成一个队伍。
- 在第二个示例中,一个重量为 1 的拳击手可以增加 1(变为重量 2),一个重量为 4 的拳击手可以减少 1,另一个可以增加 1(分别得到重量为 3 和 5 的拳击手)。这样,可以得到一个由重量为 5, 4, 3, 2, 1 的拳击手组成的队伍。题目大意: 题目描述了有 n 个拳击手,每个拳击手的重量是 a_i。在比赛前,他们可以改变自己的重量,但改变的范围不超过 1(重量不能变成零,必须保持为正数)。需要选择一个最大的拳击队伍,使得队伍中所有拳击手的重量都不同(即唯一性)。 输入输出数据格式: 输入: - 第一行包含一个整数 n (1 ≤ n ≤ 150000) —— 拳击手的数量。 - 下一行包含 n 个整数 a_1, a_2, …, a_n,其中 a_i (1 ≤ a_i ≤ 150000) 是第 i 个拳击手的重量。 输出: - 打印一个整数 —— 队伍中可能的最大人数。 示例: 输入: 4 3 2 4 1 输出: 4 输入: 6 1 1 1 4 4 4 输出: 5 注意: - 在第一个示例中,拳击手不需要改变他们的重量 —— 可以直接用他们所有人组成一个队伍。 - 在第二个示例中,一个重量为 1 的拳击手可以增加 1(变为重量 2),一个重量为 4 的拳击手可以减少 1,另一个可以增加 1(分别得到重量为 3 和 5 的拳击手)。这样,可以得到一个由重量为 5, 4, 3, 2, 1 的拳击手组成的队伍。

加入题单

上一题 下一题 算法标签: