class Solution: def longestSubsequence(self, a: List[int], d: int) -> int: di = {} for v in a: di[v] = di.get(v-d, 0) + 1 return max(di.values())