You are a coach at your local university. There are n students under your supervision, the programming skill of the i-th student is ai.
You have to create a team for a new programming competition. As you know, the more students some team has the more probable its victory is! So you have to create a team with the maximum number of students. But you also know that a team should be balanced. It means that the programming skill of each pair of students in a created team should differ by no more than 5.
Your task is to report the maximum possible number of students in a balanced team.
Input:
The first line of the input contains integer n (1≤n≤2⋅105) — the number of students.
The second line of the input contains n integers a1,a2,…,an (1≤ai≤109), where ai is a programming skill of the i-th student.
Output:
Print the maximum possible number of students in a balanced team.
Examples
Input:
6
1 10 17 12 15 2
Output:
3
(In this example you can create a team with skills [12,17,15], all the element(programming skills) in this array have a difference of not more than 5)
def diff5(team=[]): i,j=0,0 while(i<len(team)): while(j<len(team)): if(i!=j and abs(team[i]-team[j])>=5): team.pop(j) j+=1 i+=1 return team #Driver N=int(input('')) Arr=list(map(int,input('').split(' '))) N=len(Arr) # lol L=[] Arr.sort() for i in range(len(Arr)): temp=[] temp.append(Arr[i]) for j in range(len(Arr)): if(i!=j and abs(Arr[i]-Arr[j]) <= 5): temp.append(Arr[j]) L.append(diff5(temp)) print("") print(max([len(i) for i in L]),"\n")
INPUT_1:
6
1 10 17 12 15 2
OUTPUT:
3
INPUT_2:
10
1337 1337 1337 1337 1337 1337 1337 1337 1337 1337
OUTPUT:
10
INPUT_3:
6
1 1000 10000 10 100 10000000
OUTPUT:
1
INPUT_4:
6
36 4 1 25 9 16
OUTPUT:
2
ILLUSTRATION
Morae Q!
- Find the length of the array’s longest increasing sub-sequence.
- Arrange numbers in a circle so that any two neighbouring numbers differ by 1.
- Find partial names and count the total numbers.
- Find the minimized sum of non-deleted elements of the array after the end of the game.
- Find the maximum number of good sleeping times optimally.
- Sort the elements of the array in the order in which they are required.
- Find the minimum number of flats, monkey needs to visit to catch ninjas.
- Convert the square matrix to matrix in Z form.
- Shift the K elements of each row to right of the matrix.
- Find maximum possible number of students in a balanced team with skills.
- Find the Maximum number of pairs of points you can match with each other.
- Calculate the number of non-empty good subarrays of given array.
- Transform the binary string A into the string B using finite operations.
- Find the number of potion must the character take to jump the hurdles.
- Count the total number of vowels and consonants.
- Return all elements of the matrix in spiral order.
- Return all palindromic paths of the matrix.
- Write the code to change the display in reverse order using pointer.
- Find the number of days the expedition can last.
- Find the minimum size of the sub-segment to make the array pairwise distinct.