#include using namespace std; using ll = long long; int main() { int h, w, k; cin >> h >> w >> k; int c = 1; for (int i = 0; i < h * w; i++) { c *= k; } vector f(c, 0); int r = 0; for (int u = 0; u < c; u++) { int p[10][10], q[3] = {}; int t = u; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { p[i][j] = t % k; t /= k; q[p[i][j]] = 1; } } int s = 0; for (int i = 0; i < k; i++) { s += q[i]; } if (s != k) continue; int g = 0; for (int x = 0; x < h; x++) { for (int y = 0; y < w; y++) { int t = 0, s = 1; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { t += p[(i + x) % h][(j + y) % w] * s; s *= k; } } g |= f[t]; } } if (g == 0) f[u] = 1, r++; } cout << r << endl; return 0; }