#include <bits/stdc++.h>
long long k, i, p, sum, l, ans;
char s[100005];
long long power(long long a, long long b) {
  long long x = 1, y = a;
  while (b > 0) {
    if (b % 2 == 1) {
      x = (x * y);
      if (x > 1000000007) x %= 1000000007;
    }
    y = (y * y);
    if (y > 1000000007) y %= 1000000007;
    b /= 2;
  }
  return x;
}
int main() {
  long long a, b, c, d;
  scanf("%s %lld", &s, &k);
  l = strlen(s);
  sum = 0;
  for (i = 0; i < l; i++) {
    p = (int)s[i] - 48;
    if (p == 5 || p == 0) sum = (sum + power(2, i)) % 1000000007;
  }
  a = power(2, l * k);
  a = a - 1;
  if (a < 0) a = a + 1000000007;
  b = power(2, l);
  b = b - 1;
  if (b < 0) b = b + 1000000007;
  c = power(b, 1000000007 - 2);
  d = (a % 1000000007 * c % 1000000007) % 1000000007;
  ans = (sum * d) % 1000000007;
  printf("%lld\n", ans);
  return 0;
}
