MOD = 998244353 n = int(input()) a = list(map(int, input().split())) p = 0 for i in range(n): if a[i-1] == 0 and a[i] == 1: p += 1 p %= MOD print((p * pow(n, -1, MOD)) % MOD)