#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
string s;
long long k, n;
long long ans = 0;
long long pw(long long a, long long b) {
  long long ret = 1;
  while (b) {
    if (b & 1) ret = (ret * a) % MOD;
    b >>= 1;
    a = (a * a) % MOD;
  }
  return ret;
}
long long get(long long ind) {
  long long ret = pw(2, ind);
  long long a = (pw(2, k * n) + MOD - 1) % MOD;
  long long b = (pw(2, n) + MOD - 1) % MOD;
  a = (a * pw(b, MOD - 2)) % MOD;
  return (ret * a) % MOD;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> s >> k;
  n = s.size();
  for (int i = 0; i < n; i++) {
    if (s[i] != '5' && s[i] != '0') continue;
    if (k == 1)
      ans = (ans + pw(2, i)) % MOD;
    else
      ans = (ans + get(i)) % MOD;
  }
  cout << ans << endl;
  return 0;
}
