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