#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const long long N = 1e5 + 10;
long long pw[N];
long long modp(long long a, long long b) {
  if (b == 0) return 1;
  long long u = modp(a, b / 2);
  u = u * u % mod;
  if (b & 1) return a * u % mod;
  return u;
}
signed main() {
  string s;
  cin >> s;
  long long k;
  cin >> k;
  long long n = s.length();
  pw[0] = 1;
  for (long long i = 1; i <= n; i++) pw[i] = pw[i - 1] * 2 % mod;
  long long twon = pw[n];
  long long base;
  if (1) {
    long long dem = twon - 1;
    dem %= mod;
    dem += mod;
    dem %= mod;
    dem = modp(dem, mod - 2);
    long long num = modp(twon, k);
    num--;
    num %= mod;
    num += mod;
    num %= mod;
    base = num * dem % mod;
  }
  long long ans = 0;
  for (long long i = 0; i < n; i++) {
    if (s[i] == '5' or s[i] == '0') {
      ans += pw[i];
      ans %= mod;
    }
  }
  ans *= base;
  ans %= mod;
  cout << ans << "\n";
}
