#C3272. Longest Stable Operation Period

    ID: 46681 Type: Default 1000ms 256MiB

Longest Stable Operation Period

Longest Stable Operation Period

In this problem, you are given a sequence of operations performed hourly. Each operation is indicated by either 1 (representing an activation or 'on') or -1 (representing a deactivation or 'off'). The task is to determine the length of the longest contiguous segment during which the same operation occurs. In other words, if we denote the operations by ( a_1, a_2, \ldots, a_n ), you are to find the maximum value of ( k ) such that ( a_i = a_{i+1} = \cdots = a_{i+k-1} ) for some valid index ( i ).

For example, if the input operations are: 1 1 -1 1 1 -1 -1 1 1 1, the longest stable period is 3 (the last three operations are all 1).

inputFormat

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

  1. The first line contains a single integer ( n ) which is the number of operations.
  2. The second line contains ( n ) space-separated integers. Each integer is either 1 or -1, representing an operation.

outputFormat

Output to standard output (stdout) a single integer representing the length of the longest contiguous segment in which all operations are the same.## sample

0
0