시간 제한 메모리 제한 제출 정답 맞은 사람 정답 비율
1 초 32 MB 239 56 36 31.034%

문제

삼각분할이란 볼록 다각형의 대각선을 이용해서 삼각형으로 분할하는 것이다. 두 대각선은 교차할 수 없다. 삼각분할을 이루는 대각선의 집합이 다르면 두 삼각분할은 서로 다른 삼각분할이다. (꼭짓점에 1번부터 N번까지 번호를 붙인다)

오각형을 삼각분할하는 방법은 총 다섯가지가 있으며, 아래 그림과 같다.

Tn을 n각형을 삼각분할하는 방법의 수라고 했을 때, T3 + T4 + ... + Tn을 구하는 프로그램을 작성하시오.

입력

첫째 줄에 n과 m이 주어진다. (3 ≤ n ≤ 100,000, 2 ≤ m ≤ 109)

출력

T3 + ... + Tn을 m으로 나눈 나머지를 출력한다.

예제 입력 1

5 1000

예제 출력 1

8
W3sicHJvYmxlbV9pZCI6Ijc3MzciLCJwcm9ibGVtX2xhbmciOiIwIiwidGl0bGUiOiJcdWMwYmNcdWFjMDFcdWJkODRcdWQ1NjAiLCJkZXNjcmlwdGlvbiI6IjxwPlx1YzBiY1x1YWMwMVx1YmQ4NFx1ZDU2MFx1Yzc3NFx1Yjc4MCBcdWJjZmNcdWI4NWQgXHViMmU0XHVhYzAxXHVkNjE1XHVjNzU4IFx1YjMwMFx1YWMwMVx1YzEyMFx1Yzc0NCBcdWM3NzRcdWM2YTlcdWQ1NzRcdWMxMWMgXHVjMGJjXHVhYzAxXHVkNjE1XHVjNzNjXHViODVjIFx1YmQ4NFx1ZDU2MFx1ZDU1OFx1YjI5NCBcdWFjODNcdWM3NzRcdWIyZTQuIFx1YjQ1MCBcdWIzMDBcdWFjMDFcdWMxMjBcdWM3NDAgXHVhZDUwXHVjYzI4XHVkNTYwIFx1YzIxOCBcdWM1YzZcdWIyZTQuIFx1YzBiY1x1YWMwMVx1YmQ4NFx1ZDU2MFx1Yzc0NCBcdWM3NzRcdWI4ZThcdWIyOTQgXHViMzAwXHVhYzAxXHVjMTIwXHVjNzU4IFx1YzlkMVx1ZDU2OVx1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