시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 128 MB40141137.931%

문제

3 × N개의 점이 찍혀있는 직사각형 그리드가 있다. 그리드 상의 모든 점은 최대 8개의 이웃한 점을 가지고 있다.

그리드 상의 점을 연결해서 만들 수 있는 다각형의 개수를 구하려고 한다. 다각형은 아래와 같은 조건을 만족해야 한다.

  1. 꼭짓점은 3 × N개 모두로 이루어져 있어야 한다.
  2. 다각형에서 인접한 꼭짓점은 그리드상에서 이웃한 점이어야 한다.
  3. 단순 다각형이어야 한다. 즉, 변이 교차하며 안 된다.

아래 그림은 N=6인 경우에 가능한 두 가지 다각형이다.

N이 주어졌을 때, 만들 수 있는 다각형의 개수를 구하는 프로그램을 작성하시오.

입력

첫째 줄에는 양의 정수 N이 주어진다. (N ≤ 1,000,000,000).

출력

다각형의 만드는 방법의 수를  1,000,000,000로 나눈 나머지를 출력한다.

예제 입력 1

3

예제 출력 1

8

예제 입력 2

4

예제 출력 2

40
W3sicHJvYmxlbV9pZCI6IjI0MzQiLCJwcm9ibGVtX2xhbmciOiIwIiwidGl0bGUiOiJcdWM4MTAgXHVjNWYwXHVhY2IwXHVkNTU4XHVhZTMwIiwiZGVzY3JpcHRpb24iOiI8cD4zICZ0aW1lczsgTlx1YWMxY1x1Yzc1OCBcdWM4MTBcdWM3NzQgXHVjYzBkXHVkNjAwXHVjNzg4XHViMjk0IFx1YzljMVx1YzBhY1x1YWMwMVx1ZDYxNSBcdWFkZjhcdWI5YWNcdWI0ZGNcdWFjMDAgXHVjNzg4XHViMmU0LiBcdWFkZjhcdWI5YWNcdWI0ZGMgXHVjMGMxXHVjNzU4IFx1YmFhOFx1YjRlMCBcdWM4MTBcdWM3NDAgXHVjZDVjXHViMzAwIDhcdWFjMWNcdWM3NTggXHVjNzc0XHVjNmMzXHVkNTVjIFx1YzgxMFx1Yzc0NCBcdWFjMDBcdWM5YzBcdWFjZTAgXHVjNzg4XHViMmU0LjxcL3A+XHJcblxyXG48cCBzdHlsZT1cInRleH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