#include const int Mod = 998244353; int main() { int N, A, B, C; scanf("%d %d %d %d", &N, &A, &B, &C); int x, y, im[4][4]; for (x = 0; x < 4; x++) for (y = 0; y < 4; y++) im[x][y] = (A * (x & y) + B * (x | y) + C * (x ^ y)) % 4; int i, j, k, l, ii, jj, kk, ll, cur, prev; long long dp[2][4][4][4][4][4] = {}, tmp; for (x = 0; x < 4; x++) dp[0][x][im[x][0]][im[x][1]][im[x][2]][im[x][3]] = 1; for (N -= 2, cur = 1, prev = 0; N > 0; N--, cur ^= 1, prev ^= 1) { for (x = 0; x < 4; x++) { for (i = 0; i < 4; i++) { for (j = 0; j < 4; j++) { for (k = 0; k < 4; k++) { for (l = 0; l < 4; l++) { if (dp[prev][x][i][j][k][l] == 0) continue; tmp = dp[prev][x][i][j][k][l] % Mod; dp[prev][x][i][j][k][l] = 0; for (y = 0; y < 4; y++) { ii = (im[0][y] == 0)? i: (im[0][y] == 1)? j: (im[0][y] == 2)? k: l; jj = (im[1][y] == 0)? i: (im[1][y] == 1)? j: (im[1][y] == 2)? k: l; kk = (im[2][y] == 0)? i: (im[2][y] == 1)? j: (im[2][y] == 2)? k: l; ll = (im[3][y] == 0)? i: (im[3][y] == 1)? j: (im[3][y] == 2)? k: l; dp[cur][im[x][y]][ii][jj][kk][ll] += tmp; } } } } } } } long long ans = 0; for (x = 0; x < 4; x++) { for (i = 0; i < 4; i++) { for (j = 0; j < 4; j++) { for (k = 0; k < 4; k++) { for (l = 0; l < 4; l++) { if (dp[prev][x][i][j][k][l] == 0) continue; tmp = dp[prev][x][i][j][k][l] % Mod; if (im[x][0] == i) ans += tmp; if (im[x][1] == j) ans += tmp; if (im[x][2] == k) ans += tmp; if (im[x][3] == l) ans += tmp; } } } } } printf("%lld\n", ans % Mod); fflush(stdout); return 0; }