def main(): N = int(input()); MOD = 998244353 S = str(input()) if N == 1: if S == "?": print(26) else: print(1) exit() MAX = 26*26 #dp[i]: 一つ前がi//26,二つ前がi%26の場合 dp = [0]*MAX dp_pre = [0]*26 dp_prepre = [0]*26 for i in range(26): #二つ前 s0 = chr(i+97) if S[0] == s0 or S[0] == "?": for j in range(26): #一つ前 s1 = chr(j+97) if S[1] == s1 or S[1] == "?": idx = j*26 + i dp[idx] += 1 #for i in range(26): # for j in range(26): # dp_pre[j] += dp[i][j] # dp_prepre[i] += dp[i][j] #print(dp) for i in range(2,N): p = [0]*MAX p,dp = dp,p if S[i] != "?": si = ord(S[i]) - 97 for pre in range(26): if si == pre: continue #一つ前と同じではだめ nidx = si*26 + pre for prepre in range(26): if si == prepre: continue #二つ前と同じでもだめ if pre == prepre: continue preidx = pre*26 + prepre dp[nidx] += p[preidx] dp[nidx] %= MOD else: #? for now in range(26): for pre in range(26): if now == pre: continue for prepre in range(26): if now == prepre: continue if pre == prepre: continue nidx = now*26 + pre preidx = pre*26 + prepre dp[nidx] += p[preidx] dp[nidx] %= MOD #print(dp) ans = sum(dp)%MOD print(ans) if __name__ == '__main__': main()