#include <bits/stdc++.h>
using namespace std;
long long mm = 1000000007;
const int maxn = 100000 + 10;
string s;
int k;
long long ans1 = 0, pow2 = 1;
long long pow(long long first, long long second) {
  if (!second) return 1;
  if (!(second % 2)) return (pow((first * first) % mm, second / 2)) % mm;
  return (pow((first * first) % mm, (second - 1) / 2) * first) % mm;
}
long long cs(long long first) {
  long long ret;
  if (!first) return 1;
  if (first % 2 == 1)
    ret = (cs((first - 1) / 2) * (pow(pow2, (first + 1) / 2) + 1)) % mm;
  else
    ret = (cs(first / 2 - 1) * (pow(pow2, first / 2) + 1) + pow(pow2, first)) %
          mm;
  return ret;
}
int main() {
  cin >> s >> k;
  for (int i = 0; i < s.length(); i++) {
    if (s[i] == '0' || s[i] == '5') ans1 += pow2;
    pow2 *= 2;
    pow2 %= mm;
    ans1 %= mm;
  }
  long long ans = ans1;
  ans *= cs(k - 1);
  ans %= mm;
  cout << ans << endl;
}
