#include <bits/stdc++.h>
const long long N = 1e9 + 7;
long long qpow(long long a, long long b, long long mod) {
  long long sum = 1;
  while (b) {
    if (b & 1) {
      sum = sum * a % mod;
    }
    a = a * a % mod;
    b >>= 1;
  }
  return sum;
}
void exgcd(long long a, long long b, long long &x, long long &y) {
  if (b == 0) {
    x = 1;
    y = 0;
    return;
  }
  exgcd(b, a % b, x, y);
  long long t = x;
  x = y;
  y = t - a / b * y;
}
int main() {
  int n, i, mm;
  char m[1000005];
  long long a, b, q, s, r, sum;
  while (~scanf("%s", m)) {
    scanf("%d", &n);
    mm = strlen(m);
    sum = 0;
    q = qpow(2, mm, N);
    s = qpow(q, n, N) - 1;
    for (i = 0; i < mm; i++) {
      if (m[i] == '0' || m[i] == '5') {
        r = qpow(2, i, N);
        r *= s;
        r %= N;
        long long x, y;
        exgcd(q - 1, N, x, y);
        r *= x;
        r = (r % N + N) % N;
        sum += r;
        sum %= N;
      }
    }
    printf("%I64d\n", sum);
  }
  return 0;
}
