#include <bits/stdc++.h>
using namespace std;
string a;
long long k, r = 0, m = 1000000007;
long long p(long long a, long long b) {
  long long r = 1, t = a;
  for (long long i = 0; i < 64; i++) {
    if (b & (1LL << i)) r = r * t % m;
    t = t * t % m;
  }
  return r;
}
long long in(long long x) { return p(x, m - 2); }
int main() {
  cin >> a >> k;
  for (long long i = 0; i < a.length(); i++) {
    if (a[i] == '0' || a[i] == '5') {
      r = (r + p(2, i)) % m;
    }
  }
  r = r * (p(p(2, a.length()), k) - 1) % m * (in(p(2, a.length()) - 1)) % m;
  cout << r;
  return 0;
}
