#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007LL;
long long powmod(long long b, long long e, long long m) {
  if (!e) return 1;
  long long r = powmod(b, e / 2, m);
  return ((r * r) % m * ((e & 1) ? b : 1)) % m;
}
string s;
long long k;
int main() {
  cin >> s >> k;
  long long cum = 0;
  for (int i = s.size() - 1; i >= 0; i--) {
    if (s[i] == '5' || s[i] == '0') cum += powmod(2, i, mod);
    if (cum >= mod) cum -= mod;
  }
  long long len = s.size();
  long long num = powmod(2, len * k, mod);
  num = (num - 1 + mod) % mod;
  long long den = (powmod(2, s.size(), mod) - 1 + mod) % mod;
  long long show = (num * powmod(den, mod - 2, mod)) % mod;
  long long opa = (cum * show) % mod;
  cout << opa << endl;
  return 0;
}
