#include <bits/stdc++.h>
const int INF = 1e18;
using namespace std;
const int maxn = 2e5 + 5;
const int ma = 1e9 + 5;
long long int power(long long int base, long long int exp) {
  long long int res = 1;
  while (exp) {
    if (exp & 1) res = (res * base) % 1000000007;
    base = (base * base) % 1000000007;
    exp >>= 1;
  }
  return res;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  long long int ans = 0, k, i;
  string a;
  cin >> a;
  cin >> k;
  long long int n = a.length();
  long long int temp1 = power(2, n * k) - 1;
  long long int temp2 = power(2, n) - 1;
  temp2 = power(temp2, 1000000007 - 2);
  for (i = 0; i < n; i++) {
    if ((a[i] - '0') % 5 == 0)
      ans =
          (ans + (((power(2, i) * temp1) % 1000000007) * (temp2) % 1000000007) %
                     1000000007) %
          1000000007;
  }
  cout << ans << endl;
  return 0;
}
