from math import isqrt n, m, b = map(int, input().split()) r = pow(m, n, b) x = [0] * 6 x[5] = isqrt(r) r -= x[5] ** 2 x[4] = isqrt(r) r -= x[4] ** 2 def f(r): for i in range(r + 1): for j in range(r + 1): for k in range(r + 1): rest = r - i ** 2 - j ** 2 - k ** 2 l = isqrt(rest) if l ** 2 == rest: return i, j, k, l assert False x[:4] = f(r) print(*x)