PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#QHD0000038. Kiến bò trên tứ diện (Tetrahedron)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Kiến bò trên tứ diện (Tetrahedron)
Tetrahedron
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
A tetrahedron has four vertices labeled . Every pair of distinct vertices is joined by an edge.
An ant starts at vertex . On every step, it must traverse an edge to a different vertex; remaining at the current vertex is forbidden.
Count the paths of exactly steps that end at vertex again. Two paths are different if the vertex visited at any step differs. Print the answer modulo .
Input
One line containing integer , the exact number of steps.
Output
Print the number of walks from back to in exactly steps, modulo .
Subtasks
- Subtask 1 (20 points): .
- Subtask 2 (30 points): .
- Subtask 3 (50 points): .
Examples
Input
2
Output
3
Explanation
On the first step the ant moves from to one of . The second step returns it to . The three paths are , , and , giving answer .