Nike likes playing cards and makes a problem of it.
Now give you n integers, ai(1≤i≤n)ai(1≤i≤n)
We define two identical numbers (eg: 2,22,2) a Duizi,
and three consecutive positive integers (eg: 2,3,42,3,4) a Shunzi.
Now you want to use these integers to form Shunzi and Duizi as many as possible.
Let s be the total number of the Shunzi and the Duizi you formed.
Try to calculate max(s)max(s).
Each number can be used only once.
InputThe input contains several test cases.
Now give you n integers, ai(1≤i≤n)ai(1≤i≤n)
We define two identical numbers (eg: 2,22,2) a Duizi,
and three consecutive positive integers (eg: 2,3,42,3,4) a Shunzi.
Now you want to use these integers to form Shunzi and Duizi as many as possible.
Let s be the total number of the Shunzi and the Duizi you formed.
Try to calculate max(s)max(s).
Each number can be used only once.
For each test case, the first line contains one integer n( 1≤n≤1061≤n≤106).
Then the next line contains n space-separated integers aiai ( 1≤ai≤n1≤ai≤n)
OutputFor each test case, output the answer in a line.
Sample Input
7 1 2 3 4 5 6 7 9 1 1 1 2 2 2 3 3 3 6 2 2 3 3 3 3 6 1 2 3 3 4 5Sample Output
2
4
3
2
Hint
Case 1(1,2,3)(4,5,6) Case 2(1,2,3)(1,1)(2,2)(3,3) Case 3(2,2)(3,3)(3,3) Case 4(1,2,3)(3,4,5)
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<ctype.h>
#include<stack>
#include<math.h>
#include <string>
#include<algorithm>
#include<iomanip>
/*
½¨Á¢Êý×é´¢´æËùÓÐÅÆ µÄÊýÁ¿£¬È»ºó´Ó¶Ô×Ó¿ªÊ¼Êý£¬ÓжÔ×Ó´ò¶Ô×Ó£¬Ê£ÏµÄÆæÊýÅƹ¹³É˳×Ó£¬
Ö»ÒªµÚÒ»ÕÅÅÆʱÆæÊý ÅжϵڶþÕÅÅÆÊÇ·ñΪÆæÊý£¬ÊÇ×é³É˳×Ó£¬ÒòΪÕâÖÖÇé¿öÏ¿ÉÒÔ×î´óÏ޶ȵÄÀûÓÃÅÆ
´Ó¶øÊ£ÏÂ×î¶àµÄÅÆ£¬
*/
const int maxn = 1000005;
using namespace std;
int card[maxn];
int main() {
int n;
while(~scanf("%d",&n)) {
int ans = 0;
memset(card,0,sizeof(card));
int v;
for(int i = 1; i<= n; i++) {
cin>>v;
card[v]++;
}
for(int i = 1; i <= n; i++) {
ans += (card[i]/2);
card[i] %= 2;
if(card[i]&&card[i+1]&&card[i + 1]%2/* ÆæÊý*/ &&card[i+2])//sshunzi
{
ans++;
card[i]--;
card[i+1]--;
card[i+2]--;
}
}
cout<<ans<<endl;
}
return 0;
}