#C7468. Longest Consecutive Difference Subarray

    ID: 51342 Type: Default 1000ms 256MiB

Longest Consecutive Difference Subarray

Longest Consecutive Difference Subarray

Given an array of integers, find the longest contiguous subarray in which every pair of adjacent elements has an absolute difference of 1. In other words, for a subarray A, for every consecutive pair \(A[i]\) and \(A[i+1]\), it must hold that \(|A[i]-A[i+1]| = 1\). If there are multiple subarrays with the same maximum length, return the one that appears first.

Example:

Input: 9
       2 2 3 4 2 3 4 3 2
Output: 2 3 4 3 2

Your task is to implement a program that reads the input from standard input and writes the output to standard output following the format specified below.

inputFormat

The first line of input contains a single integer \(n\) representing the number of elements in the array. The second line contains \(n\) space-separated integers.

outputFormat

Output the longest contiguous subarray that satisfies the condition. Print the elements separated by a single space.

## sample
1
5
5