#C1496. Maximum Consecutive Group Size

    ID: 44666 Type: Default 1000ms 256MiB

Maximum Consecutive Group Size

Maximum Consecutive Group Size

You are given a list of integers representing the starting times of participants in a race. The starting times may be unsorted and might contain duplicate values. Your task is to determine the size of the largest group of participants that can start together with consecutive times. Two numbers are considered consecutive if they differ by exactly 1, i.e. if for two consecutive numbers a and b, it holds that \(b = a+1\).

For example, given the list [540, 541, 542, 543, 545, 546], the largest group with consecutive times is [540, 541, 542, 543] with size 4.

Note that if there are duplicates in the list, they are not counted as consecutive. For instance, [300, 300, 300] has a maximum consecutive group of size 1.

inputFormat

The input is given from stdin and consists of two lines:

  • The first line contains an integer \(n\) representing the number of participant starting times.
  • The second line contains \(n\) space-separated integers representing the starting times.

If \(n = 0\), then the second line will be absent and you should output 0.

outputFormat

Output to stdout a single integer representing the size of the largest group of consecutive starting times.

## sample
6
540 541 542 543 545 546
4