#include <bits/stdc++.h>
using namespace std;
const int PT = 1e9 + 7;
const int N = 1e5 + 10;
char s[N];
long long FP(long long a, long long n) {
  int res = 1;
  while (n) {
    if (n & 1) res = (res * a) % PT;
    a = a * a % PT;
    n >>= 1;
  }
  return res;
}
int main() {
  int sum, k, i, flag = 0, cnt = 0, len;
  scanf("%s", s);
  len = strlen(s);
  scanf("%d", &k);
  long long q = FP(2, len);
  long long a = (1LL + PT - FP(q, k));
  long long b = (1LL + PT - q);
  long long t = (a * FP(b, PT - 2LL)) % PT;
  long long ans = 0;
  for (int i = 0; i < len; i++) {
    if (s[i] == '0' || s[i] == '5') {
      long long p = FP(2LL, (long long)i);
      ans = ((ans + (p * t) % PT)) % PT;
    }
  }
  printf("%I64d\n", ans);
  return 0;
}
