#include <bits/stdc++.h>
using namespace std;
const int inf = INT_MAX / 2;
const int Maxn = 4005;
const long long Mod = 1000000007;
string s;
long long k, p;
long long opt_pow_n(long long x, unsigned int n) {
  long long pw = 1;
  while (n > 0) {
    if (n & 1) pw = pw * x % Mod;
    x = x * x % Mod;
    n = n >> 1;
  }
  return pw;
}
long long go(long long n) {
  if (n == 1) return 1;
  long long tmp = go(n / 2);
  if (n & 1) {
    return ((tmp + opt_pow_n(p, n / 2) * tmp % Mod) % Mod +
            opt_pow_n(p, n - 1)) %
           Mod;
  } else {
    return (tmp + opt_pow_n(p, n / 2) * tmp % Mod) % Mod;
  }
}
long long solve() {
  long long ans = 0, n = s.length();
  p = opt_pow_n(2, n);
  long long base = go(k);
  for (int(i) = (0); (i) <= (n - 1); ++(i))
    if (s[i] == '5' || s[i] == '0') {
      long long a0 = opt_pow_n(2, i);
      ans = (ans + a0 * base % Mod) % Mod;
    }
  return ans;
}
int main() {
  iostream::sync_with_stdio(false);
  cin >> s >> k;
  cout << solve() << endl;
  return 0;
}
