#include <bits/stdc++.h>
using namespace std;
char a[100000 + 1];
long long quickpow(long long a, long long k) {
  long long ret = 1;
  for (; k; a = a * a % 1000000007, k >>= 1)
    (k & 1) && (ret = ret * a % 1000000007);
  return ret;
}
int main() {
  int k, l;
  long long tot = 0;
  scanf("%s%d", a, &k);
  l = strlen(a);
  for (int i = -1; ++i < l;
       (a[i] == '0' || a[i] == '5') && (tot += quickpow(2, i)))
    ;
  long long tmp = quickpow(2, l);
  printf("%I64d\n",
         tot % 1000000007 * (1 - quickpow(tmp, k) + 1000000007) % 1000000007 *
             quickpow((1 - tmp + 1000000007), 1000000007 - 2) % 1000000007);
  return 0;
}
