#include <bits/stdc++.h>
using namespace std;
const long long p = 1000000007;
char s[100001];
long long C(long long x, long long n) {
  long long ans = 1;
  while (n) {
    if (n & 1) ans = ans * x % p;
    n >>= 1;
    x = x * x % p;
  }
  return ans;
}
int main() {
  long long k, l;
  cin >> s >> k;
  l = strlen(s);
  long long ans = 0, t1, t2;
  for (int i = 0; i < l; i++) {
    if (s[i] == '0' || s[i] == '5') {
      ans = (ans + C(2, i)) % p;
    }
  }
  t1 = C((C(2, l) - 1), p - 2);
  t2 = (t1 * (C(2, k * l) - 1)) % p;
  ans = (ans * t2) % p;
  cout << ans;
  return 0;
}
