#C4953. Longest Contiguous Equal Subarray

    ID: 48548 Type: Default 1000ms 256MiB

Longest Contiguous Equal Subarray

Longest Contiguous Equal Subarray

Given an array of integers, your task is to find the longest contiguous subarray where all elements are equal. Formally, let (A = [a_1, a_2, \ldots, a_n]) be the input array. You need to identify the segment (A[i\ldots j]) (with (1 \leq i \leq j \leq n)) such that every element in this segment is identical and its length (L = j-i+1) is maximized. In case of ties (i.e. multiple subarrays of equal maximum length), return the subarray that appears first in the array. The answer should be output as a sequence of integers separated by a single space.

inputFormat

The input is given via standard input. The first line contains a single integer (n) ((n \ge 0)), representing the number of elements in the array. If (n > 0), the second line contains (n) space-separated integers.

outputFormat

Output the longest contiguous subarray (i.e. the segment where all elements are equal) in a single line with each number separated by a space. If the array is empty, output nothing.## sample

11
1 2 2 2 1 1 1 3 3 3 3
3 3 3 3