#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; string s; int k, i = 0; int e[3][3] = { {1,2,1},{2,0,0},{1,0,0} }; int a[3][3] = { {0,1,2},{1,1,2},{2,2,2} }; long long mod = 998244353; typedef struct { long long x, y, z; }t; t expression(int &i){ if (s[i] == 'm') { i++; t ans = { 0,0,0 }; if (s[i] == '?') { i += 3; t left = expression(i); i++; t right = expression(i); long long l[3] = { left.x,left.y,left.z }; long long r[3] = { right.x,right.y,right.z }; long long ans1[3] = { 0,0,0 }; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { ans1[e[i][j]] += l[i] * r[j] % mod; ans1[a[i][j]] += l[i] * r[j] % mod; ans1[e[i][j]] %= mod; ans1[a[i][j]] %= mod; } } ans.x += ans1[0], ans.y += ans1[1], ans.z += ans1[2]; } else if (s[i] == 'e') { i += 3; t left = expression(i); i++; t right = expression(i); long long l[3] = { left.x,left.y,left.z }; long long r[3] = { right.x,right.y,right.z }; long long ans1[3] = { 0,0,0 }; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { ans1[a[i][j]] += l[i] * r[j] % mod; ans1[a[i][j]] %= mod; } } ans.x += ans1[0], ans.y += ans1[1], ans.z += ans1[2]; } else if (s[i] == 'a') { i += 3; t left = expression(i); i++; t right = expression(i); long long l[3] = { left.x,left.y,left.z }; long long r[3] = { right.x,right.y,right.z }; long long ans1[3] = { 0,0,0 }; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { ans1[a[i][j]] += l[i] * r[j] % mod; ans1[a[i][j]] %= mod; } } ans.x += ans1[0], ans.y += ans1[1], ans.z += ans1[2]; } i++; return { ans.x % mod,ans.y % mod,ans.z % mod }; } else { if (s[i] == '0') { i++; return { 1,0,0 }; } else if (s[i] == '1') { i++; return { 0,1,0 }; } else if (s[i] == '2') { i++; return { 0,0,1 }; } else { i++; return { 1,1,1 }; } } } int main() { cin >> s >> k; t ans = expression(i); if (k == 0)cout << ans.x <