ABABABAB

Consider the following formula:

A + B * A + B * A + B * A + B

We can obtain many different values by replacing each A with an
arbitrary number from set 𝒜, and each B with an arbitrary number from
set ℬ.

Even more, in this problem we are allowed to place parentheses in any
way we want. For example, (A + B) * (A + B) * (A + B) * (A + B) can be a
very big number. We don’t like very big numbers.

Output the number of ways we can obtain a result which is at most M.

Input

The first line of input contains four numbers: N, M, Q_(A), Q_(B). We
have 1 ≤ N ≤ 16, 1 ≤ M ≤ 1000, 1 ≤ Q_(A), Q_(B) ≤ 1000. N is the number
of operands (8 in the formula above, it always starts with A).

The second line contains Q_(A) non-negative integers — these are the
elements of 𝒜. Each of them is different, and in range from 0 to 10000.

The third line contains Q_(B) non-negative integers — these are the
elements of ℬ. Each of them is different, and in range from 0 to 10000.

Output

Output the number of ways of obtaining at most M, modulo 1000003.

Problem information

Author: Eryk Kopczynski

Generation: 2026-01-25T22:30:02.330Z

© Jutge.org, 2006–2026.
https://jutge.org
