Cowmpetency

시간 제한2초메모리 제한1024 MB

요약
길이 N의 점수열에서 Q개의 조건, 각 조건이 앞선 모든 값보다 큰 최초 위치를 지정할 때 가능한 수열의 개수를 센다.
난이도

어려움10점 중 8점

유형
동적 계획법, 조합론, 수학
정답자
아직 제출이 없습니다

문제

Farmer John is hiring a new herd leader for his cows. To that end, he has interviewed NN (2≤N≤1092 \leq N \leq 10^9) cows for the position. After each interview, he assigned an integer "cowmpetency" score to the candidate ranging from 11 to CC (1≤C≤1041 \leq C \leq 10^4) that is correlated with their leadership abilities.

Because he has interviewed so many cows, Farmer John has forgotten all of their cowmpetency scores. However, he does remembers QQ (1≤Q≤min⁡(N−1,100)1 \leq Q \leq \min(N - 1, 100)) pairs of numbers (a_i,h_i)(a\_i, h\_i) where cow h_ih\_i was the first cow with a strictly greater cowmpetency score than cows 11 through a_ia\_i (so 1≤a_i<h_i≤N1 \leq a\_i < h\_i \leq N).

Farmer John now tells you the QQ pairs of (a_i,h_i)(a\_i, h\_i). Help him count how many sequences of cowmpetency scores are consistent with this information! It is guaranteed that there is at least one such sequence. Because this number may be very large, output its value modulo 109+710^9 + 7.

입력

The first line contains NN, QQ, and CC.

The next QQ lines each contain a pair (a_i,h_i)(a\_i, h\_i). It is guaranteed that all a_ja\_j are distinct.

출력

The number of sequences of cowmpetency scores consistent with what Farmer John remembers, modulo 109+710^9+7.

예제2

  1. 예제 1

    입력
    6 2 3
    2 3
    4 5
    
    예상 출력
    6
    
  2. 예제 2

    입력
    10 1 20
    1 3
    
    예상 출력
    399988086