#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int maxn = 1e5 + 5;
long long qpow(long long a, long long b, long long r) {
  long long ans = 1, buff = a % r;
  while (b) {
    if (b & 1) ans = (ans * buff) % r;
    buff = (buff * buff) % r;
    b >>= 1;
  }
  return ans;
}
long long f_inv(long long a, long long p) { return qpow(a, p - 2, p); }
string s;
long long k, ans = 0;
int main() {
  ios::sync_with_stdio(false);
  cin >> s >> k;
  if (s[0] == '-' || s[0] == '+') s.erase(s.begin());
  long long len = s.length();
  for (long long i = 0; i < len; i++) {
    if (s[i] == '0' || s[i] == '5') {
      ans += qpow(2, i, mod);
      ans %= mod;
    }
  }
  long long x = qpow(2, len, mod);
  long long y = qpow(x, k, mod);
  x--, y--;
  ans = ans * (y * f_inv(x, mod) % mod) % mod;
  cout << ans << endl;
  return 0;
}
