Under construction

Still being built. Things may change

How Many Unicycles in a Wheel?

Time limit1sMemory limit512 MB

Summary
Count the number of spanning unicycles (spanning trees plus one edge forming a single cycle) in a wheel graph of size m, output modulo 100007.
Level

Medium7 of 10

Topics
Combinatorics, Graph, Math, Dynamic programming
Solved
No attempts yet

Problem

A wheel graph of size nn is a cycle of nn vertices, each of which is connected to a center vertex. Examples of wheel graphs of size 4, 5, 6, and 8 are shown below.

A spanning unicycle in a graph GG is a spanning tree in GG with one additional edge added to form a single cycle. Each of the examples below is a spanning unicycle in a wheel graph of size 5.

Write a program to compute the number of different unicycles in a wheel graph of size nn. Recall that two subgraphs S1S_1 and S2S_2 of a graph GG are different if there is at least one edge of GG that is in S1S_1 and not in S2S_2, or an edge in S2S_2 which is not in S1S_1.

Input

Input consists of a single line that contains a decimal integer mm (3≤m≤40003 \le m \le 4000), which is the size of the wheel graph to find the number of unicycles of.

Output

The single output line consists of the count of unicycles modulo 100007100007 for the input size mm.

Examples2

  1. Example 1

    Input
    5
    
    Expected output
    170
    
  2. Example 2

    Input
    1234
    
    Expected output
    17511