#include <bits/stdc++.h>
int k, n;
char s[100002];
int lgput(int a, int n) {
  int p = 1;
  while (n) {
    if (n & 1) p = (long long)p * a % 1000000007;
    a = (long long)a * a % 1000000007;
    n >>= 1;
  }
  return p;
}
int main() {
  gets(s);
  scanf("%d", &k);
  n = strlen(s);
  long long ans = 0;
  for (int i = 0; i < n; ++i)
    if (s[i] == '0' || s[i] == '5')
      ans = (long long)(ans + lgput(2, i)) % 1000000007;
  int ratie = lgput(2, n);
  int numarator = lgput(ratie, k) - 1;
  int numitor = ratie - 1;
  int mul = lgput(numitor, 1000000007 - 2);
  mul = (long long)mul * numarator % 1000000007;
  ans = (long long)ans * mul % 1000000007;
  printf("%I64d", ans);
}
