#P8708. Concatenation Count

    ID: 21872 Type: Default 1000ms 256MiB

Concatenation Count

Concatenation Count

Given an array \(A_1, A_2, \dots, A_n\) of length \(n\) and an integer \(K\), you are allowed to select two different elements \(A_i\) and \(A_j\) (\(i \neq j\)) and concatenate them together in either order, i.e. either \(A_i\) followed by \(A_j\) or \(A_j\) followed by \(A_i\). Even if \(A_i = A_j\), swapping their order is considered as 2 distinct concatenations.

The concatenation is defined as follows: if you concatenate \(a\) and \(b\) (where \(b\) has \(d\) digits) then the resulting number is \(a \times 10^{d} + b\). For example, concatenating 12 and 345 can produce \(12 \times 10^{3} + 345 = 12345\) or \(345 \times 10^{2} + 12 = 34512\).

Your task is to calculate how many ways (order matters) there exist such that the concatenated integer is less than or equal to \(K\).

Note: Each ordered pair of indices \((i, j)\) satisfying the condition is counted, and the two orders are treated as distinct if they satisfy the condition independently.

inputFormat

The first line contains two integers \(n\) and \(K\).

The second line contains \(n\) integers \(A_1, A_2, \dots, A_n\).

outputFormat

Output a single integer, the number of valid concatenation ways such that the resulting integer is \(\le K\).

sample

2 12
1 2
2