## https://yukicoder.me/problems/no/1646 MOD = 998244353 def is_palindrome(word): left = 0 right = len(word) - 1 while left < right: if word[left] != word[right]: return False left += 1 right -= 1 return True def main(): N = int(input()) S = input() # ありえる状態を番号づけ states_list = [""] for a in range(26): states_list.append(chr(a + ord("a"))) for a in range(26): for b in range(26): x = chr(a + ord("a")) + chr(b + ord("a")) states_list.append(x) state_map = {} for from_i, before_word in enumerate(states_list): state_map[before_word] = from_i # before + word -> afterの対応表を作る state_trans_map =[[-1] * 26 for _ in range(len(states_list))] for from_i, before_word in enumerate(states_list): for a in range(26): word = before_word + chr(a + ord("a")) if len(word) >= 2 and is_palindrome(word): continue if len(word) > 2: word = word[-2:] if len(word) >= 2 and is_palindrome(word): continue after_i = state_map[word] state_trans_map[from_i][a] = after_i dp = [0] * len(states_list) dp[0] = 1 for s in S: new_dp = [0] * len(states_list) if s == "?": target = -1 else: target = ord(s) - ord("a") for from_i in range(len(states_list)): for x in range(26): if target == -1 or target == x: after_i = state_trans_map[from_i][x] if after_i != -1: new_dp[after_i] += dp[from_i] new_dp[after_i] %= MOD dp = new_dp answer = 0 for i in range(len(dp)): answer += dp[i] answer %= MOD print(answer) if __name__ == "__main__": main()