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; foreach (x; -Mmax .. Mmax+1) foreach (y; -Mmax .. Mmax+1) foreach (z; -Mmax .. Mmax+1) { if (half_spaces.all!(hs => inside(hs,x,y,z,1))) i1++; } foreach (x; 2*(-Mmax) .. 2*Mmax+1) foreach (y; 2*(-Mmax) .. 2*Mmax+1) foreach (z; 2*(-Mmax) .. 2*Mmax+1) { if (half_spaces.all!(hs => inside(hs,x,y,z,2))) i2++; } foreach (x; 3*(-Mmax) .. 3*Mmax+1) foreach (y; 3*(-Mmax) .. 3*Mmax+1) foreach (z; 3*(-Mmax) .. 3*Mmax+1) { if (half_spaces.all!(hs => inside(hs,x,y,z,3))) i3++; } i1 %= p, i2 %= p, i3 %= p; long d1 = i1 - 4, d2 = i2 - 10 - 4*d1, d3 = i3 - 20 - 10*d1 - 4*d2; d1 %= p, d2 %= p, d3 %= p; long ans = -inv6 * ( (-N+3)%p*(-N+2)%p*(-N+1)%p + d1*(-N+2)%p*(-N+1)%p*(-N)%p + d2*(-N+1)%p*(-N)%p*(-N-1)%p + d3*(-N)%p*(-N-1)%p*(-N-2)%p) % p; if (ans < 0) ans += p; writeln( ans ); }