cswork / OA打开练习工作台

Susquehanna International GroupOA #4

Access Code Fragments — Concatenation Pairs

估计中等可在线判题

考点(AI 标注)哈希计数字符串

You are given positive integer fragments and a positive integer accessCode. Two fragments at different positions can be placed in either order, and their decimal representations are concatenated directly (not added). Count all ordered position pairs whose concatenation equals accessCode. Each fragment position can be used only once; swapping the positions of two fragments with the same value also counts as a different way.

输入格式

The first line contains N and accessCode (1≤N≤100000, 1≤accessCode≤10^18). The second line contains N positive integer fragments, each at most 10^9. Integers are written in canonical decimal form without leading zeros.

输出格式

Output the number of ordered position pairs that form accessCode.

样例 1

输入:

4 1212
1 212 12 12

输出:

3

样例 2

输入:

4 121
2 12 1 21

输出:

2

样例 3

输入:

2 1212
212 1

输出:

1

样例说明

Enumerate every split of accessCode into two non-empty parts. For each split, look up the occurrence counts of the left and right fragments; when both sides are the same, subtract the cases where the same position would be used twice.