cswork / OAOpen practice workspace

UberOA #10

Spy Access Code Fragments

Estimated MediumJudge-ready

Topics (AI-labelled)HashingStrings

Count the ordered pairs of distinct indices (i,j) such that concatenating the canonical decimal representations of the two positive integers, in that order, gives exactly accessCode. Different indices holding the same value are still different choices.

This site's standard input/output is stated explicitly.

Input

The first line contains n, the second line contains n positive integers fragments, and the third line contains the positive integer accessCode. 2≤n≤30000, 1≤fragments[i]≤10⁹. The source places no upper bound on the target; on this site the target is a positive integer with at most 20 digits, since more than 20 digits cannot be formed from two valid fragments.

Output

Output one integer answer.

Example 1

Input:

5
12 12 13 12 12
1212

Output:

12

Example 2

Input:

4
22 8 22 110
1108

Output:

1

Example 3

Input:

5
777 7 777 77 77
7777

Output:

6

Example notes

Example 1: choosing different indices among four 12s gives 4×3=12 pairs. Example 2: only 110 followed by 8 works, 1 pair. Example 3: 777 followed by 7 gives 2 pairs, 7 followed by 777 gives 2 pairs, and the two 77s concatenated with each other give 2 pairs, 6 in total.

Editorial

Loading solution…