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): #二つ前 for j in range(26): if i == j: continue if S[0] == chr(i+97) or S[0] == "?": if S[1] == chr(j+97) or S[1] =="?": idx = j*26 + i dp[idx] = 1 for i in range(26): for j in range(26): idx = j*26 + i dp_pre[j] += dp[idx] #dp_prepre[i] += dp[idx] #print(dp) #print(dp_pre) #print(dp_prepre) for i in range(2,N): p = [0]*MAX p_pre = [0]*26 #p_prepre = [0]*26 p,dp = dp,p dp_pre,p_pre = p_pre,dp_pre #dp_prepre,p_prepre = p_prepre,dp_prepre #SUM = sum(p) if S[i] != "?": si = ord(S[i]) - 97 for pre in range(26): if si == pre: continue #一つ前と同じではだめ nidx = si*26 + pre dp[nidx] += p_pre[pre] - p[pre*26 + si] #print(dp[nidx]) dp[nidx] %= MOD else: #? for si in range(26): #今 for pre in range(26): #今の前 if si == pre: continue nidx = si*26 + pre dp[nidx] += p_pre[pre] - p[pre*26 + si] #print(dp[nidx]) dp[nidx] %= MOD for j in range(26): #二つ前 for k in range(26): #一つ前 if j == k: continue jkidx = k*26 + j dp_pre[k] += dp[jkidx] #dp_prepre[j] += dp[jkidx] #print(dp) #print(dp_pre) ans = sum(dp)%MOD print(ans) if __name__ == '__main__': main()