import std.algorithm, std.array, std.container, std.conv, std.math, std.range, std.stdio, std.typecons; immutable long p = 998244353; immutable long inv6 = 166374059; // inv6 * 6 % p = 1 immutable Mmax = 25; void main() { auto NM = readln.split.to!(uint[]); auto N = NM[0] % p, M = NM[1]; long[][] half_spaces; foreach (m; 0 .. M) { half_spaces ~= readln.split.to!(long[]); } bool inside(long[] half_space, long x, long y, long z, long n) { return (half_space[0]*x + half_space[1]*y + half_space[2]*z + half_space[3]*n > 0); } // count long i1, i2, i3, i4; foreach (x; -Mmax+1 .. Mmax) foreach (y; -Mmax+1 .. Mmax) foreach (z; -Mmax+1 .. Mmax) { if (half_spaces.all!(hs => inside(hs,x,y,z,1))) i1++; } foreach (x; 2*(-Mmax)+1 .. 2*Mmax) foreach (y; 2*(-Mmax)+1 .. 2*Mmax) foreach (z; 2*(-Mmax)+1 .. 2*Mmax) { if (half_spaces.all!(hs => inside(hs,x,y,z,2))) i2++; } foreach (x; 3*(-Mmax)+1 .. 3*Mmax) foreach (y; 3*(-Mmax)+1 .. 3*Mmax) foreach (z; 3*(-Mmax)+1 .. 3*Mmax) { if (half_spaces.all!(hs => inside(hs,x,y,z,3))) i3++; } foreach (x; 4*(-Mmax)+1 .. 4*Mmax) foreach (y; 4*(-Mmax)+1 .. 4*Mmax) foreach (z; 4*(-Mmax)+1 .. 4*(Mmax)) { if (half_spaces.all!(hs => inside(hs,x,y,z,4))) i4++; } i1 %= p, i2 %= p, i3 %= p, i4 %= p; long a0 = -inv6 *i1 + 3*inv6 *i2 - 3*inv6 *i3 + inv6 *i4, a1 = 9*inv6 *i1 - 4 *i2 + 21*inv6 *i3 - i4, a2 = -26*inv6 *i1 + 57*inv6 *i2 - 7 *i3 + 11*inv6 *i4, a3 = 4 *i1 - 6 *i2 + 4 *i3 - i4; a0 %= p, a1 %= p, a2 %= p, a3 %= p; if (a0 < 0) a0 += p; if (a1 < 0) a1 += p; if (a2 < 0) a2 += p; if (a3 < 0) a3 += p; writeln( ((a0*N%p*N%p*N%p) + (a1*N%p*N%p) + (a2*N%p) + a3 ) % p ); }