n, *a = map(int, open(0).read().split()) ans = r = 0 st = set() for l in range(n): while r