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