403545: GYM101192 G ReHanoi Towers

Memory Limit:64 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

G. ReHanoi Towerstime limit per test1 secondmemory limit per test64 megabytesinputstandard inputoutputstandard output

Everybody knows the classical puzzle about Hanoi Towers. There are three rods and one of them has n rings in ascending order of radius, the biggest disk is at the bottom, smallest is at the top. The objective of the puzzle is to move all of the rings to another rod in a minimal number of steps and preserve the disk order. During one step you are allowed to move only one ring and smaller radius rings can only be put on top of bigger radius rings.

You are required to solve modified Hanoi Towers puzzle. You have four rods instead of three. All other rules are left unchanged.

Input

A single integer number n — the number of rings on the first rod.

1 ≤ n ≤ 109
Output

The minimal number of steps modulo 109 + 7.

ExamplesInput
2
Output
3
Input
8
Output
33

加入题单

算法标签: