#include <bits/stdc++.h>
using namespace std;
const int nmax = 200001;
const int mod = 1000000007;
int n, k;
string s;
long long binpow(long long a, long long b, long long mod) {
  long long res = 1;
  while (b) {
    if (b % 2) res *= a;
    a *= a;
    res %= mod;
    a %= mod;
    b /= 2;
  }
  return res;
}
long long f(long long n, long long k) {
  if (k == 0) return 0;
  if (k % 2 == 0) {
    long long x = f(n, k / 2);
    return (x + x * binpow(2, n * k / 2, mod)) % mod;
  } else
    return (binpow(2, k * n, mod) + f(n, k - 1)) % mod;
}
int main() {
  ios::sync_with_stdio(0);
  cin >> s >> k;
  int n = s.size();
  long long ans = 0;
  long long sv = (1 + f(n, k - 1));
  for (int i = 0; i < n; i++) {
    if (s[i] != '5' && s[i] != '0') continue;
    ans = (ans + binpow(2, i, mod) * sv) % mod;
  }
  ans = (ans + mod) % mod;
  cout << ans << endl;
  return 0;
}
