Under construction

Still being built. Things may change

Normalizing the Stone Piles

Time limit1sMemory limit1024 MB

Summary
Count the permutations of piles for which the greedy rule (the player with fewer stones takes the next pile) leaves both players with equal totals, modulo 1,000,000,007.
Level

Medium7 of 10

Topics
Dynamic programming, Combinatorics, Math
Solved
No attempts yet

Problem

Heewon and Chaewan came up with a fun game using NN stone piles lying on the floor. Pile ii has AiA_i stones.

First, they make a permutation TT of length NN in which each number from 1 to NN appears exactly once. Then, over NN turns in total, they play the game on each turn ii, from the first turn to the NN-th turn, as follows.

  • If the number of stones Heewon has taken so far is less than Chaewan's, Heewon takes all stones from pile TiT_i.
  • Otherwise, Chaewan takes all stones from pile TiT_i.

After the game ends, find the number of permutations TT that make the number of stones taken by the two players equal.

Input

The first line contains the number of stone piles NN. (1≤N≤100)(1 \leq N \leq 100)

The second line contains the numbers of stones A1,A2,⋯ ,ANA_1, A_2, \cdots, A_N in piles 11 through NN, separated by spaces. (1≤Ai≤20)(1 \leq A_i \leq 20)

Output

Print the number of permutations TT that make the two players' totals equal, modulo 1 000 000 0071\,000\,000\,007.

Examples2

  1. Example 1

    Input
    3
    1 2 3
    
    Expected output
    4
    
  2. Example 2

    Input
    4
    1 2 3 4
    
    Expected output
    8