E. Boxers

time limit per test:2 seconds
memory limit per test:256 megabytes
input:standard input
output:standard 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\leq n\leq 150000$) — the number of boxers. The next line contains $n$ integers $a_1,a_2,…,a_n$, where $a_i$($1\leq a_i\leq 150000$) is the weight of the $i-th$ boxer.

Output

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

Examples

input

1
2
4
3 2 4 1

output

1
4

input

1
2
6
1 1 1 4 4 4

output

1
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.

题意

给你 $n$ 个数,每个数的大小可以变动的大小为 1,但 1 不能变成 0,问你最多可以有多少个不同的数。

解决方案

很明显的贪心,先把所有数排好序,统计一下数量,再扫一遍,分情况讨论,能往左靠的数就尽量往左靠(其实更好的做法就是排完序扫一遍就行了,判断一下他的前后有没有变过,不必统计…头脑不清醒,没想那么多就直接敲了,哎)。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include <bits/stdc++.h>

using namespace std;

const int maxn = 15e4 + 10;

struct node {
int u, num;
} p[maxn];

int a[maxn];
int b[maxn];

int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
int tot = 0;
sort(a + 1, a + n + 1);
for (int i = 1; i <= n; i++) {
if (a[i] == a[i - 1]) {
p[tot].num++;
} else {
p[++tot].u = a[i];
p[tot].num = 1;
}
}
int ans;
if (p[1].u == 1) {
if (p[1].num >= 2) {
ans = 2;
b[1] = 2;
} else {
ans = 1;
b[1] = 1;
}
} else {
if (p[1].num >= 3) {
b[1] = p[1].u + 1;
ans = 3;
} else if (p[1].num == 2) {
b[1] = p[1].u;
ans = 2;
} else {
b[1] = p[1].u - 1;
ans = 1;
}
}
for (int i = 2; i <= tot; i++) {
if (p[i].u > b[i - 1] + 1) {
if (p[i].num >= 3) {
b[i] = p[i].u + 1;
ans += 3;
} else if (p[i].num == 2) {
b[i] = p[i].u;
ans += 2;
} else {
b[i] = p[i].u - 1;
ans += 1;
}
} else {
if (b[i - 1] == p[i].u) {
ans++;
b[i] = p[i].u + 1;
} else if (b[i - 1] == p[i].u - 1) {
if (p[i].num == 1) {
ans += 1;
b[i] = p[i].u;
} else {
ans += 2;
b[i] = p[i].u + 1;
}
}
}
}
cout << ans << endl;
return 0;
}

晚上状态不是很好,写题的时候手忙脚乱的,犯了各种奇奇怪怪的错误,交了很多次才AC