#include <bits/stdc++.h>
using namespace std;
char a[100010];
int c[100010];
const int mod = 1000000007;
long long Pow(long long a, long long b, long long c) {
  long long ans = 1;
  while (b) {
    if (b & 1) ans = ans * a % c;
    b >>= 1;
    a = a * a % c;
  }
  return ans;
}
int main() {
  scanf("%s", a);
  int n = strlen(a), k;
  int cnt0 = count(a, a + n, '0');
  int cnt5 = count(a, a + n, '5');
  int cnt = 0;
  for (int i = 0; i <= n - 1; i++) {
    if (a[i] == '0' || a[i] == '5') {
      c[cnt++] = i;
    }
  }
  scanf("%d", &k);
  long long tmp1 = Pow(2, (long long)n * k, mod);
  tmp1 -= 1;
  if (tmp1 < 0) tmp1 += mod;
  long long tmp2 = Pow(2, n, mod);
  tmp2 -= 1;
  if (tmp2 < mod) tmp2 += mod;
  tmp2 = Pow(tmp2, mod - 2, mod);
  long long ans = 0;
  for (int i = 0; i <= cnt - 1; i++) {
    ans += Pow(2, c[i], mod) * tmp1 % mod * tmp2 % mod;
    if (ans >= mod) ans -= mod;
  }
  printf("%I64d\n", ans);
  return 0;
}
