#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 100000;
const int MOD = 1000000007;
char s[MAX_N + 4];
int powmod(int a, int n) {
  int pm = 1;
  while (n > 0) {
    if (n & 1) pm = (long long)pm * a % MOD;
    a = (long long)a * a % MOD;
    n >>= 1;
  }
  return pm;
}
int main() {
  int k;
  scanf("%s%d", s, &k);
  int n = strlen(s);
  int asum = 0, e = 1;
  for (int i = 0; i < n; i++) {
    if (s[i] == '0' || s[i] == '5') asum = (asum + e) % MOD;
    e = e * 2 % MOD;
  }
  int ans = (long long)(powmod(e, k) + (MOD - 1)) % MOD *
            powmod((e + (MOD - 1)) % MOD, MOD - 2) % MOD * asum % MOD;
  printf("%d\n", ans);
  return 0;
}
