#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
int ax;
string s;
long long n;
int pwr(long long a, int b) {
  if (b == 0) return 1;
  if (b == 1) return a;
  long long res = 1;
  while (b != 0) {
    if (b & 1 == 1) res = (res * a) % MOD;
    a *= a;
    if (a > MOD) a %= MOD;
    b >>= 1;
  }
  return res;
}
int mult(long long a, int b, int c) {
  long long d = a * b;
  if (d > MOD) d %= MOD;
  long long e = d * c;
  if (e > MOD) e %= MOD;
  return e;
}
int val(long long a, long long r) { return mult(a, (pwr(r, n) - 1), ax); }
int main() {
  cin >> s >> n;
  vector<long long> v;
  long long ans = 0;
  int cmr = pwr(2, s.length());
  ax = pwr(cmr - 1, MOD - 2);
  for (int i = 0; i < s.length(); i++) {
    if (s[i] == '0' || s[i] == '5') {
      v.push_back(i);
      ans += val(pwr(2, i), cmr);
    }
  }
  cout << ans % MOD << endl;
}
