mod = 998244353 N = int(input()) A = list(map(int, input().split())) ans = 0 dp = [0]*5 dp[1] = 1 for i in range(N): new_dp = [0]*5 if i