#C3670. Longest Arithmetic Subarray

    ID: 47123 Type: Default 1000ms 256MiB

Longest Arithmetic Subarray

Longest Arithmetic Subarray

You are given an array of integers. Your task is to determine the length of the longest arithmetic subarray in the given array.

An arithmetic subarray is defined as a continuous subsequence of at least two elements where the difference between consecutive elements is the same. Formally, given an array \(a_1, a_2, \dots, a_n\), a subarray \(a_i, a_{i+1}, \dots, a_j\) (with \(j-i+1 \ge 2\)) is called arithmetic if there exists a constant \(d\) such that for all \(k\) with \(i \le k < j\), \(a_{k+1} - a_k = d\).

Your task is to compute the maximum length of such a subarray.

If the array has fewer than two elements, output 0.

inputFormat

The first line contains a single integer \(n\) representing the number of elements in the array.

The second line contains \(n\) space-separated integers.

outputFormat

Print a single integer which is the length of the longest arithmetic subarray.

## sample
4
3 6 9 12
4

</p>