Perry the Saviour

0

0 votes
Problem

Wait! Perry Kahan Hai? 

Platypus Perry aka Agent P was on a mission when he got caught by Dr. Doofenshmirtz. While he is stuck, Dr. Doofenshmirtz explains to him his wicked plan of destroying the world. The Dr. has set up an advanced security system by setting up a password difficult to crack. Now, Perry needs to escape as soon as possible to ask Phineas and Ferb for help in punishing the (somewhat)Evil Scientist.

class="bias">Perry is stuck in a cage and needs to get out. There are n iron rods in his cell and each rod has an integer written on it denoted by wi of an array w (1in).

For each 1in Perry has three choices:

  • add 1 to wi
  • subtract 1  from wi
  • Do nothing

After this, he can select any integer X and count the number of occurrences of X in the newly formed sequence.

The maximum count of the number of occurrences of any integer X in w that Perry can achieve by making the optimal choices is the password that can lead him out of the cell. Help Perry Crack the password!

INPUT:

The first line of each input consists of an integer n (1n105)

The second line of each input consists of n integers, w1,w2,w3,..,wn (1wi105)

OUTPUT: 

For each input, output the maximal occurrences of X that you can achieve in the array by performing the above operations. 

Time Limit: 2
Memory Limit: 256
Source Limit:
Explanation

Convert the sequence into 2,2,3,2,4,8,2 by doing the operations on each index and select X=2 to obtain 4 as the maximum possible count.

Editor Image

?