
#include <iostream>
#include <vector>
#include <math.h>
using namespace std;
bool ok(vector<int> &A)
{
int n = A.size();
if(n < 2)
return true;
int max = A[0];
int min = A[0];
for(int i=1; i<n; i++)
{
if(max < A[i])
max = A[i];
if(min > A[i])
min = A[i];
}
return abs(max - min)<2;
}
int maxSum = 0;
void dfs(int dep, int n, vector<int> &A, vector<int> &tmp)
{
if(dep >= n)
{
if(ok(tmp) && tmp.size() > maxSum)
maxSum = tmp.size();
return;
}
tmp.push_back(A[dep]);
dfs(dep+1, n, A, tmp);
tmp.pop_back();
dfs(dep+1, n, A, tmp);
}
int solution(vector<int> &A)
{
int n = A.size();
if(n < 1)
return 1;
vector<int> tmp;
dfs(0, n, A, tmp);
return maxSum;
}
int main()
{
vector<int> a;
a.push_back(6);
a.push_back(10);
a.push_back(6);
a.push_back(9);
a.push_back(7);
a.push_back(8);
cout << solution(a) << endl;
getchar();
getchar();
}