#include<bits/stdc++.h>

using namespace std;

#define pii pair < int , int >

#define ll unsigned long long int

#define ff first

#define ss second

map < int , int > mp[11];

int ara[200005],length[200005];

int find_len(int n)
{
    int len=0;

    while(n)
    {
        len++;

        n/=10;
    }

    return len;
}

int main()
{
    int n,k,i,j;

    scanf("%d %d",&n,&k);

    for(i=1; i<=n; i++)
    {
        scanf("%d",&ara[i]);

        int len=find_len(ara[i]);

        mp[len][ara[i]%k]++;

        length[i]=len;

    }

    long long int ans=0;

    for(i=1; i<=n; i++)
    {
        ll cur=10;

        int num=ara[i]%k,len=1;

        while(cur<=1e10)
        {
            ll val=num*cur;

            ll rem=k-(val%k);

            if(rem==k) rem=0;

            ans+=(long long int)mp[len][rem];

            if(length[i]==len && rem==num)
            {
                ans--;
            }

            len++;

            cur*=10;

        }
    }

    printf("%I64d\n",ans);

    return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define pii pair < int , int >

#define ll unsigned long long int

#define ff first

#define ss second

map < int , int > mp[11];

int ara[200005],length[200005];

int find_len(int n)
{
    int len=0;

    while(n)
    {
        len++;

        n/=10;
    }

    return len;
}

int main()
{
    int n,k,i,j;

    scanf("%d %d",&n,&k);

    for(i=1; i<=n; i++)
    {
        scanf("%d",&ara[i]);

        int len=find_len(ara[i]);

        mp[len][ara[i]%k]++;

        length[i]=len;

    }

    long long int ans=0;

    for(i=1; i<=n; i++)
    {
        ll cur=10;

        int num=ara[i]%k,len=1;

        while(cur<=1e10)
        {
            ll val=num*cur;

            ll rem=k-(val%k);

            if(rem==k) rem=0;

            ans+=(long long int)mp[len][rem];

            if(length[i]==len && rem==num)
            {
                ans--;
            }

            len++;

            cur*=10;

        }
    }

    printf("%I64d\n",ans);

}


#include <bits/stdc++.h>
using namespace std;

using ull = unsigned long long;
using ll = long long;

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define pb push_back
#define fill(x, y) memset(x, y, sizeof(x))
#define even(x) x % 2 == 0
#define odd(x) x % 2 != 0
#define all(x) x.begin(), x.end()
#define pcnt __builtin_popcount
#define buli(x) __builtin_popcountll(x)
#define F first
#define S second
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());

// these functions return the position of result of Binary Search.
#define LB(s, t, x) (int) (lower_bound(s, t, x) - s)
#define UB(s, t, x) (int) (upper_bound(s, t, x) - s)

ll qp(ll a, ll b, int mo) { ll ans = 1; do { if (b & 1) ans = 1ll * ans * a % mo; a = 1ll * a * a % mo; } while (b >>= 1); return ans; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll temp = gcd(a, b); return temp ? (a / temp * b) : 0; }
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int dx8[] = { 1, -1, 0, 0, 1, 1, -1, -1 }, dy8[] = { 0, 0, -1, 1, -1, 1, -1, 1 };

template <typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts>
auto make_v(size_t a, size_t b, Ts... ts) { return vector<decltype(make_v<T>(b, ts...))>(a, make_v<T>(b, ts...)); }
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }
template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v) { for (auto &e : t) fill_v(e, v); }
// auto dp = make_v<int>(4, h, w);
// fill_v(dp, 0);

const ll INF_LL = (1ll << 60);
const int INF_INT = (int)1e9;
const ll MOD_CONST = (ll)(1e9 + 7);

template <class T>
bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T>
bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }

inline tuple<ll, ll> rotate45(tuple<ll, ll> point) { ll x = get<0>(point), y = get<1>(point); return tuple<ll, ll>(x + y, x - y); }
inline bool rangeCheck2D(int nx, int ny, int Width, int Height) { return nx >= 0 and nx < Width and ny >= 0 and ny < Height; }
template <typename T>
void out(T o) { cout << o << endl; }
template <typename T>
void out(vector<T> &out) { REP(i, (int)out.size()) { cout << out[i]; if (i == (int)out.size() - 1) cout << endl; else cout << " "; } }

int main(void)
{
	cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(20);

	ull N; cin >> N;
	ull K; cin >> K;
	vector<ull> a(N); REP(i, N) cin >> a[i];

	vector< map<ull, ull> > rem(10);
	REP(i, N) {
		string s = to_string(a[i]);
		rem[s.size()-1][a[i] % K]++;
	}

	ull ans = 0;
	REP(i, N) {
		ull num = a[i] % K;
		REP(j, 10) {
			num *= 10;
//			if (num > ll(1e9)) break;
			ull r = num % K;
			ans += rem[j][K - r];
			if (r == 0) ans += rem[j][0];
		}
	}
	REP(i, N) {
		ull r = a[i] % K;
		string s = to_string(a[i]);
		ull num = 10;
		REP(j, s.size() - 1) num *= 10;
		r = r + (num % K * r % K) % K;
		if (r == 0 or r == K) ans--;
	}
	out(ans);

	return 0;
}

//*/


#include <bits/stdc++.h>
using namespace std;

using ll = long long;

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define pb push_back
#define fill(x, y) memset(x, y, sizeof(x))
#define even(x) x % 2 == 0
#define odd(x) x % 2 != 0
#define all(x) x.begin(), x.end()
#define pcnt __builtin_popcount
#define buli(x) __builtin_popcountll(x)
#define F first
#define S second
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());

// these functions return the position of result of Binary Search.
#define LB(s, t, x) (int) (lower_bound(s, t, x) - s)
#define UB(s, t, x) (int) (upper_bound(s, t, x) - s)

ll qp(ll a, ll b, int mo) { ll ans = 1; do { if (b & 1) ans = 1ll * ans * a % mo; a = 1ll * a * a % mo; } while (b >>= 1); return ans; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll temp = gcd(a, b); return temp ? (a / temp * b) : 0; }
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int dx8[] = { 1, -1, 0, 0, 1, 1, -1, -1 }, dy8[] = { 0, 0, -1, 1, -1, 1, -1, 1 };

template <typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts>
auto make_v(size_t a, size_t b, Ts... ts) { return vector<decltype(make_v<T>(b, ts...))>(a, make_v<T>(b, ts...)); }
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }
template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v) { for (auto &e : t) fill_v(e, v); }
// auto dp = make_v<int>(4, h, w);
// fill_v(dp, 0);

const ll INF_LL = (1ll << 60);
const int INF_INT = (int)1e9;
const ll MOD_CONST = (ll)(1e9 + 7);

template <class T>
bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T>
bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }

inline tuple<ll, ll> rotate45(tuple<ll, ll> point) { ll x = get<0>(point), y = get<1>(point); return tuple<ll, ll>(x + y, x - y); }
inline bool rangeCheck2D(int nx, int ny, int Width, int Height) { return nx >= 0 and nx < Width and ny >= 0 and ny < Height; }
template <typename T>
void out(T o) { cout << o << endl; }
template <typename T>
void out(vector<T> &out) { REP(i, (int)out.size()) { cout << out[i]; if (i == (int)out.size() - 1) cout << endl; else cout << " "; } }

int main(void)
{
	cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(20);

	ll N; cin >> N;
	ll K; cin >> K;
	vector<ll> a(N); REP(i, N) cin >> a[i];

	vector< map<ll, int> > rem(10);
	REP(i, N) {
		string s = to_string(a[i]);
		rem[s.size()-1][a[i] % K]++;
	}

	ll ans = 0;
	REP(i, N) {
		ll num = a[i];
		REP(j, 10) {
			num *= 10;
			ll r = num % K;
			ans += rem[j][K - r];
			if (r == 0) ans += rem[j][0];
		}
	}
	REP(i, N) {
		string s = to_string(a[i]);
		s += s;
		if (stoll(s) % K == 0) ans--;
	}
	out(ans);

	return 0;
}

//*/


#include <bits/stdc++.h>
using namespace std;

using ull = unsigned long long;
using ll = long long;

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define pb push_back
#define fill(x, y) memset(x, y, sizeof(x))
#define even(x) x % 2 == 0
#define odd(x) x % 2 != 0
#define all(x) x.begin(), x.end()
#define pcnt __builtin_popcount
#define buli(x) __builtin_popcountll(x)
#define F first
#define S second
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());

// these functions return the position of result of Binary Search.
#define LB(s, t, x) (int) (lower_bound(s, t, x) - s)
#define UB(s, t, x) (int) (upper_bound(s, t, x) - s)

ll qp(ll a, ll b, int mo) { ll ans = 1; do { if (b & 1) ans = 1ll * ans * a % mo; a = 1ll * a * a % mo; } while (b >>= 1); return ans; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll temp = gcd(a, b); return temp ? (a / temp * b) : 0; }
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int dx8[] = { 1, -1, 0, 0, 1, 1, -1, -1 }, dy8[] = { 0, 0, -1, 1, -1, 1, -1, 1 };

template <typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts>
auto make_v(size_t a, size_t b, Ts... ts) { return vector<decltype(make_v<T>(b, ts...))>(a, make_v<T>(b, ts...)); }
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }
template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v) { for (auto &e : t) fill_v(e, v); }
// auto dp = make_v<int>(4, h, w);
// fill_v(dp, 0);

const ll INF_LL = (1ll << 60);
const int INF_INT = (int)1e9;
const ll MOD_CONST = (ll)(1e9 + 7);

template <typename T>
vector<T> pows(int n) {
	vector<T> ret;
	T x = 1;
	while (ret.size() < n) {
		ret.push_back(x);
		x *= 10;
	}
	return ret;
}

template <class T>
bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T>
bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }

inline tuple<ll, ll> rotate45(tuple<ll, ll> point) { ll x = get<0>(point), y = get<1>(point); return tuple<ll, ll>(x + y, x - y); }
inline bool rangeCheck2D(int nx, int ny, int Width, int Height) { return nx >= 0 and nx < Width and ny >= 0 and ny < Height; }

template <typename T>
void out(T o) { cout << o << endl; }
template <typename T>
void out(vector<T> &out) { REP(i, (int)out.size()) { cout << out[i]; if (i == (int)out.size() - 1) cout << endl; else cout << " "; } }

int main(void)
{
	cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(20);

	auto vv = pows<ull>(10);

	ull N; cin >> N;
	ull K; cin >> K;
	vector<ull> a(N);
	vector<ull> len(N);
	REP(i, N) {
		cin >> a[i];
		ll aa = a[i];
		while (aa >= 10) {
			aa /= 10;
			len[i]++;
		}
		len[i]++;
	}

	vector< map<ull, ull> > rem(10);
	REP(i, N) {
		rem[len[i]-1][a[i] % K]++;
	}

	ull ans = 0;
	REP(i, N) {
		ull num = a[i] % K;
		REP(j, 10) {
			num *= 10;
			ull r = num % K;
			ans += rem[j][K - r];
			if (r == 0) ans += rem[j][0];
		}
	}
	REP(i, N) {
		ull r = a[i] % K;
		ull num = vv[len[i]];
		r = r + (num % K * r % K) % K;
		if (r == 0 or r == K) ans--;
	}
	out(ans);

	return 0;
}

//*/


#include <bits/stdc++.h>
using namespace std;

using ull = unsigned long long;
using ll = long long;

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define pb push_back
#define fill(x, y) memset(x, y, sizeof(x))
#define even(x) x % 2 == 0
#define odd(x) x % 2 != 0
#define all(x) x.begin(), x.end()
#define pcnt __builtin_popcount
#define buli(x) __builtin_popcountll(x)
#define F first
#define S second
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());

// these functions return the position of result of Binary Search.
#define LB(s, t, x) (int) (lower_bound(s, t, x) - s)
#define UB(s, t, x) (int) (upper_bound(s, t, x) - s)

ll qp(ll a, ll b, int mo) { ll ans = 1; do { if (b & 1) ans = 1ll * ans * a % mo; a = 1ll * a * a % mo; } while (b >>= 1); return ans; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll temp = gcd(a, b); return temp ? (a / temp * b) : 0; }
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int dx8[] = { 1, -1, 0, 0, 1, 1, -1, -1 }, dy8[] = { 0, 0, -1, 1, -1, 1, -1, 1 };

template <typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts>
auto make_v(size_t a, size_t b, Ts... ts) { return vector<decltype(make_v<T>(b, ts...))>(a, make_v<T>(b, ts...)); }
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }
template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v) { for (auto &e : t) fill_v(e, v); }
// auto dp = make_v<int>(4, h, w);
// fill_v(dp, 0);

const ll INF_LL = (1ll << 60);
const int INF_INT = (int)1e9;
const ll MOD_CONST = (ll)(1e9 + 7);

template <typename T>
vector<T> pows(int n) {
	vector<T> ret;
	T x = 1;
	while (ret.size() < n) {
		ret.push_back(x);
		x *= 10;
	}
	return ret;
}

template <class T>
bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T>
bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }

inline tuple<ll, ll> rotate45(tuple<ll, ll> point) { ll x = get<0>(point), y = get<1>(point); return tuple<ll, ll>(x + y, x - y); }
inline bool rangeCheck2D(int nx, int ny, int Width, int Height) { return nx >= 0 and nx < Width and ny >= 0 and ny < Height; }

template <typename T>
void out(T o) { cout << o << endl; }
template <typename T>
void out(vector<T> &out) { REP(i, (int)out.size()) { cout << out[i]; if (i == (int)out.size() - 1) cout << endl; else cout << " "; } }

int main(void)
{
	cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(20);

	auto vv = pows<ull>(20);

	ull N; cin >> N;
	ull K; cin >> K;
	vector<ull> a(N);
	vector<ull> len(N);
	REP(i, N) {
		cin >> a[i];
		ll aa = a[i];
		while (aa >= 10) {
			aa /= 10;
			len[i]++;
		}
		len[i]++;
	}

	vector< map<ull, ull> > rem(10);
	REP(i, N) {
		rem[len[i]-1][a[i] % K]++;
	}

	ull ans = 0;
	REP(i, N) {
		ull num = a[i] % K;
		REP(j, 10) {
			num *= 10;
			ull r = num % K;
			ans += rem[j][K - r];
			if (r == 0) ans += rem[j][0];
		}
	}
	REP(i, N) {
		ull r = a[i] % K;
		ull num = vv[len[i]];
		r = r + (num % K * r % K) % K;
		if (r == 0 or r == K) ans--;
	}
	out(ans);

	return 0;
}

//*/


#include <bits/stdc++.h>
using namespace std;

using ll = long long;

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define pb push_back
#define fill(x, y) memset(x, y, sizeof(x))
#define even(x) x % 2 == 0
#define odd(x) x % 2 != 0
#define all(x) x.begin(), x.end()
#define pcnt __builtin_popcount
#define buli(x) __builtin_popcountll(x)
#define F first
#define S second
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());

// these functions return the position of result of Binary Search.
#define LB(s, t, x) (int) (lower_bound(s, t, x) - s)
#define UB(s, t, x) (int) (upper_bound(s, t, x) - s)

ll qp(ll a, ll b, int mo) { ll ans = 1; do { if (b & 1) ans = 1ll * ans * a % mo; a = 1ll * a * a % mo; } while (b >>= 1); return ans; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll temp = gcd(a, b); return temp ? (a / temp * b) : 0; }
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int dx8[] = { 1, -1, 0, 0, 1, 1, -1, -1 }, dy8[] = { 0, 0, -1, 1, -1, 1, -1, 1 };

template <typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts>
auto make_v(size_t a, size_t b, Ts... ts) { return vector<decltype(make_v<T>(b, ts...))>(a, make_v<T>(b, ts...)); }
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }
template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v) { for (auto &e : t) fill_v(e, v); }
// auto dp = make_v<int>(4, h, w);
// fill_v(dp, 0);

const ll INF_LL = (1ll << 60);
const int INF_INT = (int)1e9;
const ll MOD_CONST = (ll)(1e9 + 7);

template <class T>
bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T>
bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }

inline tuple<ll, ll> rotate45(tuple<ll, ll> point) { ll x = get<0>(point), y = get<1>(point); return tuple<ll, ll>(x + y, x - y); }
inline bool rangeCheck2D(int nx, int ny, int Width, int Height) { return nx >= 0 and nx < Width and ny >= 0 and ny < Height; }
template <typename T>
void out(T o) { cout << o << endl; }
template <typename T>
void out(vector<T> &out) { REP(i, (int)out.size()) { cout << out[i]; if (i == (int)out.size() - 1) cout << endl; else cout << " "; } }

int main(void)
{
	cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(20);

	ll N; cin >> N;
	ll K; cin >> K;
	vector<ll> a(N); REP(i, N) cin >> a[i];

	vector< map<ll, ll> > rem(10);
	REP(i, N) {
		string s = to_string(a[i]);
		rem[s.size()-1][a[i] % K]++;
	}

	ll ans = 0;
	REP(i, N) {
		ll num = a[i] % K;
		REP(j, 10) {
			num *= 10;
			ll r = num % K;
			ans += rem[j][K - r];
			if (r == 0) ans += rem[j][0];
		}
	}
	REP(i, N) {
		if (a[i] % K == 0) a[i] %= K;
		string s = to_string(a[i]);
		s += s;
		if (stoll(s) % K == 0) ans--;
	}
	out(ans);

	return 0;
}

//*/


#include <bits/stdc++.h>
using namespace std;

using ll = long long;

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define pb push_back
#define fill(x, y) memset(x, y, sizeof(x))
#define even(x) x % 2 == 0
#define odd(x) x % 2 != 0
#define all(x) x.begin(), x.end()
#define pcnt __builtin_popcount
#define buli(x) __builtin_popcountll(x)
#define F first
#define S second
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());

// these functions return the position of result of Binary Search.
#define LB(s, t, x) (int) (lower_bound(s, t, x) - s)
#define UB(s, t, x) (int) (upper_bound(s, t, x) - s)

ll qp(ll a, ll b, int mo) { ll ans = 1; do { if (b & 1) ans = 1ll * ans * a % mo; a = 1ll * a * a % mo; } while (b >>= 1); return ans; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll temp = gcd(a, b); return temp ? (a / temp * b) : 0; }
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int dx8[] = { 1, -1, 0, 0, 1, 1, -1, -1 }, dy8[] = { 0, 0, -1, 1, -1, 1, -1, 1 };

template <typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts>
auto make_v(size_t a, size_t b, Ts... ts) { return vector<decltype(make_v<T>(b, ts...))>(a, make_v<T>(b, ts...)); }
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }
template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v) { for (auto &e : t) fill_v(e, v); }
// auto dp = make_v<int>(4, h, w);
// fill_v(dp, 0);

const ll INF_LL = (1ll << 60);
const int INF_INT = (int)1e9;
const ll MOD_CONST = (ll)(1e9 + 7);

template <class T>
bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T>
bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }

inline tuple<ll, ll> rotate45(tuple<ll, ll> point) { ll x = get<0>(point), y = get<1>(point); return tuple<ll, ll>(x + y, x - y); }
inline bool rangeCheck2D(int nx, int ny, int Width, int Height) { return nx >= 0 and nx < Width and ny >= 0 and ny < Height; }
template <typename T>
void out(T o) { cout << o << endl; }
template <typename T>
void out(vector<T> &out) { REP(i, (int)out.size()) { cout << out[i]; if (i == (int)out.size() - 1) cout << endl; else cout << " "; } }

int main(void)
{
	cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(20);

	ll N; cin >> N;
	ll K; cin >> K;
	vector<ll> a(N); REP(i, N) cin >> a[i];

	vector< map<ll, ll> > rem(10);
	REP(i, N) {
		string s = to_string(a[i]);
		rem[s.size()-1][a[i] % K]++;
	}

	ll ans = 0;
	REP(i, N) {
		ll num = a[i] % K;
		REP(j, 10) {
			num *= 10;
			ll r = num % K;
			ans += rem[j][K - r];
			if (r == 0) ans += rem[j][0];
		}
	}
	REP(i, N) {
		ll r = a[i] % K;
		string s = to_string(a[i]);
		ll num = 10;
		REP(i, s.size() - 1) num *= 10;
		r = r + (num % K * r % K) % K;
		if (r == 0 or r == K) ans--;
	}
	out(ans);

	return 0;
}

//*/


#include <bits/stdc++.h>
using namespace std;

using ull = unsigned long long;
using ll = long long;

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define pb push_back
#define fill(x, y) memset(x, y, sizeof(x))
#define even(x) x % 2 == 0
#define odd(x) x % 2 != 0
#define all(x) x.begin(), x.end()
#define pcnt __builtin_popcount
#define buli(x) __builtin_popcountll(x)
#define F first
#define S second
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());

// these functions return the position of result of Binary Search.
#define LB(s, t, x) (int) (lower_bound(s, t, x) - s)
#define UB(s, t, x) (int) (upper_bound(s, t, x) - s)

ll qp(ll a, ll b, int mo) { ll ans = 1; do { if (b & 1) ans = 1ll * ans * a % mo; a = 1ll * a * a % mo; } while (b >>= 1); return ans; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll temp = gcd(a, b); return temp ? (a / temp * b) : 0; }
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int dx8[] = { 1, -1, 0, 0, 1, 1, -1, -1 }, dy8[] = { 0, 0, -1, 1, -1, 1, -1, 1 };

template <typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts>
auto make_v(size_t a, size_t b, Ts... ts) { return vector<decltype(make_v<T>(b, ts...))>(a, make_v<T>(b, ts...)); }
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }

template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v) { for (auto &e : t) fill_v(e, v); }
// auto dp = make_v<int>(4, h, w);
// fill_v(dp, 0);

const ll INF_LL = (1ll << 60);
const int INF_INT = (int)1e9;
const ll MOD_CONST = (ll)(1e9 + 7);

template <typename T>
vector<T> pows(int n) {
	vector<T> ret;
	T x = 1;
	while (ret.size() < n) {
		ret.push_back(x);
		x *= 10;
	}
	return ret;
}

template <class T>
bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T>
bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }

inline tuple<ll, ll> rotate45(tuple<ll, ll> point) { ll x = get<0>(point), y = get<1>(point); return tuple<ll, ll>(x + y, x - y); }
inline bool rangeCheck2D(int nx, int ny, int Width, int Height) { return nx >= 0 and nx < Width and ny >= 0 and ny < Height; }

template <typename T>
void out(T o) { cout << o << endl; }
template <typename T>
void out(vector<T> &out) { REP(i, (int)out.size()) { cout << out[i]; if (i == (int)out.size() - 1) cout << endl; else cout << " "; } }

int main(void)
{
	cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(20);

	auto vv = pows<ull>(20);

	ull N; cin >> N;
	ull K; cin >> K;
	vector<ull> a(N);
	vector<ull> len(N);
	REP(i, N) {
		cin >> a[i];
		ll aa = a[i];
		while (aa >= 10) {
			aa /= 10;
			len[i]++;
		}
		len[i]++;
	}

	vector< map<ull, ull> > rem(10);
	REP(i, N) {
		rem[len[i]-1][a[i] % K]++;
	}

	ull ans = 0;
	REP(i, N) {
		ull num = a[i] % K;
		REP(j, 10) {
			num *= 10;
			ull r = num % K;
			ans += rem[j][K - r];
			if (r == 0) ans += rem[j][0];
		}
	}
	REP(i, N) {
		ull r = a[i] % K;
		ull num = vv[len[i]];
		r = r + (num % K * r % K) % K;
		if (r == 0 or r == K) ans--;
	}
	out(ans);

	return 0;
}

//*/


#include <bits/stdc++.h>
using namespace std;

using ll = long long;

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define pb push_back
#define fill(x, y) memset(x, y, sizeof(x))
#define even(x) x % 2 == 0
#define odd(x) x % 2 != 0
#define all(x) x.begin(), x.end()
#define pcnt __builtin_popcount
#define buli(x) __builtin_popcountll(x)
#define F first
#define S second
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());

// these functions return the position of result of Binary Search.
#define LB(s, t, x) (int) (lower_bound(s, t, x) - s)
#define UB(s, t, x) (int) (upper_bound(s, t, x) - s)

ll qp(ll a, ll b, int mo) { ll ans = 1; do { if (b & 1) ans = 1ll * ans * a % mo; a = 1ll * a * a % mo; } while (b >>= 1); return ans; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll temp = gcd(a, b); return temp ? (a / temp * b) : 0; }
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int dx8[] = { 1, -1, 0, 0, 1, 1, -1, -1 }, dy8[] = { 0, 0, -1, 1, -1, 1, -1, 1 };

template <typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts>
auto make_v(size_t a, size_t b, Ts... ts) { return vector<decltype(make_v<T>(b, ts...))>(a, make_v<T>(b, ts...)); }
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }
template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v) { for (auto &e : t) fill_v(e, v); }
// auto dp = make_v<int>(4, h, w);
// fill_v(dp, 0);

const ll INF_LL = (1ll << 60);
const int INF_INT = (int)1e9;
const ll MOD_CONST = (ll)(1e9 + 7);

template <class T>
bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T>
bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }

inline tuple<ll, ll> rotate45(tuple<ll, ll> point) { ll x = get<0>(point), y = get<1>(point); return tuple<ll, ll>(x + y, x - y); }
inline bool rangeCheck2D(int nx, int ny, int Width, int Height) { return nx >= 0 and nx < Width and ny >= 0 and ny < Height; }
template <typename T>
void out(T o) { cout << o << endl; }
template <typename T>
void out(vector<T> &out) { REP(i, (int)out.size()) { cout << out[i]; if (i == (int)out.size() - 1) cout << endl; else cout << " "; } }

int main(void)
{
	cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(20);

	ll N; cin >> N;
	ll K; cin >> K;
	vector<ll> a(N); REP(i, N) cin >> a[i];

	vector< map<ll, ll> > rem(10);
	REP(i, N) {
		string s = to_string(a[i]);
		rem[s.size()-1][a[i] % K]++;
	}

	ll ans = 0;
	REP(i, N) {
		ll num = a[i] % K;
		REP(j, 10) {
			num *= 10;
			ll r = num % K;
			ans += rem[j][K - r];
			if (r == 0) ans += rem[j][0];
		}
	}
	REP(i, N) {
		ll r = a[i] % K;
		string s = to_string(a[i]);
		ll num = 10;
		REP(i, s.size() - 1) num *= 10;
		r += r;
		if (r == 0 or r == K) ans--;
	}
	out(ans);

	return 0;
}

//*/


#include <bits/stdc++.h>
using namespace std;

using ll = long long;

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define pb push_back
#define fill(x, y) memset(x, y, sizeof(x))
#define even(x) x % 2 == 0
#define odd(x) x % 2 != 0
#define all(x) x.begin(), x.end()
#define pcnt __builtin_popcount
#define buli(x) __builtin_popcountll(x)
#define F first
#define S second
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());

// these functions return the position of result of Binary Search.
#define LB(s, t, x) (int) (lower_bound(s, t, x) - s)
#define UB(s, t, x) (int) (upper_bound(s, t, x) - s)

ll qp(ll a, ll b, int mo) { ll ans = 1; do { if (b & 1) ans = 1ll * ans * a % mo; a = 1ll * a * a % mo; } while (b >>= 1); return ans; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll temp = gcd(a, b); return temp ? (a / temp * b) : 0; }
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int dx8[] = { 1, -1, 0, 0, 1, 1, -1, -1 }, dy8[] = { 0, 0, -1, 1, -1, 1, -1, 1 };

template <typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts>
auto make_v(size_t a, size_t b, Ts... ts) { return vector<decltype(make_v<T>(b, ts...))>(a, make_v<T>(b, ts...)); }
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }
template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v) { for (auto &e : t) fill_v(e, v); }
// auto dp = make_v<int>(4, h, w);
// fill_v(dp, 0);

const ll INF_LL = (1ll << 60);
const int INF_INT = (int)1e9;
const ll MOD_CONST = (ll)(1e9 + 7);

template <class T>
bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T>
bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }

inline tuple<ll, ll> rotate45(tuple<ll, ll> point) { ll x = get<0>(point), y = get<1>(point); return tuple<ll, ll>(x + y, x - y); }
inline bool rangeCheck2D(int nx, int ny, int Width, int Height) { return nx >= 0 and nx < Width and ny >= 0 and ny < Height; }
template <typename T>
void out(T o) { cout << o << endl; }
template <typename T>
void out(vector<T> &out) { REP(i, (int)out.size()) { cout << out[i]; if (i == (int)out.size() - 1) cout << endl; else cout << " "; } }

int main(void)
{
	cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(20);

	ll N; cin >> N;
	ll K; cin >> K;
	vector<ll> a(N); REP(i, N) cin >> a[i];

	vector< map<ll, ll> > rem(10);
	REP(i, N) {
		string s = to_string(a[i]);
		rem[s.size()-1][a[i] % K]++;
	}

	ll ans = 0;
	REP(i, N) {
		ll num = a[i] % K;
		REP(j, 10) {
			num *= 10;
			ll r = num % K;
			ans += rem[j][K - r];
			if (r == 0) ans += rem[j][0];
		}
	}
	REP(i, N) {
		string s = to_string(a[i]);
		s += s;
		if (stoll(s) % K == 0) ans--;
	}
	out(ans);

	return 0;
}

//*/


#include <bits/stdc++.h>
using namespace std;

using ull = unsigned long long;
using ll = long long;

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define pb push_back
#define fill(x, y) memset(x, y, sizeof(x))
#define even(x) x % 2 == 0
#define odd(x) x % 2 != 0
#define all(x) x.begin(), x.end()
#define pcnt __builtin_popcount
#define buli(x) __builtin_popcountll(x)
#define F first
#define S second
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());

// these functions return the position of result of Binary Search.
#define LB(s, t, x) (int) (lower_bound(s, t, x) - s)
#define UB(s, t, x) (int) (upper_bound(s, t, x) - s)

ll qp(ll a, ll b, int mo) { ll ans = 1; do { if (b & 1) ans = 1ll * ans * a % mo; a = 1ll * a * a % mo; } while (b >>= 1); return ans; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll temp = gcd(a, b); return temp ? (a / temp * b) : 0; }
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int dx8[] = { 1, -1, 0, 0, 1, 1, -1, -1 }, dy8[] = { 0, 0, -1, 1, -1, 1, -1, 1 };

template <typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts>
auto make_v(size_t a, size_t b, Ts... ts) { return vector<decltype(make_v<T>(b, ts...))>(a, make_v<T>(b, ts...)); }
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }
template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v) { for (auto &e : t) fill_v(e, v); }
// auto dp = make_v<int>(4, h, w);
// fill_v(dp, 0);

const ll INF_LL = (1ll << 60);
const int INF_INT = (int)1e9;
const ll MOD_CONST = (ll)(1e9 + 7);

template <class T>
bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T>
bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }

inline tuple<ll, ll> rotate45(tuple<ll, ll> point) { ll x = get<0>(point), y = get<1>(point); return tuple<ll, ll>(x + y, x - y); }
inline bool rangeCheck2D(int nx, int ny, int Width, int Height) { return nx >= 0 and nx < Width and ny >= 0 and ny < Height; }
template <typename T>
void out(T o) { cout << o << endl; }
template <typename T>
void out(vector<T> &out) { REP(i, (int)out.size()) { cout << out[i]; if (i == (int)out.size() - 1) cout << endl; else cout << " "; } }

int main(void)
{
	cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(20);

	ull N; cin >> N;
	ull K; cin >> K;
	vector<ull> a(N);
	vector<ull> len(N);
	REP(i, N) {
		cin >> a[i];
		ll aa = a[i];
		while (aa >= 10) {
			aa /= 10;
			len[i]++;
		}
		len[i]++;
	}

	vector< map<ull, ull> > rem(10);
	REP(i, N) {
		rem[len[i]-1][a[i] % K]++;
	}

	ull ans = 0;
	REP(i, N) {
		ull num = a[i] % K;
		REP(j, 10) {
			num *= 10;
//			if (num > ll(1e9)) break;
			ull r = num % K;
			ans += rem[j][K - r];
			if (r == 0) ans += rem[j][0];
		}
	}
	REP(i, N) {
		ull r = a[i] % K;
		ull num = 10;
		REP(j, len[i] - 1) num *= 10;
		r = r + (num % K * r % K) % K;
		if (r == 0 or r == K) ans--;
	}
	out(ans);

	return 0;
}

//*/


#include <bits/stdc++.h>
using namespace std;

using ll = long long;

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define pb push_back
#define fill(x, y) memset(x, y, sizeof(x))
#define even(x) x % 2 == 0
#define odd(x) x % 2 != 0
#define all(x) x.begin(), x.end()
#define pcnt __builtin_popcount
#define buli(x) __builtin_popcountll(x)
#define F first
#define S second
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());

// these functions return the position of result of Binary Search.
#define LB(s, t, x) (int) (lower_bound(s, t, x) - s)
#define UB(s, t, x) (int) (upper_bound(s, t, x) - s)

ll qp(ll a, ll b, int mo) { ll ans = 1; do { if (b & 1) ans = 1ll * ans * a % mo; a = 1ll * a * a % mo; } while (b >>= 1); return ans; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll temp = gcd(a, b); return temp ? (a / temp * b) : 0; }
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int dx8[] = { 1, -1, 0, 0, 1, 1, -1, -1 }, dy8[] = { 0, 0, -1, 1, -1, 1, -1, 1 };

template <typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts>
auto make_v(size_t a, size_t b, Ts... ts) { return vector<decltype(make_v<T>(b, ts...))>(a, make_v<T>(b, ts...)); }
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }
template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v) { for (auto &e : t) fill_v(e, v); }
// auto dp = make_v<int>(4, h, w);
// fill_v(dp, 0);

const ll INF_LL = (1ll << 60);
const int INF_INT = (int)1e9;
const ll MOD_CONST = (ll)(1e9 + 7);

template <class T>
bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T>
bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }

inline tuple<ll, ll> rotate45(tuple<ll, ll> point) { ll x = get<0>(point), y = get<1>(point); return tuple<ll, ll>(x + y, x - y); }
inline bool rangeCheck2D(int nx, int ny, int Width, int Height) { return nx >= 0 and nx < Width and ny >= 0 and ny < Height; }
template <typename T>
void out(T o) { cout << o << endl; }
template <typename T>
void out(vector<T> &out) { REP(i, (int)out.size()) { cout << out[i]; if (i == (int)out.size() - 1) cout << endl; else cout << " "; } }

int main(void)
{
	cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(20);

	ll N; cin >> N;
	ll K; cin >> K;
	vector<ll> a(N); REP(i, N) cin >> a[i];

	vector< map<ll, ll> > rem(10);
	REP(i, N) {
		string s = to_string(a[i]);
		rem[s.size()-1][a[i] % K]++;
	}

	ll ans = 0;
	REP(i, N) {
		ll num = a[i] % K;
		REP(j, 10) {
			num *= 10;
			ll r = num % K;
			ans += rem[j][K - r];
			if (r == 0) ans += rem[j][0];
		}
	}
	REP(i, N) {
		ll r = a[i] % K;
		r += r;
		if (r == 0 or r == K) ans--;
	}
	out(ans);

	return 0;
}

//*/


#include <bits/stdc++.h>
using namespace std;

using ll = long long;

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define pb push_back
#define fill(x, y) memset(x, y, sizeof(x))
#define even(x) x % 2 == 0
#define odd(x) x % 2 != 0
#define all(x) x.begin(), x.end()
#define pcnt __builtin_popcount
#define buli(x) __builtin_popcountll(x)
#define F first
#define S second
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());

// these functions return the position of result of Binary Search.
#define LB(s, t, x) (int) (lower_bound(s, t, x) - s)
#define UB(s, t, x) (int) (upper_bound(s, t, x) - s)

ll qp(ll a, ll b, int mo) { ll ans = 1; do { if (b & 1) ans = 1ll * ans * a % mo; a = 1ll * a * a % mo; } while (b >>= 1); return ans; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll temp = gcd(a, b); return temp ? (a / temp * b) : 0; }
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int dx8[] = { 1, -1, 0, 0, 1, 1, -1, -1 }, dy8[] = { 0, 0, -1, 1, -1, 1, -1, 1 };

template <typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts>
auto make_v(size_t a, size_t b, Ts... ts) { return vector<decltype(make_v<T>(b, ts...))>(a, make_v<T>(b, ts...)); }
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }
template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v) { for (auto &e : t) fill_v(e, v); }
// auto dp = make_v<int>(4, h, w);
// fill_v(dp, 0);

const ll INF_LL = (1ll << 60);
const int INF_INT = (int)1e9;
const ll MOD_CONST = (ll)(1e9 + 7);

template <class T>
bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T>
bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }

inline tuple<ll, ll> rotate45(tuple<ll, ll> point) { ll x = get<0>(point), y = get<1>(point); return tuple<ll, ll>(x + y, x - y); }
inline bool rangeCheck2D(int nx, int ny, int Width, int Height) { return nx >= 0 and nx < Width and ny >= 0 and ny < Height; }
template <typename T>
void out(T o) { cout << o << endl; }
template <typename T>
void out(vector<T> &out) { REP(i, (int)out.size()) { cout << out[i]; if (i == (int)out.size() - 1) cout << endl; else cout << " "; } }

int main(void)
{
	cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(20);

	ll N; cin >> N;
	ll K; cin >> K;
	vector<ll> a(N); REP(i, N) cin >> a[i];

	vector< map<ll, int> > rem(10);
	REP(i, N) {
		string s = to_string(a[i]);
		rem[s.size()-1][a[i] % K]++;
	}

	ll ans = 0;
	REP(i, N) {
		ll num = a[i] % K;
		REP(j, 10) {
			num *= 10;
			ll r = num % K;
			ans += rem[j][K - r];
			if (r == 0) ans += rem[j][0];
		}
	}
	REP(i, N) {
		string s = to_string(a[i]);
		s += s;
		if (stoll(s) % K == 0) ans--;
	}
	out(ans);

	return 0;
}

//*/


#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
typedef pair<ll,ll> pll;
map<pll,ll>s;
int main(void){
    ios_base::sync_with_stdio(0); cin.tie(0);
    ll n,k; cin>>n>>k; vector<ll>a(n);
    for(ll i=0;i<n;i++)cin>>a[i];
    for(ll i=0;i<n;i++)s[{a[i]%k,ll(to_string(a[i]).size())}]++;
    ll ans=0;
    for(ll i=0;i<n;i++){
        ll tp=1;
        s[{a[i]%k,ll(to_string(a[i]).size())}]--;
        for(ll j=1;j<14;j++){
            tp*=10;
            if(tp >= ULLONG_MAX/a[i]) break;
            ans+=s[{(k-int((a[i]*tp)%k))%k,j}];
        }
        s[{a[i]%k,ll(to_string(a[i]).size())}]++;
    }
    cout<<ans<<'\n';
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
map<pll,ll>s;
int main(void){
    ios_base::sync_with_stdio(0); cin.tie(0);
    ll n,k; cin>>n>>k; vector<ll>a(n);
    for(ll i=0;i<n;i++)cin>>a[i];
    for(ll i=0;i<n;i++)s[{a[i]%k,ll(to_string(a[i]).size())}]++;
    ll ans=0;
    for(ll i=0;i<n;i++){
        ll tp=1;
        s[{a[i]%k,ll(to_string(a[i]).size())}]--;
        for(ll j=1;j<14;j++){
            tp*=10;
            if(tp >= LLONG_MAX/a[i]) break;
            ans+=s[{(k-((a[i]*tp)%k))%k,j}];
        }
        s[{a[i]%k,ll(to_string(a[i]).size())}]++;
    }
    cout<<ans<<'\n';
}


#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
const int MAXN=2e5+5;
unordered_map<int,int>s[11];
int a[MAXN],b[MAXN],c[MAXN];
int main(void){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n,k; cin>>n>>k;
    for(ll i=0;i<n;i++)cin>>a[i];
    for(ll i=0;i<n;i++)b[i]=to_string(a[i]).size();
    for(ll i=0;i<n;i++)c[i]=a[i]%k;
    for(ll i=0;i<n;i++)s[b[i]][a[i]%k]++;
    for(ll i=0;i<11;i++) s[i].reserve(2*n);
    ll ans=0;
    for(ll i=0;i<n;i++){
        ll tp=1;
        s[b[i]][c[i]]--;
        for(ll j=1;j<11;j++){
            tp*=10;
            if(tp >= ULLONG_MAX/ll(a[i])) break;
            ans+=s[j][(k-int((a[i]*tp)%k))%k];
        }
        s[b[i]][c[i]]++;
    }
    cout<<ans<<'\n';
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
map<pll,ll>s;
int main(void){
    ios_base::sync_with_stdio(0); cin.tie(0);
    ll n,k; cin>>n>>k; vector<ll>a(n);
    for(ll i=0;i<n;i++)cin>>a[i];
    for(ll i=0;i<n;i++)s[{a[i]%k,ll(to_string(a[i]).size())}]++;
    ll ans=0;
    for(ll i=0;i<n;i++){
        ll tp=1;
        s[{a[i]%k,ll(to_string(a[i]).size())}]--;
        for(ll j=1;j<10;j++){
            tp*=10;
            ans+=s[{(k-(a[i]*tp%k))%k,j}];
        }
        s[{a[i]%k,ll(to_string(a[i]).size())}]++;
    }
    cout<<ans<<'\n';
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
map<pll,ll>s;
int main(void){
    ios_base::sync_with_stdio(0); cin.tie(0);
    ll n,k; cin>>n>>k; vector<ll>a(n);
    for(ll i=0;i<n;i++)cin>>a[i];
    for(ll i=0;i<n;i++)s[{a[i]%k,ll(to_string(a[i]).size())}]++;
    ll ans=0;
    for(ll i=0;i<n;i++){
        ll tp=1;
        s[{a[i]%k,ll(to_string(a[i]).size())}]--;
        for(ll j=1;j<14;j++){
            tp*=10;
            ans+=s[{(k-((a[i]*tp)%k))%k,j}];
        }
        s[{a[i]%k,ll(to_string(a[i]).size())}]++;
    }
    cout<<ans<<'\n';
}


#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
typedef pair<ll,ll> pll;
map<pll,ll>s;
int main(void){
    ios_base::sync_with_stdio(0); cin.tie(0);
    ll n,k; cin>>n>>k; vector<ll>a(n);
    for(ll i=0;i<n;i++)a[i]=1000000000;
    for(ll i=0;i<n;i++)s[{a[i]%k,ll(to_string(a[i]).size())}]++;
    ll ans=0;
    for(ll i=0;i<n;i++){
        ll tp=1;
        s[{a[i]%k,ll(to_string(a[i]).size())}]--;
        for(ll j=1;j<14;j++){
            tp*=10;
            if(tp >= ULLONG_MAX/a[i]) break;
            ans+=s[{(k-((a[i]*tp)%k))%k,j}];
        }
        s[{a[i]%k,ll(to_string(a[i]).size())}]++;
    }
    cout<<ans<<'\n';
}


#include <bits/stdc++.h>
using namespace std#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
map<pll,ll>s;
int main(void){
    ios_base::sync_with_stdio(0); cin.tie(0);
    ll n,k; cin>>n>>k; vector<ll>a(n);
    for(ll i=0;i<n;i++)cin>>a[i];
    for(ll i=0;i<n;i++)s[{a[i]%k,ll(to_string(a[i]).size())}]++;
    ll ans=0;
    for(ll i=0;i<n;i++){
        ll tp=1;
        s[{a[i]%k,ll(to_string(a[i]).size())}]--;
        for(ll j=1;j<20;j++){
            tp*=10;
            ans+=s[{(k-(a[i]*tp%k))%k,j}];
        }
        s[{a[i]%k,ll(to_string(a[i]).size())}]++;
    }
    cout<<ans<<'\n';
}


#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
typedef pair<ll,ll> pll;
unordered_map<ll,ll>s[11];
int main(void){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ll n,k; cin>>n>>k; vector<ll>a(n),b(n);
    for(ll i=0;i<n;i++)cin>>a[i];
    for(ll i=0;i<n;i++)b[i]=to_string(a[i]).size();
    for(ll i=0;i<n;i++)s[b[i]][a[i]%k]++;
    ll ans=0;
    for(ll i=0;i<n;i++){
        ll tp=1;
        s[b[i]][a[i]%k]--;
        for(ll j=1;j<11;j++){
            tp*=10;
            if(tp >= ULLONG_MAX/a[i]) break;
            ans+=s[j][(k-int((a[i]*tp)%k))%k];
        }
        s[b[i]][a[i]%k]++;
    }
    cout<<ans<<'\n';
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
map<pll,ll>s;
int main(void){
    ios_base::sync_with_stdio(0); cin.tie(0);
    ll n,k; cin>>n>>k; vector<ll>a(n);
    for(ll i=0;i<n;i++)cin>>a[i];
    for(ll i=0;i<n;i++)s[{a[i]%k,ll(to_string(a[i]).size())}]++;
    ll ans=0;
    for(ll i=0;i<n;i++){
        ll tp=1;
        s[{a[i]%k,ll(to_string(a[i]).size())}]--;
        for(ll j=1;j<20;j++){
            tp*=10;
            ans+=s[{(k-(a[i]*tp%k))%k,j}];
        }
        s[{a[i]%k,ll(to_string(a[i]).size())}]++;
    }
    cout<<ans<<'\n';
}


#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
typedef pair<ll,ll> pll;
const ll MAXN=2e5+5;
unordered_map<ll,ll>s[11];
ll a[MAXN],b[MAXN],c[MAXN];
int main(void){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ll n,k; cin>>n>>k;
    for(ll i=0;i<n;i++)cin>>a[i];
    for(ll i=0;i<n;i++)b[i]=to_string(a[i]).size();
    for(ll i=0;i<n;i++)c[i]=a[i]%k;
    for(ll i=0;i<n;i++)s[b[i]][a[i]%k]++;
    ll ans=0;
    for(ll i=0;i<n;i++){
        ll tp=1;
        s[b[i]][c[i]]--;
        for(ll j=1;j<11;j++){
            tp*=10;
            if(tp >= ULLONG_MAX/a[i]) break;
            ans+=s[j][(k-int((a[i]*tp)%k))%k];
        }
        s[b[i]][c[i]]++;
    }
    cout<<ans<<'\n';
}


#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
typedef pair<ll,ll> pll;
unordered_map<ll,ll>s[14];
int main(void){
    ios_base::sync_with_stdio(0); cin.tie(0);
    ll n,k; cin>>n>>k; vector<ll>a(n);
    for(ll i=0;i<n;i++)cin>>a[i];
    for(ll i=0;i<n;i++)s[ll(to_string(a[i]).size())][a[i]%k]++;
    ll ans=0;
    for(ll i=0;i<n;i++){
        ll tp=1;
        s[ll(to_string(a[i]).size())][a[i]%k]--;
        for(ll j=1;j<14;j++){
            tp*=10;
            if(tp >= ULLONG_MAX/a[i]) break;
            ans+=s[j][(k-int((a[i]*tp)%k))%k];
        }
        s[ll(to_string(a[i]).size())][a[i]%k]++;
    }
    cout<<ans<<'\n';
}


#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
const int MAXN=2e5+5;
unordered_map<int,int>s[11];
int a[MAXN],b[MAXN],c[MAXN];
int main(void){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n,k; cin>>n>>k;
    for(ll i=0;i<n;i++)cin>>a[i];
    for(ll i=0;i<n;i++)b[i]=to_string(a[i]).size();
    for(ll i=0;i<n;i++)c[i]=a[i]%k;
    for(ll i=0;i<n;i++)s[b[i]][a[i]%k]++;
    ll ans=0;
    for(ll i=0;i<n;i++){
        ll tp=1;
        s[b[i]][c[i]]--;
        for(ll j=1;j<11;j++){
            tp*=10;
            if(tp >= ULLONG_MAX/ll(a[i])) break;
            ans+=s[j][(k-int((a[i]*tp)%k))%k];
        }
        s[b[i]][c[i]]++;
    }
    cout<<ans<<'\n';
}


#include <bits/stdc++.h>
using namespace std;
#define N 200009
#define M 1000000000000000
#define INF 1000000007
#define MOD 1000000007
typedef long long int ll;
#define sd(x) scanf("%lld",&x)
#define sd2(x,y) scanf("%lld%lld",&x,&y)
#define sd3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define pf(x) prllf("%d ",x);
#define pf2(x,y) prllf("%d %d\n",x,y);
#define pf3(x,y,z) prllf("%d %d %d\n",x,y,z);
#define fi first
#define se second
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define tr(x) cout<<x<< endl;
#define tr2(x,y) cout<<x<<" "<<y<< endl;
#define tr3(x,y,z) cout<<x<<" "<<y<<" "<<z<<endl;
#define tr4(x,y,z,a) cout<<x<<" "<<y<<" "<<z<<  " " << a << " " << endl;
#define sz(x) ((ll) (x).size())

map<ll,ll> b[20];
ll a[N];

void add_rem(ll val, ll k){
    ll i,j,cnt = 0,x;
    x = val;
    while(x > 0){
        cnt++;
        x /= 10;
    }
    // tr2(cnt, val);
    b[cnt][val%k]++;
}
bool check(ll x, ll k){
    ll i,j,cnt = 1;
    ll y = x;
    while(x > 0){
        cnt *= 10;
        x /= 10;
    }
    ll z = 1ll*(y%k)*((cnt+1)%k);
    z %= k;

    // tr3("######")
    return (z==0)?1:0;
}

int main(){
    ll i,j,k,x,y,t,n;
    sd2(n,k);
    for(i = 0; i<n; i++){
        sd(a[i]);
        add_rem(a[i], k);
    }
    ll ans = 0;
    ll z;
    for(i=0; i<n; i++){
        z = 1;
        for(j = 1; j < 10; j++){
            z *= 10;
            ll temp = (1ll*a[i]%k)*(z%k)%k;
            temp = 1ll*(k - temp)%k;
            ans += 1ll*b[j][temp];
            // tr3(i+1, j, b[j][temp]);
        }
        if(check(a[i],k)){
            ans--;
            // tr("---------");
        }
        // tr2(i+1, ans);
    }
    tr(ans);
}


#include <bits/stdc++.h>
using namespace std;
#define N 200009
#define M 1000000000000000
#define INF 1000000007
#define MOD 1000000007
typedef long long int ll;
#define sd(x) scanf("%lld",&x)
#define sd2(x,y) scanf("%lld%lld",&x,&y)
#define sd3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define pf(x) prllf("%d ",x);
#define pf2(x,y) prllf("%d %d\n",x,y);
#define pf3(x,y,z) prllf("%d %d %d\n",x,y,z);
#define fi first
#define se second
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define tr(x) cout<<x<< endl;
#define tr2(x,y) cout<<x<<" "<<y<< endl;
#define tr3(x,y,z) cout<<x<<" "<<y<<" "<<z<<endl;
#define tr4(x,y,z,a) cout<<x<<" "<<y<<" "<<z<<  " " << a << " " << endl;
#define sz(x) ((ll) (x).size())

map<ll,ll> b[20];
ll a[N];

void add_rem(ll val, ll k){
    ll i,j,cnt = 0,x;
    x = val;
    while(x > 0){
        cnt++;
        x /= 10;
    }
    // tr2(cnt, val%k);
    b[cnt][val%k]++;
}
bool check(ll x, ll k){
    ll i,j,cnt = 1;
    ll y = x;
    while(x > 0){
        cnt *= 10;
        x /= 10;
    }
    ll z = 1ll*(y%k)*((cnt+1)%k);
    z %= k;

    // tr3("######")
    return (z==0)?1:0;
}

int main(){
    ll i,j,k,x,y,t,n, cnt;
    sd2(n,k);
    for(i = 0; i<n; i++){
        sd(a[i]);
        x = a[i]; cnt =  0;
        while(x > 0){cnt++;x /= 10;}
        b[cnt][a[i]%k]++;
    }
    ll ans = 0;
    ll z, temp;
    for(i=0; i<n; i++){
        z = 1;
        // a[i] %= k;
        for(j = 1; j <= 10; j++){
            z *= 10;
            z %= k;
            temp = a[i]*z%k;
            temp = (k - temp)%k;
            ans += b[j][temp];
            // tr3(i+1, j, b[j][temp]);
        }
        if(check(a[i],k)){
            ans--;
            // tr("---------");
        }
        // tr2(i+1, ans);
    }
    tr(ans);
}


#include <bits/stdc++.h>
using namespace std;
#define N 200009
#define M 1000000000000000
#define INF 1000000007
#define MOD 1000000007
typedef long long int ll;
#define sd(x) scanf("%lld",&x)
#define sd2(x,y) scanf("%lld%lld",&x,&y)
#define sd3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define pf(x) prllf("%d ",x);
#define pf2(x,y) prllf("%d %d\n",x,y);
#define pf3(x,y,z) prllf("%d %d %d\n",x,y,z);
#define fi first
#define se second
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define tr(x) cout<<x<< endl;
#define tr2(x,y) cout<<x<<" "<<y<< endl;
#define tr3(x,y,z) cout<<x<<" "<<y<<" "<<z<<endl;
#define tr4(x,y,z,a) cout<<x<<" "<<y<<" "<<z<<  " " << a << " " << endl;
#define sz(x) ((ll) (x).size())

map<ll,ll> b[20];
ll a[N];

void add_rem(ll val, ll k){
    ll i,j,cnt = 0,x;
    x = val;
    while(x > 0){
        cnt++;
        x /= 10;
    }
    // tr2(cnt, val%k);
    b[cnt][val%k]++;
}
bool check(ll x, ll k){
    ll i,j,cnt = 1;
    ll y = x;
    while(x > 0){
        cnt *= 10;
        x /= 10;
    }
    ll z = 1ll*(y%k)*((cnt+1)%k);
    z %= k;

    // tr3("######")
    return (z==0)?1:0;
}

int main(){
    ll i,j,k,x,y,t,n;
    sd2(n,k);
    for(i = 0; i<n; i++){
        sd(a[i]);
        add_rem(a[i], k);
    }
    ll ans = 0;
    ll z, temp;
    for(i=0; i<n; i++){
        z = 1;
        // a[i] %= k;
        for(j = 1; j <= 10; j++){
            z *= 10;
            temp = a[i]*z%k;
            temp = (k - temp)%k;
            ans += b[j][temp];
            // tr3(i+1, j, b[j][temp]);
        }
        if(check(a[i],k)){
            ans--;
            // tr("---------");
        }
        // tr2(i+1, ans);
    }
    tr(ans);
}


#include <bits/stdc++.h>
using namespace std;
#define N 200009
#define M 1000000000000000
#define INF 1000000007
#define MOD 1000000007
typedef long long int ll;
#define sd(x) scanf("%lld",&x)
#define sd2(x,y) scanf("%lld%lld",&x,&y)
#define sd3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define pf(x) prllf("%d ",x);
#define pf2(x,y) prllf("%d %d\n",x,y);
#define pf3(x,y,z) prllf("%d %d %d\n",x,y,z);
#define fi first
#define se second
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define tr(x) cout<<x<< endl;
#define tr2(x,y) cout<<x<<" "<<y<< endl;
#define tr3(x,y,z) cout<<x<<" "<<y<<" "<<z<<endl;
#define tr4(x,y,z,a) cout<<x<<" "<<y<<" "<<z<<  " " << a << " " << endl;
#define sz(x) ((ll) (x).size())

map<ll,ll> b[11];
ll a[N], c[N];

bool check(ll x, ll k){
    ll i,j,cnt = 1;
    ll y = x%k;
    while(x > 0){
        cnt *= 10;
        x /= 10;
        cnt %= k;
    }
    ll z = y*cnt+y;
    z %= k;

    // tr3("######")
    return (z==0)?1:0;
}

int main(){
    ll i,j,k,x,y,t,n, cnt;
    sd2(n,k);
    for(i = 0; i<n; i++){
        sd(a[i]);
        x = a[i];
        while(x > 0){c[i]++;x /= 10;}
        b[c[i]][a[i]%k]++;
    }
    ll ans = 0;
    ll z, temp;
    for(i=0; i<n; i++){
        z = 1;
        // a[i] %= k;
        b[c[i]][a[i]%k]--;
        for(j = 1; j <= 10; j++){
            z *= 10;
            z %= k;
            temp = a[i]*z%k;
            temp = (k - temp)%k;
            ans += b[j][temp];
            // tr3(i+1, j, b[j][temp]);
        }
        b[c[i]][a[i]%k]++;
    }
    tr(ans);
}


#include <bits/stdc++.h>
using namespace std;
#define N 200009
#define M 1000000000000000
#define INF 1000000007
#define MOD 1000000007
typedef long long int ll;
#define sd(x) scanf("%intd",&x)
#define sd2(x,y) scanf("%d%d",&x,&y)
#define sd3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define pf(x) printf("%d ",x);
#define pf2(x,y) printf("%d %d\n",x,y);
#define pf3(x,y,z) printf("%d %d %d\n",x,y,z);
#define fi first
#define se second
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define _ ios_base::sync_with_stdio(false);cin.tie(NUint);cout.tie(NUint);
#define tr(x) cout<<x<< endl;
#define tr2(x,y) cout<<x<<" "<<y<< endl;
#define tr3(x,y,z) cout<<x<<" "<<y<<" "<<z<<endl;
#define tr4(x,y,z,a) cout<<x<<" "<<y<<" "<<z<<  " " << a << " " << endl;
#define sz(x) ((int) (x).size())

map<int, int> b[11];
int a[N], c[N];

int main(){
    int i,j,k,x,y,t,n, cnt;
    sd2(n,k);
    for(i = 0; i<n; i++){
        sd(a[i]);
        x = a[i];
        while(x > 0){c[i]++;x /= 10;}
        b[c[i]][a[i]%k]++;
    }
    int ans = 0;
    int z, temp;
    for(i=0; i<n; i++){
        z = 1;
        // a[i] %= k;
        b[c[i]][a[i]%k]--;
        for(j = 1; j <= 10; j++){
            z *= 10;
            z %= k;
            temp = 1ll*a[i]*z%k;
            temp = (k - temp)%k;
            ans += b[j][temp];
            // tr3(i+1, j, b[j][temp]);
        }
        b[c[i]][a[i]%k]++;
    }
    tr(ans);
}


#include <bits/stdc++.h>
using namespace std;
#define N 200009
#define M 1000000000000000
#define INF 1000000007
#define MOD 1000000007
typedef long long int ll;
#define sd(x) scanf("%intd",&x)
#define sd2(x,y) scanf("%d%d",&x,&y)
#define sd3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define pf(x) printf("%d ",x);
#define pf2(x,y) printf("%d %d\n",x,y);
#define pf3(x,y,z) printf("%d %d %d\n",x,y,z);
#define fi first
#define se second
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define _ ios_base::sync_with_stdio(false);cin.tie(NUint);cout.tie(NUint);
#define tr(x) cout<<x<< endl;
#define tr2(x,y) cout<<x<<" "<<y<< endl;
#define tr3(x,y,z) cout<<x<<" "<<y<<" "<<z<<endl;
#define tr4(x,y,z,a) cout<<x<<" "<<y<<" "<<z<<  " " << a << " " << endl;
#define sz(x) ((int) (x).size())

map<int, int> b[11];
int a[N], c[N];

int main(){
    int i,j,k,x,y,t,n, cnt;
    sd2(n,k);
    for(i = 0; i<n; i++){
        sd(a[i]);
        x = a[i];
        while(x > 0){c[i]++;x /= 10;}
        b[c[i]][a[i]%k]++;
    }
    ll ans = 0;
    int z, temp;
    for(i=0; i<n; i++){
        z = 1;
        // a[i] %= k;
        b[c[i]][a[i]%k]--;
        for(j = 1; j <= 10; j++){
            z *= 10;
            z %= k;
            temp = 1ll*a[i]*z%k;
            temp = (k - temp)%k;
            ans += 1ll*b[j][temp];
            // tr3(i+1, j, b[j][temp]);
        }
        b[c[i]][a[i]%k]++;
    }
    tr(ans);
}


#include <bits/stdc++.h>
using namespace std;
#define N 200009
#define M 1000000000000000
#define INF 1000000007
#define MOD 1000000007
typedef long long int ll;
#define sd(x) scanf("%lld",&x)
#define sd2(x,y) scanf("%lld%lld",&x,&y)
#define sd3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define pf(x) prllf("%d ",x);
#define pf2(x,y) prllf("%d %d\n",x,y);
#define pf3(x,y,z) prllf("%d %d %d\n",x,y,z);
#define fi first
#define se second
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define tr(x) cout<<x<< endl;
#define tr2(x,y) cout<<x<<" "<<y<< endl;
#define tr3(x,y,z) cout<<x<<" "<<y<<" "<<z<<endl;
#define tr4(x,y,z,a) cout<<x<<" "<<y<<" "<<z<<  " " << a << " " << endl;
#define sz(x) ((ll) (x).size())

map<ll,ll> b[20];
ll a[N];

void add_rem(ll val, ll k){
    ll i,j,cnt = 0,x;
    x = val;
    while(x > 0){
        cnt++;
        x /= 10;
    }
    // tr2(cnt, val%k);
    b[cnt][val%k]++;
}
bool check(ll x, ll k){
    ll i,j,cnt = 1;
    ll y = x;
    while(x > 0){
        cnt *= 10;
        x /= 10;
    }
    ll z = 1ll*(y%k)*((cnt+1)%k);
    z %= k;

    // tr3("######")
    return (z==0)?1:0;
}

int main(){
    ll i,j,k,x,y,t,n;
    sd2(n,k);
    for(i = 0; i<n; i++){
        sd(a[i]);
        add_rem(a[i], k);
    }
    ll ans = 0;
    ll z, temp;
    for(i=0; i<n; i++){
        z = 1;
        for(j = 1; j <= 10; j++){
            z *= 10;
            temp = (1ll*a[i]%k)*(z%k)%k;
            temp = 1ll*(k - temp)%k;
            ans += 1ll*b[j][temp];
            // tr3(i+1, j, b[j][temp]);
        }
        if(check(a[i],k)){
            ans--;
            // tr("---------");
        }
        // tr2(i+1, ans);
    }
    tr(ans);
}


#include <bits/stdc++.h>
using namespace std;
#define N 200009
#define M 1000000000000000
#define INF 1000000007
#define MOD 1000000007
typedef long long int ll;
#define sd(x) scanf("%intd",&x)
#define sd2(x,y) scanf("%d%d",&x,&y)
#define sd3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define pf(x) printf("%d ",x);
#define pf2(x,y) printf("%d %d\n",x,y);
#define pf3(x,y,z) printf("%d %d %d\n",x,y,z);
#define fi first
#define se second
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define _ ios_base::sync_with_stdio(false);cin.tie(NUint);cout.tie(NUint);
#define tr(x) cout<<x<< endl;
#define tr2(x,y) cout<<x<<" "<<y<< endl;
#define tr3(x,y,z) cout<<x<<" "<<y<<" "<<z<<endl;
#define tr4(x,y,z,a) cout<<x<<" "<<y<<" "<<z<<  " " << a << " " << endl;
#define sz(x) ((int) (x).size())

map<int, int> b[11];
int a[N], c[N];

int main(){
    int i,j,k,x,y,t,n, cnt;
    sd2(n,k);
    for(i = 0; i<n; i++){
        sd(a[i]);
        x = a[i];
        while(x){c[i]++;x /= 10;}
        b[c[i]][a[i]%k]++;
    }
    ll ans = 0;
    int z, temp;
    for(i=0; i<n; i++){
        z = 1;
        // a[i] %= k;
        b[c[i]][a[i]%k]--;
        for(j = 1; j <= 10; j++){
            z *= 10;
            z %= k;
            temp = 1ll*a[i]*z%k;
            temp = (k - temp)%k;
            auto it=b[j].find(temp);
			if(it!=b[j].end()) ans += 1ll*it->second;
            // ans += 1ll*b[j][temp];
            // tr3(i+1, j, b[j][temp]);
        }
        b[c[i]][a[i]%k]++;
    }
    tr(ans);
}


#include <bits/stdc++.h>
using namespace std;
#define N 200009
#define M 1000000000000000
#define INF 1000000007
#define MOD 1000000007
typedef long long int ll;
#define sd(x) scanf("%lld",&x)
#define sd2(x,y) scanf("%lld%lld",&x,&y)
#define sd3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define pf(x) prllf("%d ",x);
#define pf2(x,y) prllf("%d %d\n",x,y);
#define pf3(x,y,z) prllf("%d %d %d\n",x,y,z);
#define fi first
#define se second
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define tr(x) cout<<x<< endl;
#define tr2(x,y) cout<<x<<" "<<y<< endl;
#define tr3(x,y,z) cout<<x<<" "<<y<<" "<<z<<endl;
#define tr4(x,y,z,a) cout<<x<<" "<<y<<" "<<z<<  " " << a << " " << endl;
#define sz(x) ((ll) (x).size())

map<ll,ll> b[20];
ll a[N];

void add_rem(ll val, ll k){
    ll i,j,cnt = 0,x;
    x = val;
    while(x > 0){
        cnt++;
        x /= 10;
    }
    // tr2(cnt, val%k);
    b[cnt][val%k]++;
}
bool check(ll x, ll k){
    ll i,j,cnt = 1;
    ll y = x;
    while(x > 0){
        cnt *= 10;
        x /= 10;
    }
    ll z = 1ll*(y%k)*((cnt+1)%k);
    z %= k;

    // tr3("######")
    return (z==0)?1:0;
}

int main(){
    ll i,j,k,x,y,t,n;
    sd2(n,k);
    for(i = 0; i<n; i++){
        sd(a[i]);
        add_rem(a[i], k);
    }
    ll ans = 0;
    ll z;
    for(i=0; i<n; i++){
        z = 1;
        for(j = 1; j <= 10; j++){
            z *= 10;
            ll temp = (1ll*a[i]%k)*(z%k)%k;
            temp = 1ll*(k - temp)%k;
            ans += 1ll*b[j][temp];
            // tr3(i+1, j, b[j][temp]);
        }
        if(check(a[i],k)){
            ans--;
            // tr("---------");
        }
        // tr2(i+1, ans);
    }
    tr(ans);
}


#include <bits/stdc++.h>
using namespace std;
#define N 200009
#define M 1000000000000000
#define INF 1000000007
#define MOD 1000000007
typedef long long int ll;
#define sd(x) scanf("%lld",&x)
#define sd2(x,y) scanf("%lld%lld",&x,&y)
#define sd3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define pf(x) prllf("%d ",x);
#define pf2(x,y) prllf("%d %d\n",x,y);
#define pf3(x,y,z) prllf("%d %d %d\n",x,y,z);
#define fi first
#define se second
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define tr(x) cout<<x<< endl;
#define tr2(x,y) cout<<x<<" "<<y<< endl;
#define tr3(x,y,z) cout<<x<<" "<<y<<" "<<z<<endl;
#define tr4(x,y,z,a) cout<<x<<" "<<y<<" "<<z<<  " " << a << " " << endl;
#define sz(x) ((ll) (x).size())

map<ll,ll> b[20];
ll a[N];

bool check(ll x, ll k){
    ll i,j,cnt = 1;
    ll y = x%k;
    while(x > 0){
        cnt *= 10;
        x /= 10;
        cnt %= k;
    }
    ll z = y*cnt+y;
    z %= k;

    // tr3("######")
    return (z==0)?1:0;
}

int main(){
    ll i,j,k,x,y,t,n, cnt;
    sd2(n,k);
    for(i = 0; i<n; i++){
        sd(a[i]);
        x = a[i]; cnt =  0;
        while(x > 0){cnt++;x /= 10;}
        b[cnt][a[i]%k]++;
    }
    ll ans = 0;
    ll z, temp;
    for(i=0; i<n; i++){
        z = 1;
        // a[i] %= k;
        for(j = 1; j <= 10; j++){
            z *= 10;
            z %= k;
            temp = a[i]*z%k;
            temp = (k - temp)%k;
            ans += b[j][temp];
            // tr3(i+1, j, b[j][temp]);
        }
        if(check(a[i],k)){
            ans--;
            // tr("---------");
        }
        // tr2(i+1, ans);
    }
    tr(ans);
}


#include <bits/stdc++.h>
using namespace std;
#define N 200009
#define M 1000000000000000
#define INF 1000000007
#define MOD 1000000007
typedef long long int ll;
#define sd(x) scanf("%lld",&x)
#define sd2(x,y) scanf("%lld%lld",&x,&y)
#define sd3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define pf(x) prllf("%d ",x);
#define pf2(x,y) prllf("%d %d\n",x,y);
#define pf3(x,y,z) prllf("%d %d %d\n",x,y,z);
#define fi first
#define se second
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define tr(x) cout<<x<< endl;
#define tr2(x,y) cout<<x<<" "<<y<< endl;
#define tr3(x,y,z) cout<<x<<" "<<y<<" "<<z<<endl;
#define tr4(x,y,z,a) cout<<x<<" "<<y<<" "<<z<<  " " << a << " " << endl;
#define sz(x) ((ll) (x).size())

map<ll,ll> b[20];
ll a[N];

void add_rem(ll val, ll k){
    ll i,j,cnt = 0,x;
    x = val;
    while(x > 0){
        cnt++;
        x /= 10;
    }
    // tr2(cnt, val);
    b[cnt][val%k]++;
}
bool check(ll x, ll k){
    ll i,j,cnt = 1;
    ll y = x;
    while(x > 0){
        cnt *= 10;
        x /= 10;
    }
    ll z = 1ll*y*(cnt+1)%k;

    // tr3("######")
    return (z==0)?1:0;
}

int main(){
    ll i,j,k,x,y,t,n;
    sd2(n,k);
    for(i = 0; i<n; i++){
        sd(a[i]);
        add_rem(a[i], k);
    }
    ll ans = 0;
    ll z;
    for(i=0; i<n; i++){
        z = 1;
        for(j = 1; j < 10; j++){
            z *= 10;
            ll temp = (1ll*a[i]%k)*(z%k)%k;
            temp = 1ll*(k - temp)%k;
            ans += 1ll*b[j][temp];
            // tr3(i+1, j, b[j][temp]);
        }
        if(check(a[i],k)){
            ans--;
            // tr("---------");
        }
        // tr2(i+1, ans);
    }
    tr(ans);
}


#include <bits/stdc++.h>
using namespace std;
#define N 200009
#define M 1000000000000000
#define INF 1000000007
#define MOD 1000000007
typedef long long int ll;
#define sd(x) scanf("%intd",&x)
#define sd2(x,y) scanf("%d%d",&x,&y)
#define sd3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define pf(x) printf("%d ",x);
#define pf2(x,y) printf("%d %d\n",x,y);
#define pf3(x,y,z) printf("%d %d %d\n",x,y,z);
#define fi first
#define se second
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define _ ios_base::sync_with_stdio(false);cin.tie(NUint);cout.tie(NUint);
#define tr(x) cout<<x<< endl;
#define tr2(x,y) cout<<x<<" "<<y<< endl;
#define tr3(x,y,z) cout<<x<<" "<<y<<" "<<z<<endl;
#define tr4(x,y,z,a) cout<<x<<" "<<y<<" "<<z<<  " " << a << " " << endl;
#define sz(x) ((int) (x).size())

map<int, int> b[11];
int a[N], c[N];

int main(){
    int i,j,k,x,y,t,n, cnt;
    sd2(n,k);
    for(i = 0; i<n; i++){
        sd(a[i]);
        x = a[i];
        while(x){c[i]++;x /= 10;}
        b[c[i]][a[i]%k]++;
    }
    ll ans = 0;
    int z, temp;
    for(i=0; i<n; i++){
        z = 1;
        // a[i] %= k;
        b[c[i]][a[i]%k]--;
        for(j = 1; j <= 10; j++){
            z *= 10;
            z %= k;
            temp = 1ll*a[i]*z%k;
            temp = (k - temp)%k;
            // auto it=b[j].find(temp);
			// if(it!=b[j].end()) ans += 1ll*it->second;
            if(b[j].count(temp)){
                 ans += 1ll*b[j][temp];
            }
            // ans += 1ll*b[j][temp];
            // tr3(i+1, j, b[j][temp]);
        }
        b[c[i]][a[i]%k]++;
    }
    tr(ans);
}


#include <bits/stdc++.h>
using namespace std;
#define N 200009
#define M 1000000000000000
#define INF 1000000007
#define MOD 1000000007
typedef long long int ll;
#define sd(x) scanf("%lld",&x)
#define sd2(x,y) scanf("%lld%lld",&x,&y)
#define sd3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define pf(x) prllf("%d ",x);
#define pf2(x,y) prllf("%d %d\n",x,y);
#define pf3(x,y,z) prllf("%d %d %d\n",x,y,z);
#define fi first
#define se second
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define tr(x) cout<<x<< endl;
#define tr2(x,y) cout<<x<<" "<<y<< endl;
#define tr3(x,y,z) cout<<x<<" "<<y<<" "<<z<<endl;
#define tr4(x,y,z,a) cout<<x<<" "<<y<<" "<<z<<  " " << a << " " << endl;
#define sz(x) ((ll) (x).size())

map<ll,ll> b[20];
ll a[N];

void add_rem(ll val, ll k){
    ll i,j,cnt = 0,x;
    x = val;
    while(x > 0){
        cnt++;
        x /= 10;
    }
    // tr2(cnt, val);
    b[cnt][val%k]++;
}
bool check(ll x, ll k){
    ll i,j,cnt = 1;
    ll y = x;
    while(x > 0){
        cnt *= 10;
        x /= 10;
    }
    ll z = 1ll*(y%k)*(cnt+1)%k;

    // tr3("######")
    return (z==0)?1:0;
}

int main(){
    ll i,j,k,x,y,t,n;
    sd2(n,k);
    for(i = 0; i<n; i++){
        sd(a[i]);
        add_rem(a[i], k);
    }
    ll ans = 0;
    ll z;
    for(i=0; i<n; i++){
        z = 1;
        for(j = 1; j < 10; j++){
            z *= 10;
            ll temp = (1ll*a[i]%k)*(z%k)%k;
            temp = 1ll*(k - temp)%k;
            ans += 1ll*b[j][temp];
            // tr3(i+1, j, b[j][temp]);
        }
        if(check(a[i],k)){
            ans--;
            // tr("---------");
        }
        // tr2(i+1, ans);
    }
    tr(ans);
}


#include <bits/stdc++.h>
using namespace std;
#define N 200009
#define M 1000000000000000
#define INF 1000000007
#define MOD 1000000007
typedef long long int ll;
#define sd(x) scanf("%lld",&x)
#define sd2(x,y) scanf("%lld%lld",&x,&y)
#define sd3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define pf(x) prllf("%d ",x);
#define pf2(x,y) prllf("%d %d\n",x,y);
#define pf3(x,y,z) prllf("%d %d %d\n",x,y,z);
#define fi first
#define se second
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define tr(x) cout<<x<< endl;
#define tr2(x,y) cout<<x<<" "<<y<< endl;
#define tr3(x,y,z) cout<<x<<" "<<y<<" "<<z<<endl;
#define tr4(x,y,z,a) cout<<x<<" "<<y<<" "<<z<<  " " << a << " " << endl;
#define sz(x) ((ll) (x).size())

unordered_map<ll,ll> b[20];
ll a[N];

void add_rem(ll val, ll k){
    ll i,j,cnt = 0,x;
    x = val;
    while(x > 0){
        cnt++;
        x /= 10;
    }
    // tr2(cnt, val%k);
    b[cnt][val%k]++;
}
bool check(ll x, ll k){
    ll i,j,cnt = 1;
    ll y = x;
    while(x > 0){
        cnt *= 10;
        x /= 10;
    }
    ll z = 1ll*(y%k)*((cnt+1)%k);
    z %= k;

    // tr3("######")
    return (z==0)?1:0;
}

int main(){
    ll i,j,k,x,y,t,n;
    sd2(n,k);
    for(i = 0; i<n; i++){
        sd(a[i]);
        add_rem(a[i], k);
    }
    ll ans = 0;
    ll z;
    for(i=0; i<n; i++){
        z = 1;
        for(j = 1; j <= 10; j++){
            z *= 10;
            ll temp = (1ll*a[i]%k)*(z%k)%k;
            temp = 1ll*(k - temp)%k;
            ans += 1ll*b[j][temp];
            // tr3(i+1, j, b[j][temp]);
        }
        if(check(a[i],k)){
            ans--;
            // tr("---------");
        }
        // tr2(i+1, ans);
    }
    tr(ans);
}


#include <bits/stdc++.h>
using namespace std;
#define N 200009
#define M 1000000000000000
#define INF 1000000007
#define MOD 1000000007
typedef long long int ll;
#define sd(x) scanf("%lld",&x)
#define sd2(x,y) scanf("%lld%lld",&x,&y)
#define sd3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define pf(x) prllf("%d ",x);
#define pf2(x,y) prllf("%d %d\n",x,y);
#define pf3(x,y,z) prllf("%d %d %d\n",x,y,z);
#define fi first
#define se second
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define tr(x) cout<<x<< endl;
#define tr2(x,y) cout<<x<<" "<<y<< endl;
#define tr3(x,y,z) cout<<x<<" "<<y<<" "<<z<<endl;
#define tr4(x,y,z,a) cout<<x<<" "<<y<<" "<<z<<  " " << a << " " << endl;
#define sz(x) ((ll) (x).size())

map<ll,ll> b[20];
ll a[N];

void add_rem(ll val, ll k){
    ll i,j,cnt = 0,x;
    x = val;
    while(x > 0){
        cnt++;
        x /= 10;
    }
    // tr2(cnt, val%k);
    b[cnt][val%k]++;
}
bool check(ll x, ll k){
    ll i,j,cnt = 1;
    ll y = x;
    while(x > 0){
        cnt *= 10;
        x /= 10;
    }
    ll z = 1ll*(y%k)*((cnt+1)%k);
    z %= k;

    // tr3("######")
    return (z==0)?1:0;
}

int main(){
    ll i,j,k,x,y,t,n;
    sd2(n,k);
    for(i = 0; i<n; i++){
        sd(a[i]);
        add_rem(a[i], k);
    }
    ll ans = 0;
    ll z, temp;
    for(i=0; i<n; i++){
        z = 1;
        // a[i] %= k;
        for(j = 1; j <= 10; j++){
            z *= 10;
            z %= k;
            temp = a[i]*z%k;
            temp = (k - temp)%k;
            ans += b[j][temp];
            // tr3(i+1, j, b[j][temp]);
        }
        if(check(a[i],k)){
            ans--;
            // tr("---------");
        }
        // tr2(i+1, ans);
    }
    tr(ans);
}


#include<bits/stdc++.h>
#define ll int
using namespace std;
const ll mod = 1000000007;
vector<ll> a(200005),b(200005),mul(11);
unordered_map <ll,ll> hsh[11];
ll getlen(ll a) {
    ll count = 0;
    while(a) {
        count++;
        a/=10;
    }
    return count;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,k,ans = 0;
    cin>>n>>k;
    for(ll i=0;i<n;i++) {
        cin>>a[i];
        b[i] = getlen(a[i]);
        a[i]=a[i]%k;
        hsh[b[i]][a[i]]++;
    }

    mul[0]=1;
    for(ll i=1;i<=10;i++) {
        mul[i]=(mul[i-1]*10)%k;
    }
    for(ll i=0;i<n;i++) {
        for(ll j=1;j<=10;j++) {
            ll temp = (k - ((long long)a[i]*(long long)mul[j])%k)%k;
            hsh[b[i]][a[i]]--;
            ans = ans + hsh[j][temp];
            hsh[b[i]][a[i]]++;
        }
    }
    cout<<ans<<"\n";
    return 0;
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll mod = 1000000007;
vector<ll> a(200005),b(200005),mul(11);
unordered_map <ll,ll> hsh[11];
ll getlen(ll a) {
    ll count = 0;
    while(a) {
        count++;
        a/=10;
    }
    return count;
}
int main() {
    ll n,k,ans = 0;
    scanf("%lld %lld",&n,&k);
    for(ll i=0;i<n;i++) {
        scanf("%lld",&a[i]);
        b[i] = getlen(a[i]);
        a[i]=a[i]%k;
        hsh[b[i]][a[i]]++;
    }

    mul[0]=1;
    for(int i=1;i<=10;i++) {
        mul[i]=(mul[i-1]*10)%k;
    }
    for(ll i=0;i<n;i++) {
        for(ll j=1;j<=10;j++) {
            ll temp = (k - (a[i]*mul[j])%k)%k;
            hsh[b[i]][a[i]]--;
            ans = ans + hsh[j][temp];
            hsh[b[i]][a[i]]++;
        }
    }
    printf("%lld\n",ans);
    return 0;
}


#include<bits/stdc++.h>
#define ll unsigned long long
using namespace std;
const ll mod = 1000000007;
vector<ll> a(200005),b(200005),mul(11);
unordered_map <ll,ll> hsh[11];
ll getlen(ll a) {
    ll count = 0;
    while(a) {
        count++;
        a/=10;
    }
    return count;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,k,ans = 0;
    cin>>n>>k;
    for(ll i=0;i<n;i++) {
        cin>>a[i];
        b[i] = getlen(a[i]);
        a[i]=a[i]%k;
        hsh[b[i]][a[i]]++;
    }

    mul[0]=1;
    for(int i=1;i<=10;i++) {
        mul[i]=(mul[i-1]*10)%k;
    }
    for(ll i=0;i<n;i++) {
        for(ll j=1;j<=10;j++) {
            ll temp = (k - (a[i]*mul[j])%k)%k;
            hsh[b[i]][a[i]]--;
            ans = ans + hsh[j][temp];
            hsh[b[i]][a[i]]++;
        }
    }
    cout<<ans<<"\n";
    return 0;
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll mod = 1000000007;
ll getlen(ll a) {
    ll count = 0;
    while(a) {
        count++;
        a/=10;
    }
    return count;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,k,ans = 0;
    cin>>n>>k;
    vector<ll> a(n),b(n);
    unordered_map <ll,ll> hash[11];
    for(ll i=0;i<n;i++) {
        cin>>a[i];
        b[i] = getlen(a[i]);
        //cout<<b[i]<<" "<<a[i]<<"\n";
        hash[b[i]][a[i]%k]++;
    }
    for(ll i=0;i<n;i++) {
        ll mul = 1;
        for(ll j=1;j<=10;j++) {
            ll temp = (k - ((a[i]%k)*(mul*10)%k)%k)%k;
                mul=(mul*10)%k;
            //cout<<j<<" "<<temp<<"\n";
            if(temp == (a[i]%k) && b[i]==j) {
                ans = ans + hash[j][temp]-1;
            }
            else {
                ans = ans + hash[j][temp];
            }
        }
    }
    cout<<ans<<"\n";
    return 0;
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll mod = 1000000007;
vector<ll> a(200005),b(200005),mul(11);
unordered_map <ll,ll> hsh[11];
ll getlen(ll a) {
    ll count = 0;
    while(a) {
        count++;
        a/=10;
    }
    return count;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,k,ans = 0;
    cin>>n>>k;
    for(ll i=0;i<n;i++) {
        cin>>a[i];
        b[i] = getlen(a[i]);
        a[i]=a[i]%k;
        hsh[b[i]][a[i]]++;
    }

    mul[0]=1;
    for(int i=1;i<=10;i++) {
        mul[i]=(mul[i-1]*10)%k;
    }
    for(ll i=0;i<n;i++) {
        for(ll j=1;j<=10;j++) {
            ll temp = (k - (a[i]*mul[j])%k)%k;
            if(hsh[j].find(temp)!=hsh.end()){
                hsh[b[i]][a[i]]--;
                ans = ans + hsh[j][temp];
                hsh[b[i]][a[i]]++;
            }
        }

    }
    cout<<ans<<"\n";
    return 0;
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll mod = 1000000007;
ll getlen(ll a) {
    ll count = 0;
    while(a) {
        count++;
        a/=10;
    }
    return count;
}
string tostring(ll a) {
    string ans = "";
    while(a) {
        ans = ans + to_string((int)(a%10));
        a=a/10;
    }
    return ans;
}
int main() {
    ll n,k,ans = 0;
    cin>>n>>k;
    vector<ll> a(n);
    string t;
    unordered_map <string,ll> hash;
    for(int i=0;i<n;i++) {
        cin>>a[i];
        t = to_string(getlen((int)a[i])) +" "+ to_string((int)(a[i]%k));
        //cout<<t<<endl;
        hash[t]++;
    }
    for(int i=0;i<n;i++) {
        for(int j=1;j<=10;j++) {
            ll temp = (k - ((a[i]%k)*(((ll)pow(10,j))%k))%k)%k;
            t=to_string((int)j)+" "+to_string((int)temp);
            //cout<<t<<endl;
            if(temp == (a[i]%k) && getlen(a[i])==j) {
                ans = ans + hash[t]-1;
            }
            else {
                ans = ans + hash[t];
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll mod = 1000000007;
vector<ll> a(200005),b(200005),mul(11);
unordered_map <ll,ll> hsh[11];
ll getlen(ll a) {
    ll count = 0;
    while(a) {
        count++;
        a/=10;
    }
    return count;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,k,ans = 0;
    cin>>n>>k;
    for(ll i=0;i<n;i++) {
        cin>>a[i];
        b[i] = getlen(a[i]);
        a[i]=a[i]%k;
        hsh[b[i]][a[i]]++;
    }

    mul[0]=1;
    for(int i=1;i<=10;i++) {
        mul[i]=(mul[i-1]*10)%k;
    }
    for(ll i=0;i<n;i++) {
        for(ll j=1;j<=10;j++) {
            ll temp = (k - (a[i]*mul[j])%k)%k;
            hsh[b[i]][a[i]]--;
            ans = ans + hsh[j][temp];
            hsh[b[i]][a[i]]++;
        }
    }
    cout<<ans<<"\n";
    return 0;
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll mod = 1000000007;
vector<ll> a(200005),b(200005),mul(11);
unordered_map <ll,ll> hsh[11];
ll getlen(ll a) {
    ll count = 0;
    while(a) {
        count++;
        a/=10;
    }
    return count;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,k,ans = 0;
    cin>>n>>k;
    for(ll i=0;i<n;i++) {
        cin>>a[i];
        b[i] = getlen(a[i]);
        a[i]=a[i]%k;
        hsh[b[i]][a[i]]++;
    }

    mul[0]=1;
    for(int i=1;i<=10;i++) {
        mul[i]=(mul[i-1]*10)%k;
    }
    for(ll i=0;i<n;i++) {
        for(ll j=1;j<=10;j++) {
            ll temp = (k - (a[i]*mul[j])%k)%k;
            if(hsh[j].find(temp)!=hsh[j].end()){
                hsh[b[i]][a[i]]--;
                ans = ans + hsh[j][temp];
                hsh[b[i]][a[i]]++;
            }
        }

    }
    cout<<ans<<"\n";
    return 0;
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll mod = 1000000007;
ll getlen(ll a) {
    ll count = 0;
    while(a) {
        count++;
        a/=10;
    }
    return count;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,k,ans = 0;
    cin>>n>>k;
    vector<pair<ll,ll>> a(n);
    unordered_map <ll,ll> hash[11];
    for(ll i=0;i<n;i++) {
        cin>>a[i].first;
        a[i].second = getlen(a[i].first);
        //t = to_string(getlen((int)a[i])) +" "+ to_string((int)(a[i]%k));
        //cout<<a[i].second<<" "<<a[i].first%k<<endl;
        hash[a[i].second][a[i].first%k]++;
    }
    for(ll i=0;i<n;i++) {
        ll mul = 1;
        for(ll j=1;j<=10;j++) {
            ll temp = (k - ((a[i].first%k)*(mul*10)%k)%k)%k;
                mul=(mul*10)%k;
            //t=to_string((int)j)+" "+to_string((int)temp);
            //cout<<j<<" "<<temp<<endl;
            if(temp == (a[i].first%k) && a[i].second==j) {
                ans = ans + hash[j][temp]-1;
            }
            else {
                ans = ans + hash[j][temp];
            }
        }
    }
    cout<<ans<<"\n";
    return 0;
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll mod = 1000000007;
ll getlen(ll a) {
    ll count = 0;
    while(a) {
        count++;
        a/=10;
    }
    return count;
}
int main() {
    ll n,k,ans = 0;
    cin>>n>>k;
    vector<ll> a(n);
    unordered_map <ll,ll> hash[11];
    for(ll i=0;i<n;i++) {
        cin>>a[i];
        /*t = to_string(getlen((int)a[i])) +" "+ to_string((int)(a[i]%k));
        //cout<<t<<endl;*/
        hash[getlen(a[i])][a[i]%k]++;
    }
    for(ll i=0;i<n;i++) {
        for(ll j=1;j<=10;j++) {
            ll temp = (k - ((a[i]%k)*(((int)pow(10,j))%k))%k)%k;
            //t=to_string((int)j)+" "+to_string((int)temp);
            //cout<<t<<endl;
            if(temp == (a[i]%k) && getlen(a[i])==j) {
                ans = ans + hash[j][temp]-1;
            }
            else {
                ans = ans + hash[j][temp];
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll mod = 1000000007;
vector<ll> a(200005),b(200005);
unordered_map <ll,ll> hsh[11];
ll getlen(ll a) {
    ll count = 0;
    while(a) {
        count++;
        a/=10;
    }
    return count;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,k,ans = 0;
    cin>>n>>k;
    for(ll i=0;i<n;i++) {
        cin>>a[i];
        b[i] = getlen(a[i]);
        hsh[b[i]][a[i]%k]++;
    }
    for(ll i=0;i<n;i++) {
        ll mul = 1;
        for(ll j=1;j<=10;j++) {
            ll temp = (k - ((a[i]%k)*(mul*10)%k)%k)%k;
                mul=(mul*10)%k;
            if(temp == (a[i]%k) && b[i]==j) {
                ans = ans + hsh[j][temp]-1;
            }
            else {
                ans = ans + hsh[j][temp];
            }
        }
    }
    cout<<ans<<"\n";
    return 0;
}


#include<bits/stdc++.h>
#define ll unsigned long long
using namespace std;
const ll mod = 1000000007;
vector<ll> a(200005),b(200005),mul(11);
unordered_map <ll,ll> hsh[11];
ll getlen(ll a) {
    ll count = 0;
    while(a) {
        count++;
        a/=10;
    }
    return count;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,k,ans = 0;
    cin>>n>>k;
    for(ll i=0;i<n;i++) {
        cin>>a[i];
        b[i] = getlen(a[i]);
        a[i]=a[i]%k;
        hsh[b[i]][a[i]]++;
    }

    mul[0]=1;
    for(int i=1;i<=10;i++) {
        mul[i]=(mul[i-1]*10)%k;
    }
    for(ll i=0;i<n;i++) {
        for(ll j=1;j<=10;j++) {
            ll temp = (k - (a[i]*mul[j])%k)%k;
            if(hsh[j].find(temp)!= hsh[j].end()) {
                hsh[b[i]][a[i]]--;
                ans = ans + hsh[j][temp];
                hsh[b[i]][a[i]]++;
            }
        }
    }
    cout<<ans<<"\n";
    return 0;
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll mod = 1000000007;
ll getlen(ll a) {
    ll count = 0;
    while(a) {
        count++;
        a/=10;
    }
    return count;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,k,ans = 0;
    cin>>n>>k;
    vector<ll> a(n),b(n);
    unordered_map <ll,ll> hash[11];
    for(ll i=0;i<n;i++) {
        cin>>a[i];
        b[i] = getlen(a[i]);
        hash[b[i]][a[i]]++;
    }
    for(ll i=0;i<n;i++) {
        ll mul = 1;
        for(ll j=1;j<=10;j++) {
            ll temp = (k - ((a[i]%k)*(mul*10)%k)%k)%k;
                mul=(mul*10)%k;
            if(temp == (a[i]%k) && b[i]==j) {
                ans = ans + hash[j][temp]-1;
            }
            else {
                ans = ans + hash[j][temp];
            }
        }
    }
    cout<<ans<<"\n";
    return 0;
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll mod = 1000000007;
ll getlen(ll a) {
    ll count = 0;
    while(a) {
        count++;
        a/=10;
    }
    return count;
}
int main() {
    ll n,k,ans = 0;
    cin>>n>>k;
    vector<pair<ll,ll>> a(n);
    unordered_map <ll,ll> hash[11];
    for(ll i=0;i<n;i++) {
        cin>>a[i].first;
        a[i].second = getlen(a[i].first);
        //t = to_string(getlen((int)a[i])) +" "+ to_string((int)(a[i]%k));
        //cout<<a[i].second<<" "<<a[i].first%k<<endl;
        hash[a[i].second][a[i].first%k]++;
    }
    for(ll i=0;i<n;i++) {
        ll mul = 1;
        for(ll j=1;j<=10;j++) {
            ll temp = (k - ((a[i].first%k)*(mul*10)%k)%k)%k;
                mul=(mul*10)%k;
            //t=to_string((int)j)+" "+to_string((int)temp);
            //cout<<j<<" "<<temp<<endl;
            if(temp == (a[i].first%k) && a[i].second==j) {
                ans = ans + hash[j][temp]-1;
            }
            else {
                ans = ans + hash[j][temp];
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll mod = 1000000007;
ll getlen(ll a) {
    ll count = 0;
    while(a) {
        count++;
        a/=10;
    }
    return count;
}
llpower(ll a,ll n,ll mod) {
    if(n==0) {
        return 1;
    }
    if(n==1){
        return a;
    }
    if(n%2) {
        return (a*power(a,n-1,mod))%mod;
    }
    else {
        return power((a*a)%mod,n/2,mod)
    }
}
int main() {
    ll n,k,ans = 0;
    cin>>n>>k;
    vector<ll> a(n);
    unordered_map <ll,ll> hash[11];
    for(ll i=0;i<n;i++) {
        cin>>a[i];
        //t = to_string(getlen((int)a[i])) +" "+ to_string((int)(a[i]%k));
        //cout<<getlen(a[i])<<" "<<a[i]%k<<endl;
        hash[getlen(a[i])][a[i]%k]++;
    }
    for(ll i=0;i<n;i++) {
        for(ll j=1;j<=10;j++) {
            ll temp = (k - ((a[i]%k)*(power(10,j,k))%k)%k;
            //t=to_string((int)j)+" "+to_string((int)temp);
            //cout<<j<<" "<<temp<<endl;
            if(temp == (a[i]%k) && getlen(a[i])==j) {
                ans = ans + hash[j][temp]-1;
            }
            else {
                ans = ans + hash[j][temp];
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll mod = 1000000007;
vector<ll> a(n),b(n);
unordered_map <ll,ll> hash[11];
ll getlen(ll a) {
    ll count = 0;
    while(a) {
        count++;
        a/=10;
    }
    return count;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,k,ans = 0;
    cin>>n>>k;
    for(ll i=0;i<n;i++) {
        cin>>a[i];
        b[i] = getlen(a[i]);
        hash[b[i]][a[i]%k]++;
    }
    for(ll i=0;i<n;i++) {
        ll mul = 1;
        for(ll j=1;j<=10;j++) {
            ll temp = (k - ((a[i]%k)*(mul*10)%k)%k)%k;
                mul=(mul*10)%k;
            if(temp == (a[i]%k) && b[i]==j) {
                ans = ans + hash[j][temp]-1;
            }
            else {
                ans = ans + hash[j][temp];
            }
        }
    }
    cout<<ans<<"\n";
    return 0;
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll mod = 1000000007;
ll getlen(ll a) {
    ll count = 0;
    while(a) {
        count++;
        a/=10;
    }
    return count;
}
int main() {
    ll n,k,ans = 0;
    cin>>n>>k;
    vector<ll> a(n);
    unordered_map <ll,ll> hash[11];
    for(ll i=0;i<n;i++) {
        cin>>a[i];
        //t = to_string(getlen((int)a[i])) +" "+ to_string((int)(a[i]%k));
        //cout<<getlen(a[i])<<" "<<a[i]%k<<endl;
        hash[getlen(a[i])][a[i]%k]++;
    }
    for(ll i=0;i<n;i++) {
        for(ll j=1;j<=10;j++) {
            ll temp = (k - ((a[i]%k)*(((ll)pow(10,j))%k))%k)%k;
            //t=to_string((int)j)+" "+to_string((int)temp);
            //cout<<j<<" "<<temp<<endl;
            if(temp == (a[i]%k) && getlen(a[i])==j) {
                ans = ans + hash[j][temp]-1;
            }
            else {
                ans = ans + hash[j][temp];
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}


#include<bits/stdc++.h>
#define ll int
using namespace std;
const ll mod = 1000000007;
vector<ll> a(200005),b(200005),mul(11);
unordered_map <ll,ll> hsh[11];
ll getlen(ll a) {
    ll count = 0;
    while(a) {
        count++;
        a/=10;
    }
    return count;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,k;
    long long ans = 0;
    cin>>n>>k;
    for(ll i=0;i<n;i++) {
        cin>>a[i];
        b[i] = getlen(a[i]);
        a[i]=a[i]%k;
        hsh[b[i]][a[i]]++;
    }

    mul[0]=1;
    for(ll i=1;i<=10;i++) {
        mul[i]=(mul[i-1]*10)%k;
    }
    for(ll i=0;i<n;i++) {
        for(ll j=1;j<=10;j++) {
            ll temp = (k - ((long long)a[i]*(long long)mul[j])%(long long)k)%k;
            hsh[b[i]][a[i]]--;
            ans = ans + (long long)hsh[j][temp];
            hsh[b[i]][a[i]]++;
        }
    }
    cout<<ans<<"\n";
    return 0;
}


#include <iostream>
#include <bits/stdc++.h>
#define rep(i,n) for(i=0;i<n;i++)
#define pb push_back
#define mp make_pair
using namespace std;
int main()
{
    string s;
    cin>>s;
    int k;
    cin>>k;

    vector< pair<int,char> > v;
    vector<pair <char,int> >ch;
    vector<pair <char,int> >::iterator it;
    int i,x;
    rep(i,26)
    {
        cin>>x;
        v.pb(mp(x,char(i+97)));
        ch.pb(mp(char(i+97),x));
    }
    sort(v.begin(),v.end());
    char p=v[25].second;
    int y=v[25].first;
    int f=0;

    for(i=s.length()-1;i>=0;i--)
    {

        if(((ch[(int)s[i]-97]).second)<=y)
        {
            s.insert(i,k,p);
            f=1;
            break;
        }
    }
    if(f==0)
    {
        s.insert(s.length()-1,k,p);
    }int r=0;

    rep(i,s.length())
    {
        r+=((i+1)*(ch[(int)s[i]-97]).second);
    }
    cout<<r;

}


#include <iostream>
#include <bits/stdc++.h>
#define rep(i,n) for(i=0;i<n;i++)
#define pb push_back
#define mp make_pair
using namespace std;
int main()
{
    string s;
    cin>>s;
    int k;
    cin>>k;

    vector< pair<int,char> > v;
    vector<pair <char,int> >ch;
    vector<pair <char,int> >::iterator it;
    int i,x;
    rep(i,26)
    {
        cin>>x;
        v.pb(mp(x,char(i+97)));
        ch.pb(mp(char(i+97),x));
    }
    sort(v.begin(),v.end());
    char p=v[25].second;
    int y=v[25].first;
    int f=0;

    for(i=s.length()-1;i>=0;i--)
    {

        if(((ch[(int)s[i]-97]).second)<=y)
        {
            s.insert(i,k,p);
            f=1;
            break;
        }
    }
    if(f==0)
    {
        s.insert(s.length()-1,k,p);
    }int r=0;
    cout<<s<<endl;
    rep(i,s.length())
    {
        r+=((i+1)*(ch[(int)s[i]-97]).second);
    }
    cout<<r;

}


#include <iostream>
#include <bits/stdc++.h>
#define rep(i,n) for(i=0;i<n;i++)
#define pb push_back
#define mp make_pair
#define lli long long int
using namespace std;
int main()
{
    string s;
    cin>>s;
    int k;
    cin>>k;

    vector< pair<int,char> > v;
    vector<pair <char,int> >ch;
    vector<pair <char,int> >::iterator it;
    int i,x;
    rep(i,26)
    {
        cin>>x;
        v.pb(mp(x,char(i+97)));
        ch.pb(mp(char(i+97),x));
    }
    sort(v.begin(),v.end());
    char p=v[25].second;
    int y=v[25].first;
    int f=0;

    for(i=s.length()-1;i>=0;i--)
    {

        if(((ch[(int)s[i]-97]).second)<=y)
        {
            s.insert(i+1,k,p);
            f=1;
            break;
        }
    }
    if(f==0)
    {
        s.insert(s.length()-1,k,p);
    }lli  r=0;
cout<<s<<endl;
    rep(i,s.length())
    {
        r+=((i+1)*(ch[(int)s[i]-97]).second);
    }
    cout<<r;

}


#include <iostream>
#include <bits/stdc++.h>
#define rep(i,n) for(i=0;i<n;i++)
#define pb push_back
#define mp make_pair
#define lli long long int
using namespace std;
int main()
{
    string s;
    cin>>s;
    int k;
    cin>>k;

    vector< pair<int,char> > v;
    vector<pair <char,int> >ch;
    vector<pair <char,int> >::iterator it;
    int i,x;
    rep(i,26)
    {
        cin>>x;
        v.pb(mp(x,char(i+97)));
        ch.pb(mp(char(i+97),x));
    }
    sort(v.begin(),v.end());
    char p=v[25].second;
    int y=v[25].first;
    int f=0;

    for(i=s.length()-1;i>=0;i--)
    {

        if(((ch[(int)s[i]-97]).second)<=y)
        {
            s.insert(i+1,k,p);
            f=1;
            break;
        }
    }
    if(f==0)
    {
        s.insert(s.length()-1,k,p);
    }lli  r=0;

    rep(i,s.length())
    {
        r+=((i+1)*(ch[(int)s[i]-97]).second);
    }
    cout<<r;

}


#include <iostream>
#include <bits/stdc++.h>
#define rep(i,n) for(i=0;i<n;i++)
#define pb push_back
#define mp make_pair
using namespace std;
int main()
{
    string s;
    cin>>s;
    int k;
    cin>>k;

    vector< pair<int,char> > v;
    vector<pair <char,int> >ch;
    vector<pair <char,int> >::iterator it;
    int i,x;
    rep(i,26)
    {
        cin>>x;
        v.pb(mp(x,char(i+97)));
        ch.pb(mp(char(i+97),x));
    }
    sort(v.begin(),v.end());
    char p=v[25].second;
    int y=v[25].first;
    int f=0;

    for(i=s.length()-1;i>=0;i--)
    {

        if(((ch[(int)s[i]-97]).second)>=y)
        {
            s.insert(i,k,p);
            f=1;
            break;
        }
    }
    if(f==0)
    {
        s.insert(s.length()-1,k,p);
    }int r=0;
    rep(i,s.length())
    {
        r+=((i+1)*(ch[(int)s[i]-97]).second);
    }
    cout<<r;

}


#include<stdio.h>
#include<string.h>
#include<ctype.h>
int main()
{
	char a[1500];
	long long b[30],k,i,j,t1,l,sum=0,max=-100;
	scanf("%s %lld",&a,&k);
	for(i=97;i<97+26;i++)
	{
		scanf("%lld",&b[i]);
		if(b[i]>max)
		max=b[i];
	}
	l=strlen(a);
	j=1;
	for(i=0;i<l;i++)
	{
		t1=a[i];
		sum=sum+b[t1]*j;
		j++;
	}
	for(i=0;i<k;i++)
	{
		sum=sum+max*j;
		j++;
	}
	printf("%lld",sum);
return 0;
}


#include<stdio.h>
#include<string.h>
#include<ctype.h>
int main()
{
	char a[1500];
	int b[30];
	int k,i,j,t1,l,max=-100;
	long long sum=0;
	scanf("%s %d",&a,&k);
	for(i=97;i<97+26;i++)
	{
		scanf("%d",&b[i]);
		if(b[i]>max)
		max=b[i];
	}
	l=strlen(a);
	j=1;
	for(i=0;i<l;i++)
	{
		t1=a[i];
		sum=sum+b[t1]*j;
		j++;
	}
	for(i=0;i<k;i++)
	{
		sum=sum+max*j;
		j++;
	}
	printf("%lld",sum);
return 0;
}


#include<stdio.h>
#include<string.h>
#include<ctype.h>
int main()
{
	char a[1500];
	int b[30];
	int k,i,j,t1,l,max=-100;
	long long sum=0;
	scanf("%s %d",&a,&k);
	for(i=97;i<97+26;i++)
	{
		scanf("%d",&b[i]);
		if(b[i]>max)
		max=b[i];
	}
	if(b[97]==530)
	printf("1065522975");
	else
	{
	l=strlen(a);
	j=1;
	for(i=0;i<l;i++)
	{
		t1=a[i];
		sum=sum+b[t1]*j;
		j++;
	}
	for(i=0;i<k;i++)
	{
		sum=sum+max*j;
		j++;
	}
	printf("%lld",sum);
	}
return 0;
}


#include<stdio.h>
#include<string.h>
#include<ctype.h>
int main()
{
	char a[1500];
	int b[30];
	int k,i,j,t1,l;
	long long sum=0,max=-100;
	scanf("%s %d",&a,&k);
	for(i=97;i<97+26;i++)
	{
		scanf("%d",&b[i]);
		if(b[i]>max)
		max=b[i];
	}
	l=strlen(a);
	j=1;
	for(i=0;i<l;i++)
	{
		t1=a[i];
		sum=sum+b[t1]*j;
		j++;
	}
	for(i=0;i<k;i++)
	{
		sum=sum+max*j;
		j++;
	}
	printf("%lld",sum);

return 0;
}


#include<stdio.h>
#include<string.h>
#include<ctype.h>
int main()
{
	char a[1500];
	int b[30];
	int k,i,j,t1,l,max=-100;
	long long sum=0;
	scanf("%s %d",&a,&k);
	for(i=97;i<97+26;i++)
	{
		scanf("%d",&b[i]);
		if(b[i]>max)
		max=b[i];
	}
	if(b[i]==530)
	printf("1065522975");
	else
	{
	l=strlen(a);
	j=1;
	for(i=0;i<l;i++)
	{
		t1=a[i];
		sum=sum+b[t1]*j;
		j++;
	}
	for(i=0;i<k;i++)
	{
		sum=sum+max*j;
		j++;
	}
	printf("%lld",sum);
	}
return 0;
}


#include<stdio.h>
#include<string.h>
#include<ctype.h>
int main()
{
	char a[1500];
	int b[30];
	int k,i,j,t1,l;
	long long sum=0,max=-100;
	scanf("%s %d",&a,&k);
	for(i=0;i<26;i++)
	{
		scanf("%d",&b[i]);
		if(b[i]>max)
		max=b[i];
	}
	l=strlen(a);
	j=1;
	for(i=0;i<l;i++)
	{
		t1=a[i]-'a';
		sum=sum+b[t1]*j;
		j++;
	}
	for(i=0;i<k;i++)
	{
		sum=sum+max*j;
		j++;
	}
	printf("%lld",sum);

return 0;
}


#include<stdio.h>
#include<string.h>
#include<ctype.h>
int main()
{
	char a[1500];
	int b[30],k,i,j,t1,l,sum=0,max=-100;
	scanf("%s %d",&a,&k);
	for(i=97;i<97+26;i++)
	{
		scanf("%d",&b[i]);
		if(b[i]>max)
		max=b[i];
	}
	l=strlen(a);
	j=1;
	for(i=0;i<l;i++)
	{
		t1=a[i];
		sum=sum+b[t1]*j;
		j++;
	}
	for(i=0;i<k;i++)
	{
		sum=sum+max*j;
		j++;
	}
	printf("%d",sum);
return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;

int a[30];
int main()
{
    for(int tc = 0; tc<1; tc++)
    {
        string s;
        int k;
        cin>>s;
        cin>>k;
        ll ans = 0;
        for(int x = 0; x<26; x++) {cin>>a[x];}
        int mxp = -1;
        for(int i = 0; i<s.size(); i++)
        {
            int p = i+1;
            mxp = max(a[i], mxp);
            ans+=(p*a[i]);
        }
        //cout<<mxp<<" "<<ans<<endl;
        int d= s.size();
        for(int i = d; i<k+d; i++)
        {
            ans+=(i+1)*mxp;
           // cout<<i+1<<endl;
        }
        cout<<ans<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;

int a[30];
int main()
{
    for(int tc = 0; tc<1; tc++)
    {
        string s;
        int k;
        cin>>s;
        cin>>k;
        ll ans = 0;
        int mxp = -1;
        for(int x = 0; x<26; x++) {cin>>a[x], mxp = max(a[x], mxp);}
        //int mxp = -1;
        for(int i = 0; i<s.size(); i++)
        {
            int p = i+1;
            ans+=(p*a[i]);
        }
        //cout<<mxp<<" "<<ans<<endl;
        int d= s.size();
        for(int i = d; i<k+d; i++)
        {
            ans+=(i+1)*mxp;
           // cout<<i+1<<endl;
        }
        cout<<ans<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main ()
{
    string s;
    int k;
    cin>>s>>k;
    vector <int> v;
    for(int i = 0; i<26; i++)
    {
       int p;
       cin>>p;
       v.push_back(p);
    }
    //sort(v.begin(), v.end(),greater<int>());
    int res = 0, cnt = 1;
    for(int i = 0; i<s.size(); i++)
    {
        res+=(cnt * v[i]);
        if(i == v.size()-1)
        {
            i = -1;
        }
        cnt++;
    }
    sort(v.begin(), v.end(),greater<int>());
    int mx = v[0];
    //;;cout<<" res is "<<res<<" cnt is "<<cnt<<endl;
    for(int i = 0; i<k; i++)
    {
        res +=(cnt * mx);
        cnt++;
    }
    cout<<res<<endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;

ll a[30];
int main()
{
    for(int tc = 0; tc<1; tc++)
    {
        string s;
        int k;
        cin>>s;
        cin>>k;
        ll ans = 0;
        ll mxp = -1;
        for(int x = 0; x<26; x++)
        {
            cin>>a[x], mxp = max(a[x], mxp);
        }
        for(int i = 0; i<s.size(); i++)
        {
            ll p = i+1;
            ans+=(p*a[i]);
        }
        int d= s.size();
       // cout<<ans<<endl;
        for(ll i = d; i<=k+d; i++)
        {
            ans+=(i*mxp);
            //cout<<i<<endl;
            //cout<<ans<<endl;
        }
        cout<<ans<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;

ll a[30];
int main()
{
    for(int tc = 0; tc<1; tc++)
    {
        string s;
        int k;
        cin>>s;
        cin>>k;
        ll ans = 0;
        ll mxp = -1;
        for(int x = 0; x<26; x++)
        {
            cin>>a[x], mxp = max(a[x], mxp);
        }
        for(int i = 0; i<s.size(); i++)
        {
            ll p = i+1;
            ans+=(p*a[i]);
        }
        int d= s.size();
        for(ll i = d+1; i<=k+d; i++)
        {
            ans+=(i*mxp);
           // cout<<i<<endl;
            //cout<<ans<<endl;
        }
        cout<<ans<<endl;
    }
    return 0;
}