# D12
# D11: sample3 で WA
import sys
# sys.setrecursionlimit(10 ** 6)
import numpy as np
from numba import jit, boolean, int64, float64, typeof, types, typeof, objmode
def main():
from io import StringIO
execute(StringIO(sample), sys.stderr)
print("-- ^sample! --", file=sys.stderr)
execute(sys.stdin, sys.stdout)
if len(solve.nopython_signatures) != 1:
raise KeyboardInterrupt("!! Unexpected: wrong use of jit !!")
def execute(src, dst):
N, M,= map(int, src.readline().split())
Astring = src.readline().strip()
L = np.array([len(w) for w in Astring.split()] , dtype=np.int64)
A = np.fromstring(Astring, dtype=np.int64, sep=' ')
assert len(L) == len(A)
ans = solve(N, M, L, A)
print(ans, file=dst)
sample = """\
5 5
10 10 10 10 10
"""
@jit(nopython=True, cache=True)
def solve(N, M, L, A):
ny = dict()
for l, a in zip(L,A):
m = a % M
if (l,m) in ny :
ny[(l,m)] += 1
else :
ny[(l,m)] = 1
ans = 0
for x in A:
for l in range(1, 11):
m1 = ( x % M ) * ((10 ** l) % M ) % M
m2 = ( M - m1 ) % M
if (l,m2) in ny :
ans += ny[(l,m2)]
else:
pass
return ans
main()