import std.stdio, std.algorithm, std.array, std.conv; void main() { auto NMK = readln.split.to!(ulong[]); auto N = NMK[0], M = NMK[1], K = NMK[2]; F_2Vector[] matrix; foreach (i; 0 .. M) { F_2Vector vec; auto str = readln[0 .. $-1]; foreach (j; 0 .. N) { set_entry(vec, j, str[j] == cast(immutable) '1'); } matrix ~= vec; } ulong ans = 1; auto r = get_rank(matrix); foreach (i; 0 .. N-r) ans = 2 * ans % K; writeln(ans); } // F_2 matrix alias F_2Vector = size_t[40]; immutable ulong_size = 64; void set_entry(ref F_2Vector vector, ulong n_th, bool val) { if (val) vector[n_th / ulong_size] |= 1UL << n_th % ulong_size; else vector[n_th / ulong_size] &= ~0UL - (1UL << (n_th % ulong_size)); } bool is_zero(F_2Vector vector) { foreach (e; vector) if (e != 0) return false; return true; } F_2Vector slide_vector(F_2Vector vector) { F_2Vector slided; foreach (i; 0 .. vector.length - 1) { slided[i] = vector[i+1]; } return slided; } // by sweep // vectors can change uint get_rank(F_2Vector[] vectors ...) { if (vectors.all!(v => is_zero(v))) return 0; // make the left-most vector nonzero while (vectors.all!(v => v[0] == 0)) vectors.each!((ref v) => v = slide_vector(v)); while (vectors.all!(v => v[0] % 2 == 0)) vectors.each!((ref v) => v[0] >>= 1); foreach (ref v; vectors) { if (v[0] % 2 != 0) { auto tmp = vectors[0]; vectors[0] = v; v = tmp; } } // sweeping foreach (ref v; vectors[1 .. $]) { if (v[0] % 2 != 0) v[] ^= vectors[0][]; } vectors[1 .. $].map!((ref v) => v[0] >>= 1); return 1 + get_rank(vectors[1 .. $]); }