using System; using static System.Console; using System.Linq; using System.Collections.Generic; class Program { static int NN => int.Parse(ReadLine()); static double[] NList => ReadLine().Split().Select(double.Parse).ToArray(); static double[][] NArr(long n) => Enumerable.Repeat(0, (int)n).Select(_ => NList).ToArray(); public static void Main() { Solve(); } static void Solve() { var n = NN; var s = ReadLine(); var mod = 998_244_353; var ans = 0L; var dp = new long[3]; for (var i = 0; i < n; ++i) { var ndp = new long[3]; if (s[i] == '?') { ndp[0] += 4; ndp[1] += 3; ndp[2] += 3; for (var j = 0; j < 3; ++j) { ndp[j] = (ndp[j] + dp[j] * 4 % mod) % mod; ndp[(j + 1) % 3] = (ndp[(j + 1) % 3] + dp[j] * 3 % mod) % mod; ndp[(j + 2) % 3] = (ndp[(j + 2) % 3] + dp[j] * 3 % mod) % mod; } } else { ndp[(s[i] - '0') % 3] += 1; for (var j = 0; j < 3; ++j) ndp[(j + s[i] - '0') % 3] = (ndp[(j + s[i] - '0') % 3] + dp[j]) % mod; } ans = (ans + ndp[0]) % mod; dp = ndp; } WriteLine(ans); } }