#include <bits/stdc++.h>
using namespace std;
long long fast(long long a, long long b) {
  if (b == 0)
    return 1;
  else if (b == 1)
    return a;
  else {
    long long tmp = fast(a, b / 2) % 1000000007;
    if (b % 2 == 0)
      return tmp * tmp % 1000000007;
    else
      return tmp * tmp % 1000000007 * a % 1000000007;
  }
}
int main() {
  string s;
  cin >> s;
  long long k;
  cin >> k;
  vector<int> tmp;
  for (int(i) = (s.length() - 1); (i) >= (0); (i)--) {
    if (s[i] == '0' || s[i] == '5') {
      tmp.push_back(i);
    }
  }
  long long ans = 0;
  for (int(i) = 0; (i) < (tmp.size()); (i)++) {
    long long tem = tmp[i];
    long long mx = tmp[i] + (k)*s.length();
    long long tem2 = fast(2, s.length()) - 1;
    ans += ((fast(2, mx) - fast(2, tem)) * fast(tem2, 1000000007 - 2));
    ans %= 1000000007;
  }
  cout << ans << endl;
}
