def main(): import sys N, M_val, L, K, B = map(int, sys.stdin.readline().split()) mod = B M = M_val % mod def multiply(a, b, L, M, mod): res = [0] * L non_zero_a = [i for i in range(L) if a[i]] non_zero_b = [j for j in range(L) if b[j]] for i in non_zero_a: ai = a[i] for j in non_zero_b: bj = b[j] coeff = (ai * bj) % mod if coeff == 0: continue k = i + j if k >= L: coeff = (coeff * M) % mod k -= L res[k] = (res[k] + coeff) % mod return res def pow_poly(n, L, M, mod): result = [0] * L result[0] = 1 % mod current_base = [0] * L current_base[0] = 1 % mod if L > 1: current_base[1] = 1 % mod else: current_base[0] = (1 + M) % mod while n > 0: if n % 2 == 1: result = multiply(result, current_base, L, M, mod) current_base = multiply(current_base, current_base, L, M, mod) n = n // 2 return result poly = pow_poly(N, L, M, mod) print(poly[K] % mod) if __name__ == "__main__": main()