N = int(input()) A = map(int, input().split()) x = [] ans = 0 for i in A: if len(x) >= 2 and x[-1] == x[-2] == i: ans += 3 x.pop() x.pop() else: x.append(i) print(ans)