import sys sys.setrecursionlimit(200005) int1 = lambda x: int(x)-1 p2D = lambda x: print(*x, sep="\n") def II(): return int(sys.stdin.readline()) def LI(): return list(map(int, sys.stdin.readline().split())) def LI1(): return list(map(int1, sys.stdin.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def LLI1(rows_number): return [LI1() for _ in range(rows_number)] def SI(): return sys.stdin.readline().rstrip() # dij = [(0, 1), (-1, 0), (0, -1), (1, 0)] dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)] # inf = 10**16 md = 998244353 # md = 10**9+7 n = II() s = SI() if n == 1: if s[0] == "?": print(26) else: print(1) exit() for i in range(n-1): if s[i] != "?" and s[i] == s[i+1]: print(0) exit() for i in range(n-2): if s[i] != "?" and s[i] == s[i+2]: print(0) exit() dp = [[0]*26 for _ in range(26)] if s[0] == "?" and s[1] == "?": for i in range(26): for j in range(26): if i == j: continue dp[i][j] = 1 elif s[0] == "?": j = ord(s[1])-97 for i in range(26): if i == j: continue dp[i][j] = 1 elif s[1] == "?": i = ord(s[0])-97 for j in range(26): if i == j: continue dp[i][j] = 1 else: i = ord(s[0])-97 j = ord(s[1])-97 dp[i][j] = 1 def add(i, j, val): ndp[i][j] = (ndp[i][j]+val)%md for c in s[2:]: a = ord(c)-97 ndp = [[0]*26 for _ in range(26)] for i in range(26): for j in range(26): pre = dp[i][j] if c == "?": for nj in range(26): if nj == i or nj == j: continue add(j, nj, pre) elif a != i and a != j: add(j, a, pre) dp = ndp ans = 0 for i in range(26): for j in range(26): ans += dp[i][j] ans %= md print(ans)