------
## 最终结论
```python
def longestArithSeqLength(A):
    if not A:
        return 0

    n = len(A)
    dp = [{} for _ in range(n)]
    max_length = 2

    for i in range(n):
        for j in range(i):
            diff = A[i] - A[j]
            if diff in dp[j]:
                dp[i][diff] = dp[j][diff] + 1
            else:
                dp[i][diff] = 2
            max_length = max(max_length, dp[i][diff])

    return max_length

# Example usage
A1 = [3, 6, 9, 12]
A2 = [9, 4, 7, 2, 10]
A3 = [20, 1, 15, 3, 10, 5, 8]

print(longestArithSeqLength(A1)) # Output: 4
print(longestArithSeqLength(A2)) # Output: 3
print(longestArithSeqLength(A3)) # Output: 4
```