#include <bits/stdc++.h>
long long expmod(long long a, long long b);
long long inv(long long n, long long x);
long long fast(long long a, long long b);
using namespace std;
int main() {
  long long i, j, k, l, m, n, e, f, d, ans, a[100009];
  string s;
  cin >> s;
  cin >> k;
  a[0] = 1;
  d = 0;
  for (i = 1; i < 100005; i++) a[i] = (a[i - 1] * 2) % 1000000007;
  for (i = 0; i < s.length(); i++) {
    if (s[i] == '5' || s[i] == '0') {
      d = d + a[i];
      d %= 1000000007;
    }
  }
  e = inv(a[s.length()] - 1, 1000000007);
  e = e % 1000000007;
  if (e < 0) e = e + 1000000007;
  f = fast(a[s.length()], k);
  f = f % 1000000007;
  f = f - 1;
  if (f < 0) f = f + 1000000007;
  if (k == 1)
    ans = d;
  else
    ans = (((e * f) % 1000000007) * d) % 1000000007;
  cout << ans;
}
long long expmod(long long a, long long b) {
  long long x = 1, y = a, w = b + 2;
  while (b > 0) {
    if (b & 1) x = (x * y) % (w);
    y = (y * y) % (w);
    b >>= 1;
  }
  return x;
}
long long inv(long long n, long long x) { return expmod(n, x - 2); }
long long fast(long long a, long long b) {
  long long d;
  if (b == 0)
    return 1;
  else if (b == 1)
    return a;
  else if (b % 2 == 0) {
    d = fast(a, b / 2);
    return (d * d) % 1000000007;
  } else {
    d = fast(a, b / 2);
    return (a * ((d * d) % 1000000007)) % 1000000007;
  }
}
