#include <bits/stdc++.h>
using namespace std;
char a[1000005];
int n, k;
long long lpow(long long x, long long y) {
  long long ret = 1;
  while (y) {
    if (y & 1) ret = (ret * x) % 1000000007ll;
    x = (x * x) % 1000000007ll, y >>= 1;
  }
  return ret;
}
int main() {
  scanf("%s%d", a, &k);
  n = strlen(a);
  long long ans = 0;
  for (int i = 0; i < n; ++i)
    if (a[i] == '0' || a[i] == '5') {
      ans = (ans + lpow(2, i)) % 1000000007ll;
    }
  long long t = lpow(2, n);
  long long mul =
      (lpow(t, k) - 1 + 1000000007ll) % 1000000007ll *
      lpow((t - 1 + 1000000007ll) % 1000000007ll, 1000000007ll - 2) %
      1000000007ll;
  printf("%d", int(ans * mul % 1000000007ll));
}
