local mfl, mce = math.floor, math.ceil local mod = 998244353 local n = io.read("*n", "*l") local s = io.read() local t = {} for i = 1, n do t[i] = s:sub(i, i) end for i = 1, n - 1 do if t[i] == t[i + 1] and t[i] ~= "?" then print(0) os.exit() end end for i = 1, n - 2 do if t[i] == t[i + 2] and t[i] ~= "?" then print(0) os.exit() end end if n == 1 then print(t[1] == "?" and 26 or 1) os.exit() end local dp1, dp2 = {}, {} if t[1] == "?" and t[2] == "?" then for i = 1, 26 do for j = 1, 26 do local v = (i - 1) * 26 + j dp1[v] = i == j and 0 or 1 end end elseif t[1] == "?" then local i2 = t[2]:byte() - 96 for i = 1, 26 do for j = 1, 26 do local v = (i - 1) * 26 + j if i == i2 or j ~= i2 then dp1[v] = 0 else dp1[v] = 1 end end end elseif t[2] == "?" then local i1 = t[1]:byte() - 96 for i = 1, 26 do for j = 1, 26 do local v = (i - 1) * 26 + j if i ~= i1 or j == i1 then dp1[v] = 0 else dp1[v] = 1 end end end else local i1 = t[1]:byte() - 96 local i2 = t[2]:byte() - 96 for i = 1, 26 do for j = 1, 26 do local v = (i - 1) * 26 + j if i ~= i1 or j ~= i2 then dp1[v] = 0 else dp1[v] = 1 end end end end for i = 3, n do local src = i % 2 == 1 and dp1 or dp2 local dst = i % 2 == 1 and dp2 or dp1 for j = 1, 676 do dst[j] = 0 end for prv_state = 1, 676 do local srcval = src[prv_state] local prvprv = mce(prv_state / 26) local prv = prv_state - (prvprv - 1) * 26 if t[i] == "?" then for j = 1, 26 do if j ~= prvprv and j ~= prv then local d = (prv - 1) * 26 + j dst[d] = dst[d] + srcval end end else local z = t[i]:byte() - 96 for j = 1, 26 do if j == z and j ~= prvprv and j ~= prv then local d = (prv - 1) * 26 + j dst[d] = dst[d] + srcval end end end end for j = 1, 676 do dst[j] = dst[j] % mod end end local tbl = n % 2 == 1 and dp2 or dp1 local ret = 0 for i = 1, 676 do ret = ret + tbl[i] end print(ret % mod) -- print(os.clock())