li = list(map(int, input().split()))[:-1] n = len(li) dp = [[[400001] * 5 for _ in range(5)] for _ in range(n + 1)] dp[-1][0][0] = 0 def check(c, n): if c == n: return 1 elif c == 0: return 2 elif n in [c + 1, c - 1, c - 3, c + 3]: return 3 else: return 4 for i in range(n): for j in range(5): for k in range(5): dp[i][li[i]][j] = min(dp[i][li[i]][j], dp[i - 1][k][j] + check(k, li[i])) for j in ra..