#P16763. [GKS 2020 #E] Longest Arithmetic

[GKS 2020 #E] Longest Arithmetic

Problem Description

An arithmetic array is an array that contains at least 22 integers and the differences between consecutive integers are equal. For example, [99, 1010], [33, 33, 33], and [99, 77, 55, 33] are arithmetic arrays, while [11, 33, 33, 77], [22, 11, 22], and [11, 22, 44] are not arithmetic arrays.

Sarasvati has an array of NN non-negative integers. The ii-th integer of the array is AiA_i. She wants to choose a contiguous arithmetic subarray from her array that has the maximum length. Please help her to determine the length of the longest contiguous arithmetic subarray.

Input Format

The first line of the input gives the number of test cases, TT. TT test cases follow. Each test case begins with a line containing the integer NN. The second line contains NN integers. The ii-th integer is AiA_i.

Output Format

For each test case, output one line containing Case #x: y, where x is the test case number (starting from 11) and y is the length of the longest contiguous arithmetic subarray.

4
7
10 7 4 6 8 10 11
4
9 7 5 3
9
5 5 4 5 5 5 4 5 6
10
5 4 3 2 1 2 3 4 5 6
Case #1: 4
Case #2: 4
Case #3: 3
Case #4: 6

Hint

In Sample Case #1, the integers inside the bracket in the following represent the longest contiguous arithmetic subarray: 1010 77 [44 66 88 1010] 1111

In Sample Case #2, the whole array is an arithmetic array, thus the longest contiguous arithmetic subarray is the whole array.

In Sample Case #3, the longest contiguous arithmetic subarray is either [55, 55, 55] (a subarray from the fourth integer to the sixth integer) or [44, 55, 66] (a subarray from the seventh integer to the ninth integer).

In Sample Case #4, the longest contiguous arithmetic subarray is the last six integers.

Limits

1T1001 \le T \le 100.

0Ai1090 \le A_i \le 10^9.

Test Set 1

2N20002 \le N \le 2000.

Test Set 2

2N2×1052 \le N \le 2 \times 10^5 for at most 1010 test cases.

For the remaining cases, 2N20002 \le N \le 2000.