from itertools import product n = int(input()) S = input() mod = 998244353 def count(s): a = s n = len(a) ret = 0 #配列は末から dp=[[[0] * 3 for _ in range(2)] for _ in range(n+1) ] for i in range(n) : if a[i]=='?': max_d = 9 for d in range(max_d+1): mod3_ = d % 3 leading0_ = d==0 dp[i + 1][leading0_][mod3_] += 1 else: d = int(a[i]) mod3_ = d % 3 leading0_ = d==0 dp[i + 1][leading0_][mod3_] += 1 #条件に合わせてDP for leading0, mod3 in product(range(2), range(3)): if a[i]=='?': max_d = 9 for d in range(max_d+1): mod3_ = (mod3*10 + d) % 3 leading0_ = leading0 and d==0 dp[i + 1][leading0_][mod3_] = (dp[i + 1][leading0_][mod3_]+dp[i][leading0][mod3])%mod else: d = int(a[i]) if leading0==0 and d==0: continue leading0_ = leading0 and d==0 mod3_ = (mod3*10 + d) % 3 dp[i + 1][leading0_][mod3_] = (dp[i + 1][leading0_][mod3_]+dp[i][leading0][mod3])%mod ret = (ret+dp[i+1][0][0]+dp[i+1][1][0])%mod return ret%mod print(count(S))