Under construction

Still being built. Things may change

Sorcerers of the Round Table

Time limit2sMemory limit512 MB

Summary
Count the circular seatings of the other sorcerers, with the chairman fixed at height n, where neighbors' hat heights differ by at most p and no disliked pair sits adjacent.
Level

Hard9 of 10

Topics
Dynamic programming, Bit manipulation, Divide and conquer, Combinatorics
Solved
No attempts yet

Problem

The sorcerers of the round table are holding their privy council again. As always, they began to squabble before the agenda was even presented, and the seating order around the table proved controversial enough.

There are nn sorcerers, each identified by the height of their pointed hat. The hat heights are pairwise distinct integers from 1 to nn, and a taller hat means a more senior sorcerer. For aesthetic reasons, the hat heights of two sorcerers seated next to each other must differ by at most pp.

Some sorcerers dislike others. If sorcerer aa dislikes sorcerer bb, then bb may not sit immediately to the right of aa. The chairman, whose hat has height nn, has already sat down at the table. In how many ways can the remaining sorcerers be arranged around the table?

Input

The first line contains three integers nn, kk, and pp (1≤n≤1061 \le n \le 10^6, 0≤k≤1000000 \le k \le 100000, 0≤p≤30 \le p \le 3), separated by single spaces. They are the number of sorcerers, the number of dislikes, and the maximum allowed difference in height between adjacent hats.

Each of the next kk lines contains two integers aia_i and bib_i (1≤ai,bi≤n1 \le a_i, b_i \le n, ai≠bia_i \ne b_i), separated by a single space. This means the sorcerer with hat height aia_i dislikes the sorcerer with hat height bib_i. Each ordered pair appears at most once.

One set of tests worth 16% of the total score has n≤5n \le 5. Another, disjoint set worth 16% has p≤2p \le 2.

Output

Print a single integer: the number of possible arrangements, modulo 109+710^9 + 7.

Hint

The sorcerers can sit around the table in one of the six orders: 53124, 53142, 52143, 53412, 52314, 53214.

Examples1

  1. Example 1

    Input
    5 2 3
    1 3
    5 4
    
    Expected output
    6