MOD = 998244353 n = int(input()) S = input() dp = [0, 0, 0] ans = 0 for s in S: if s == "?": lst = list(range(10)) else: lst = [int(s)] for x in lst: ans += dp[-x % 3] if x % 3 == 0: ans += 1 ans %= MOD ndp = [0] * 3 for x in lst: ndp[x % 3] += 1 for i in range(3): ndp[(i + x) % 3] += dp[i] ndp[(i + x) % 3] %= MOD dp = ndp print(ans)