from itertools import * H, W, K = map(int, input().split()) S = set() ans = 0 for tup in product(range(K), repeat=H * W): if len(set(tup)) != K: continue G =[[0] * W for i in range(H)] for j in range(H * W): x, y = divmod(j, W) G[x][y] = tup[j] now = 1 v = 0 for i in range(H): for j in range(W): v += G[(x + i)%H][(y + j)%W] * now now *= K if v not in S: ans += 1 for x in range(H): for y in range(W): now = 1 v = 0 for i in range(H): for j in range(W): v += G[(x + i)%H][(y + j)%W] * now now *= K S.add(v) print(ans)