#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
long long quickpow(long long a, long long x) {
  long long ret = 1;
  for (; x; x >>= 1) {
    if (x & 1) ret = (ret * a) % mod;
    a = (a * a) % mod;
  }
  return ret;
}
int main(int argc, char const *argv[]) {
  string s;
  int k;
  cin >> s;
  cin >> k;
  int n = s.size();
  long long ret = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] == '5' || s[i] == '0') {
      ret = ret + quickpow(2LL, (long long)i);
      ret %= mod;
    }
  }
  long long pow2n = quickpow(2LL, (long long)n);
  ret =
      ret * (quickpow(pow2n, k) - 1) % mod * quickpow(pow2n - 1, mod - 2) % mod;
  cout << ret << endl;
  return 0;
}
