#include <bits/stdc++.h>
#pragma GCC optimize("-O2")
using namespace std;
const int N = 2e5 + 5;
const long double EPS = 1e-9;
long long MOD = 1e9 + 7;
long long fastpowMOD(long long a, long long p, long long MOD = 1e9 + 7) {
  if (p == 0) return 1;
  long long z = fastpowMOD(a, p / 2, MOD);
  z = (z * z) % MOD;
  if (p % 2) z = (z * a) % MOD;
  return z;
}
long long modInverse(long long a, long long m = MOD) {
  long long m0 = m;
  long long y = 0, x = 1;
  if (m == 1) return 0;
  while (a > 1) {
    long long q = a / m;
    long long t = m;
    m = a % m, a = t;
    t = y;
    y = x - q * y;
    x = t;
  }
  if (x < 0) x += m0;
  return x;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  string s;
  cin >> s;
  long long i, n = s.length(), k;
  cin >> k;
  long long x = n * k;
  long long ans = (fastpowMOD(2, x) - 1 + MOD) % MOD;
  ans *= modInverse((fastpowMOD(2, n) - 1 + MOD) % MOD);
  ans %= MOD;
  long long sum = 0;
  vector<long long> ind;
  for (i = 0; i < n; i++)
    if (s[i] == '0' or s[i] == '5') ind.push_back(i);
  for (i = 0; i < ind.size(); i++) {
    sum += fastpowMOD(2, ind[i]);
    sum %= MOD;
  }
  ans *= sum;
  ans %= MOD;
  cout << ans;
  return 0;
}
