#include <bits/stdc++.h>
using namespace std;
long long expo(long long p, long long q) {
  long long r = 1;
  while (q != 0) {
    if (q % 2 == 1) {
      r = (r % 1000000007 * p % 1000000007) % 1000000007;
      q--;
    }
    p = (p % 1000000007 * p % 1000000007) % 1000000007;
    q /= 2;
  }
  return r % 1000000007;
}
long long inv(long long x) { return expo(x, 1000000007 - 2); }
int main(int argc, char const *argv[]) {
  string a;
  int k;
  cin >> a;
  cin >> k;
  long long arr[100001];
  arr[0] = 1;
  for (int i = 1; i < 100001; ++i) {
    arr[i] = (arr[i - 1] * 2) % 1000000007;
  }
  long long ans = 0;
  int ex;
  ex = a.length();
  for (int i = 0; i < a.length(); ++i) {
    if ((a[i] - '0') % 5 == 0) {
      ans = (ans +
             (expo(arr[ex], k) - 1) * inv(arr[ex] - 1) % 1000000007 * arr[i]) %
            1000000007;
    }
  }
  cout << ans << endl;
  return 0;
}
