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