#include #include #include #include #include #include #include #include #include #include #include #include #include #include #define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl; #define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl; template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } using namespace std; typedef long long ll; template vector> vec2d(int n, int m, T v){ return vector>(n, vector(m, v)); } template vector>> vec3d(int n, int m, int k, T v){ return vector>>(n, vector>(m, vector(k, v))); } template void print_vector(vector v, char delimiter=' '){ if(v.empty()) { cout << endl; return; } for(int i = 0; i+1 < v.size(); i++) cout << v[i] << delimiter; cout << v.back() << endl; } using mint = atcoder::modint998244353; ostream& operator<<(ostream& os, const mint& m){ os << m.val(); return os; } using F = vector>; using S = vector; mint dp[5005][4][4][4][4][4]; int main(){ ios::sync_with_stdio(false); cin.tie(0); cout << setprecision(10) << fixed; int n, a, b, c; cin >> n >> a >> b >> c; vector> f(4, vector(4)); for(int x = 0; x < 4; x++){ vector v(4); for(int y = 0; y < 4; y++){ v[y] = (a*(x&y) + b*(x|y) + c*(x^y))%4; } f[x] = v; dp[0][x][v[0]][v[1]][v[2]][v[3]]++; } auto composition = [&](vector f, vector g){ vector ans(4); for(int i = 0; i < 4; i++) ans[i] = f[g[i]]; return ans; }; for(int i = 1; i < n-1; i++){ for(int x = 0; x < 4; x++){ for(int f0 = 0; f0 < 4; f0++){ for(int f1 = 0; f1 < 4; f1++){ for(int f2 = 0; f2 < 4; f2++){ for(int f3 = 0; f3 < 4; f3++){ for(int y = 0; y < 4; y++){ int z = (a*(x&y) + b*(x|y) + c*(x^y))%4; auto ff = composition({f0, f1, f2, f3}, f[y]); dp[i][z][ff[0]][ff[1]][ff[2]][ff[3]] += dp[i-1][x][f0][f1][f2][f3]; } } } } } } } mint ans = 0; for(int x = 0; x < 4; x++){ for(int f0 = 0; f0 < 4; f0++){ for(int f1 = 0; f1 < 4; f1++){ for(int f2 = 0; f2 < 4; f2++){ for(int f3 = 0; f3 < 4; f3++){ for(int y = 0; y < 4; y++){ int z = (a*(x&y) + b*(x|y) + c*(x^y))%4; vector f = {f0, f1, f2, f3}; if(z == f[y]) ans += dp[n-2][x][f0][f1][f2][f3]; } } } } } } cout << ans << endl; }