This page is still under construction.

Parts of this page are still being built. What you see may change.

Erasing Game

Time limit1sMemory limit128 MB

Summary
Count the ordered sequences A whose entries can each be matched to a distinct entry of S that is at least as large.
Level

Medium7 of 10

Topics
Combinatorics, Sorting, Dynamic programming, Greedy
Solved
No attempts yet

Problem

Hongjun and Myungwoo play a game with sequences. Hongjun first writes down a sequence AA of NN natural numbers, chosen however he likes, and Myungwoo writes down a sequence SS of the same length in the same way.

The game runs for NN rounds. In round ii, Hongjun has to erase one number from his own sequence AA that is not greater than SiS_i. If no such number is left, Hongjun loses. If he finishes all NN rounds, Hongjun wins.

Given Myungwoo's sequence SS, count the sequences AA that let Hongjun win when he plays with an optimal strategy. Two sequences with the same numbers in a different order count as different sequences.

Input

The first line contains the length NN. (1≤N≤2001 \le N \le 200)

The ii-th of the next NN lines contains SiS_i. (1≤Si≤1091 \le S_i \le 10^9)

Output

Print the number of sequences AA that Hongjun can win with, modulo 1,000,000,007.

Hint

For N=2N = 2 and S=(1,2)S = (1, 2), the sequences AA that Hongjun can win with are (1,1)(1, 1), (1,2)(1, 2), and (2,1)(2, 1).

Examples1

  1. Example 1

    Input
    2
    1
    2
    
    Expected output
    3