Diagrams & Tableaux#7016

Diagrams & Tableaux

1 second
64 megabytes
Easy

A Young diagram is an arrangement of boxes in rows and columns conforming to the following rules:

Here are some examples of Young diagrams:

A semi-standard Young tableau for a given number is a Young diagram that has its boxes filled according to the following rules:

Here is a list of all semi-standard Young tableaux for N = 3, based on a particular Young diagram:

Your task is to count how many semi-standard Young tableaux are possible, based on a given Young diagram, with a given .

Input

Each test case consists of two lines. The first line of each test case specifies the Young diagram. This line starts with the number satisfying 1 \leq k \leq 7, the number of rows, followed by positive integers l_1, l_2, ..., l_k. These integers specify the number of boxes on each row of the Young diagram, and they satisfy 7 \geq l_1 \geq l_2 \geq \ldots \geq l_k \geq 1. The second line contains the integer , satisfying k \leq N \leq 7.

Output

For each test case, print one line containing the number of semi-standard Young tableaux based on the given Young diagram, with the given .

Examples

Example 1

Loading
Loading