#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
void fio() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
}
const int mod = 1000000007;
ll mul(ll a, ll b) {
return (((a % mod) * (b % mod)) % mod);
}
ll fast_power(ll base, ll exponent) {
if (exponent == 0) return 1;
ll half_power = fast_power(base, exponent / 2);
ll full_power = mul(half_power, half_power);
if (exponent % 2 != 0) {
full_power = mul(full_power, base);
}
return full_power;
}
ll mod_inverse(ll b) {
return fast_power(b, mod - 2);
}
ll add(ll a, ll b) {
return (((a % mod) + (b % mod)) % mod);
}
int main() {
fio();
string a;
cin >> a;
int k;
cin >> k;
int n = a.length();
ll ans = 0;
for (int i = 0; i < n; i++) {
if (a[i] == '0' || a[i] == '5') {
ll ways = fast_power(2, i);
if (k == 1) {
ans = add(ans, ways);
} else {
ll numerator = mul(ways, fast_power(2, (k-1) * n));
ll sum_series = 0;
// (1 + 2^n + 2^2n + ... + 2^((k-1)n))
ll geo_sum = (fast_power(2, k * n) - 1 + mod) % mod;
ll divisor = (fast_power(2, n) - 1 + mod) % mod;
sum_series = mul(geo_sum, mod_inverse(divisor));
ans = add(ans, mul(ways, sum_series));
}
}
}
cout << ans << endl;
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+Cgp1c2luZyBuYW1lc3BhY2Ugc3RkOwp1c2luZyBsbCA9IGxvbmcgbG9uZzsKdXNpbmcgbGQgPSBsb25nIGRvdWJsZTsKCnZvaWQgZmlvKCkgewogICAgaW9zX2Jhc2U6OnN5bmNfd2l0aF9zdGRpbyhmYWxzZSk7CiAgICBjaW4udGllKG51bGxwdHIpOwogICAgY291dC50aWUobnVsbHB0cik7Cn0KCmNvbnN0IGludCBtb2QgPSAxMDAwMDAwMDA3OwoKbGwgbXVsKGxsIGEsIGxsIGIpIHsKICAgIHJldHVybiAoKChhICUgbW9kKSAqIChiICUgbW9kKSkgJSBtb2QpOwp9CgpsbCBmYXN0X3Bvd2Vy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EgKyAyXm4gKyAyXjJuICsgLi4uICsgMl4oKGstMSluKSkKICAgICAgICAgICAgICAgIGxsIGdlb19zdW0gPSAoZmFzdF9wb3dlcigyLCBrICogbikgLSAxICsgbW9kKSAlIG1vZDsKICAgICAgICAgICAgICAgIGxsIGRpdmlzb3IgPSAoZmFzdF9wb3dlcigyLCBuKSAtIDEgKyBtb2QpICUgbW9kOwogICAgICAgICAgICAgICAgc3VtX3NlcmllcyA9IG11bChnZW9fc3VtLCBtb2RfaW52ZXJzZShkaXZpc29yKSk7CgogICAgICAgICAgICAgICAgYW5zID0gYWRkKGFucywgbXVsKHdheXMsIHN1bV9zZXJpZXMpKTsKICAgICAgICAgICAgfQogICAgICAgIH0KICAgIH0KCiAgICBjb3V0IDw8IGFucyA8PCBlbmRsOwogICAgcmV0dXJuIDA7Cn0=