PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#SP0000222. Tổng chữ số nguyên tố liên tiếp (Prime Digit Sums)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Tổng chữ số nguyên tố liên tiếp (Prime Digit Sums)

Prime Digit Sums

Source: HackerRank

Version: Phuoc Hung OJ Extended

Problem Statement

Chloe notices that certain groups of consecutive decimal digits have prime sums. She defines three rules for a positive integer:

  • The sum of every 3 consecutive digits is prime.
  • The sum of every 4 consecutive digits is prime.
  • The sum of every 5 consecutive digits is prime.

If the integer has fewer than 3, 4, or 5 digits, the corresponding rule has no group to check. A positive nn-digit integer cannot start with 0.

Given nn, count all positive integers having exactly nn decimal digits that satisfy these rules. Print the result modulo 109+710^9+7.

Input

The only line contains nn, the required number of decimal digits.

Output

Print the number of valid nn-digit positive integers modulo 109+710^9+7.

Subtasks

  • Subtask 1 (20 points): 1≤n≤201\le n\le 20.

  • Subtask 2 (30 points): 1≤n≤20001\le n\le 2000.

  • Subtask 3 (50 points): 1≤n≤4000001\le n\le 400000.

Examples

Input

6

Output

95

Explanation

For n=6n=6, examine four length-3 digit groups, three length-4 groups, and two length-5 groups. For example, 283002283002 is valid: the sums for groups of 3 digits are 13,11,3,213,11,3,2; for groups of 4 digits they are 13,11,513,11,5; and for groups of 5 digits they are 13,1313,13. Every listed sum is prime. Any six-digit integer with a non-prime sum for at least one required group is invalid.

The counts for lengths 3,4,5,63,4,5,6 are respectively 303,280,218,95303,280,218,95. Thus the required six-digit count is 95.