#K63857. Longest Increasing Arithmetic Subsequence

    ID: 31846 Type: Default 1000ms 256MiB

Longest Increasing Arithmetic Subsequence

Longest Increasing Arithmetic Subsequence

You are given an array of integers. Your task is to determine the length of the longest subsequence that forms a strictly increasing arithmetic progression.

An arithmetic progression is a sequence of numbers of the form \(a, a+d, a+2d, \ldots\), where \(d\) (the common difference) is a non-zero constant. The subsequence you choose must have at least two elements to form an arithmetic progression. If the array has fewer than 2 elements, output 0.

Note: The subsequence does not need to be contiguous.

inputFormat

The input is read from stdin as follows:

  • The first line contains a single integer \(T\), the number of test cases.
  • For each test case, the first line contains an integer \(n\), the number of elements in the array.
  • The second line contains \(n\) space-separated integers representing the array.

outputFormat

For each test case, output a single integer on a separate line to stdout representing the length of the longest subsequence that forms a strictly increasing arithmetic progression. If no valid subsequence exists, output 0.

## sample
3
5
1 2 3 4 5
6
1 7 10 13 14 19
4
5 10 15 20
5

4 4

</p>