시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 512 MB216533723.270%

문제

우체국에서 파는 우표 중에서 가격이 1원인 우표는 총 N종류가 있고, 2원인 우표는 총 M종류가 있다.

우표를 K원어치 구매하는 방법의 수를 구하는 프로그램을 작성하시오.

같은 종류의 우표를 여러 개 사도 가능하며, 우체국에는 우표가 무한대 만큼 있다. 정확하게 K원을 모두 사용해야 한다.

입력

첫째 줄에 N, M, K, P가 주어진다. (0 ≤ N, M ≤ 300, 1 ≤ K ≤ 1012, 3 ≤ P ≤ 1,000,000, P는 소수)

출력

첫째 줄에 우표를 사는 방법의 수를 P로 나눈 나머지를 출력한다.

예제 입력 1

0 10 2 47

예제 출력 1

10

예제 입력 2

2 2 4 47

예제 출력 2

14

예제 입력 3

5 5 10 47

예제 출력 3

6
W3sicHJvYmxlbV9pZCI6IjEzNTQyIiwicHJvYmxlbV9sYW5nIjoiMCIsInRpdGxlIjoiXHVjNmIwXHVkNDVjIFx1YWQ2Y1x1YjllNFx1ZDU1OFx1YWUzMCAoSGFyZCkiLCJkZXNjcmlwdGlvbiI6IjxwPlx1YzZiMFx1Y2NiNFx1YWQ2ZFx1YzVkMFx1YzExYyBcdWQzMGNcdWIyOTQgXHVjNmIwXHVkNDVjIFx1YzkxMVx1YzVkMFx1YzExYyBcdWFjMDBcdWFjYTlcdWM3NzQgMVx1YzZkMFx1Yzc3OCBcdWM2YjBcdWQ0NWNcdWIyOTQgXHVjZDFkIE5cdWM4ODVcdWI5NThcdWFjMDAgXHVjNzg4XHVhY2UwLCAyXHVjNmQwXHVjNzc4IFx1YzZiMFx1ZDQ1Y1x1YjI5NCBcdWNkMWQgTVx1Yzg4NVx1Yjk1OFx1YWMwMCBcdWM3ODhcdWIyZTQuPFwvcD5cclxuXHJcbjxwPlx1YzZiMFx1ZDQ1Y1x1Yjk3YyBLXHVjNmQwXHVjNWI0XHVjZTU4IFx1YWQ2Y1x1YjllNFx1ZDU1OFx1YjI5NCBcdWJjMjlcdWJjOT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