PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#GL0000302. Ghép số thành bội (Concatenated Multiples)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Ghép số thành bội (Concatenated Multiples)

Concatenated Multiples

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

You are given an array of nn positive integers a1,a2,…,ana_1,a_2,\ldots,a_n and an integer kk.

The concatenation of xx and yy is obtained by writing the full decimal representation of yy immediately after that of xx. For example, concatenating 1212 and 34563456 produces 123456123456.

Count the ordered pairs of positions (i,j)(i,j) with 1≤i,j≤n1\le i,j\le n and i≠ji\ne j for which concatenating aia_i before aja_j gives an integer divisible by kk.

Different positions are counted separately even if their values are equal; (i,j)(i,j) and (j,i)(j,i) are different pairs.

Input

The first line contains two integers nn and kk.

The second line contains exactly nn integers a1,a2,…,ana_1,a_2,\ldots,a_n in array order.

Output

Print one integer: the number of valid ordered pairs of positions.

Subtasks

  • Subtask 1 (20 points): 1≤n≤601\le n\le60; 2≤k≤1002\le k\le100; 1≤ai≤1031\le a_i\le10^3 for all 1≤i≤n1\le i\le n.
  • Subtask 2 (30 points): 1≤n≤60001\le n\le6000; 2≤k≤1062\le k\le10^6; 1≤ai≤1071\le a_i\le10^7 for all 1≤i≤n1\le i\le n.
  • Subtask 3 (50 points): 1≤n≤2⋅1051\le n\le2\cdot10^5; 2≤k≤1092\le k\le10^9; 1≤ai≤1091\le a_i\le10^9 for all 1≤i≤n1\le i\le n.

Examples

Example 1

Input

6 11
45 1 10 12 11 7

Output

7

Explanation

The seven valid position pairs are (1,2),(1,3),(2,3),(3,1),(3,4),(4,2),(4,3)(1,2),(1,3),(2,3),(3,1),(3,4),(4,2),(4,3). They produce 451,4510,110,1045,1012,121,1210451,4510,110,1045,1012,121,1210, all divisible by 1111.

Example 2

Input

4 2
2 78 4 10

Output

12

Explanation

Every aja_j ends with an even digit, so every concatenation is divisible by 22. There are 4⋅3=124\cdot3=12 ordered pairs with different positions.

Example 3

Input

5 2
3 7 19 3 3

Output

0

Explanation

Every value ends in an odd digit. A concatenation ends with the last digit of aja_j, so none is divisible by 22.