class Solution:
    def longestArithSeqLength(self, A: List[int]) -> int:
        dic = {}
        for i in range(1, len(A)):
            for j in range(i-1, -1, -1):
                d = A[i]-A[j]
                dic[(d, i)] = max(dic.get((d, i), 0), dic.get((d,j), 1)+1)
        return max(dic.values())

