Log inSign up
Problems / B100

Sluice gate levels

300 ptsCases 15Set by dongbinna
Added October 30.

Statement

A waterway has N sluice gates laid out in order, numbered 1 through N along the direction the water flows. Each gate can be left open at a level from 0 to 9.

Gates are damaged when the current in the waterway changes sharply. So one condition is attached to a setting. Two gates whose numbers differ by 1 have to differ in level by exactly 1. If some gate is left open at level 4, for example, the next gate can be left open only at level 3 or level 5. Leaving it at level 4 or level 6 does not meet the condition.

Gate 1 is also the place the water reaches first, so it cannot be left at level 0. From gate 2 onward level 0 is allowed.

Write a program that calculates how many settings keep all of these conditions. The number of settings can grow very large, so print the remainder of the number of settings divided by 1,000,000,000.

For example, suppose N=2. Fixing the level of gate 1 first and counting the levels gate 2 can then take gives the table below.

Gate 1Level 1Level 2Level 3Level 4Level 5Level 6Level 7Level 8Level 9
Levels gate 2 can take0, 21, 32, 43, 54, 65, 76, 87, 98
Number of settings222222221

Gate 1 cannot be left at level 0, so only level 1 through level 9 come into it. When gate 1 is at level 9 there is no level 10, so only the case where gate 2 is at level 8 is left and the count is 1. Adding up every count in the table gives 17, so the answer in this example is 17.

Consider N=1 as well. There is no neighboring gate, so the condition on the level difference has nothing to check, and only the condition that gate 1 cannot be left at level 0 remains. So there are 9 settings, level 1 through level 9.

When N=3 there are 32 settings. It is worth pointing out that when N goes up by one from 2 to 3 the count grows from 17 to 32, which is not double. Level 0 can be followed only by level 1 and level 9 can be followed only by level 8, so at the levels on either end there is only one case to join on.

Input and Output Examples

Example 1

Input

2

Output

17

Example 2

Input

1

Output

9

Example 3

Input

100

Output

18404112

Input

  • First the number of sluice gates N is given on the first line. N is a natural number from 1 to 100. The input ends with this one line. The levels each gate can be left open at are not given in the input, they are always level 0 through level 9.

Output

  • Print on one line the remainder, divided by 1,000,000,000, of the number of settings that keep all of the conditions. As N grows the number of settings grows very large, so only the remainder is printed. The value before the remainder was taken must not be printed.

Requirements

  • Two gates whose numbers differ by 1 have to differ in level by exactly 1
  • Gate 1 cannot be left at level 0. From gate 2 onward level 0 is allowed
  • The level of each gate is an integer from 0 to 9
  • Print the answer as the remainder divided by 1,000,000,000
  • You must write a program that reads from standard input and writes to standard output
  • Trailing spaces at the end of a line and blank lines at the end of the output are ignored when grading
  • The languages you can use are Python and JavaScript
  • The memory limit is 256MB. The browser does not measure it, it only states it
  • The time limit is set by measuring the setter's reference solution on the same runtime
  • On this problem you submit code, not a prompt. That code runs in the browser on this device, and all that goes to the server is a fingerprint of the output and the time it took. Whether it is correct is decided by the server. The run time is a number each device reports, so the code and the device details are posted next to it on the leaderboard.
  • The output has to match the expected value down to the character. A space inside a line counts the same as any other character.
  • There are 15 cases, and 3 of them show the input together with the expected output. The rest are used only when you submit and are not shown on this page.
  • You have to pass all 15 cases to solve this.
Read the requirements carefully before solving. Tampering with the grading to make a submission look like a pass can get you sanctioned if caught. The code you submit is published on the leaderboard along with the result.

Examples

3 public cases. Judging also uses hidden cases. You have to pass all 15 cases to solve this.

Input
Expected output
1
9
2
17
100
18404112

Solution

Your code runs on this device. Only the fingerprint of the output and the elapsed time go to the server. The server decides whether it is correct.

0 chars1 lineMemory 256MB (recorded only)Reference 2.0ms

Submitting requires you to log in. Running against the public cases works without one.

You can test with 3 public cases. Submitting runs the hidden cases too.

People who solved this problem

Nobody yet. You could be the first.