Order#2419

Order

1 second
64 megabytes
Very easy

In some institutions, documents are numbered in an unusual way. One set of digits is used for odd positions, and generally a different set is used for even positions (positions are numbered from right to left starting from ). In different years, different sets of digits may be used. The only strict rule is that, within the given constraints, numbers are not skipped and are maintained in ascending order.

For example, if the digits , , are used for odd positions, and , are used for even positions, then the first few numbers are: , , , , , , , , , , , , , ...

Given the sets of digits used and a specific document number, write a program to determine its position in the sequence starting from .

Input

The first line contains three numbers , , . is the given document number, and and are the number of digits used in odd and even positions, respectively. The second line lists the digits used in odd positions, and the third line lists the digits used in even positions, separated by spaces.

1 \leq N \leq 10^{55}, 2 \leq K, L \leq 10.

Output

The output should contain a single line with the answer. It is guaranteed that the answer fits within 2^{64}-1.

Examples

Example 1

Loading
Loading