C++#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 2010, M = 5010, B1 = 131, mod1 = 1e9 + 7, B2 = 171, mod2 = /*6e8 + 7313*/998244353;
int n, l, h1[N], h2[N];
struct Big
{
int num[M];
Big()
{
memset(num, 0, sizeof num);
num[0] = 1;
}
void set()
{
for (int i = 1; i <= num[0]; i++) num[i] = 0;
num[0] = 1;
}
void set(string s)
{
num[0] = s.size();
for (int i = 1; i <= num[0]; i++)
{
num[i] = s[num[0] - i] - '0';
}
}
} a[N];
Big operator + (const Big& a, const Big& b)
{
Big c;
c.num[0] = max(a.num[0], b.num[0]);
int d = 0;
for (int i = 1; i <= max(a.num[0], b.num[0]); i++)
{
int t = a.num[i] + b.num[i] + d;
c.num[i] = t % 10;
d = t / 10;
}
while (d)
{
c.num[++c.num[0]] = d % 10;
d /= 10;
}
return c;
}
Big operator * (const Big& a, int b)
{
Big c;
c = a;
c.num[0]++;
for (int i = c.num[0]; i >= 2; i--)
{
c.num[i] = c.num[i - 1];
}
while (c.num[0] > 1 && !c.num[c.num[0]]) c.num[0]--;
return c;
}
Big operator % (Big a, int b)
{
Big c, t;
while (a.num[0] > b)
{
c.set();
for (int i = 1; i <= a.num[0]; i += b)
{
t.set();
for (int j = 0; j < b && i + j <= a.num[0]; j++)
{
t = t * 10;
t.num[1] = a.num[i + j];
}
c = c + t;
}
a = c;
}
if (a.num[0] < b) return a;
for (int i = 1; i <= a.num[0]; i++)
{
if (a.num[i] != 9) return a;
}
a.set();
return a;
}
int hash1(Big a)
{
int res = 0;
for (int i = 1; i <= a.num[0]; i++)
{
res = res * 10 % mod1 + a.num[i];
res %= mod1;
}
return res;
}
int hash2(Big a)
{
int res = 0;
for (int i = 1; i <= a.num[0]; i++)
{
res = res * 10 % mod2 + a.num[i];
res %= mod2;
}
return res;
}
unordered_map<int, int> mp;
signed main()
{
freopen("sum.in", "r", stdin);
freopen("sum.out", "w", stdout);
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
cin >> n >> l;
for (int i = 1; i <= n; i++)
{
string s;
cin >> s;
a[i].set(s);
a[i] = a[i] % l;
h1[i] = hash1(a[i]), h2[i] = hash2(a[i]);
}
int ch21 = 0, ch22 = 0, ch31 = 1, ch32 = 1;
for (int i = 1; i <= l; i++)
{
ch21 = ch21 * 10 % mod1 + 9;
ch22 = ch22 * 10 % mod2 + 9;
}
// for (int i = 1; i < l; i++)
// {
// ch31 = ch31 * B1 % mod1 + 9;
// ch32 = ch32 * B2 % mod2 + 9;
// }
// ch31 = ch31 * B1 % mod1 + 8;
// ch32 = ch32 * B2 % mod2 + 8;
ch31=ch21*2%mod1;
ch32=ch22*2%mod2;
int ans = 0;
for (int i = 1; i <= n; i++)
{
mp[h1[i] * mod2 + h2[i]] ++;
for (int j = i; j <= n; j++)
{
int x1 = (0 - h1[i] - h1[j] + 2 * mod1) % mod1 * mod2 + (0 - h2[i] - h2[j] + 2 * mod2) % mod2;
int x2 = (ch21 - h1[i] - h1[j] + 2 * mod1) % mod1 * mod2 + (ch22 - h2[i] - h2[j] + 2 * mod2) % mod2;
int x3 = (ch31 - h1[i] - h1[j] + 2 * mod1) % mod1 * mod2 + (ch32 - h2[i] - h2[j] + 2 * mod2) % mod2;
if (mp.count(x1)) ans += mp[x1];
if (mp.count(x2)) ans += mp[x2];
if (mp.count(x3)) ans += mp[x3];
}
}
cout << ans << '\n';
return 0;
}