#C13235. Longest Contiguous Arithmetic Subarray
Longest Contiguous Arithmetic Subarray
Longest Contiguous Arithmetic Subarray
Given an array of integers, your task is to find the longest contiguous subarray that forms an arithmetic sequence. An arithmetic sequence is a sequence of numbers where the difference between consecutive elements is constant. Formally, a sequence \( a, a+d, a+2d, \dots \) is arithmetic, where \( d \) is the common difference.
If there are multiple subarrays with the maximum length, return the first one encountered. If the length of the array is less than 2 or no arithmetic subarray can be found, output an empty result.
Note: The input is read from standard input and the result must be printed to standard output.
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 elements of the longest contiguous arithmetic subarray in order, separated by a single space. If there is no valid arithmetic subarray (i.e. when \( n < 2 \)), output an empty line.
## sample9
1 3 5 7 9 10 20 30 40
1 3 5 7 9
</p>