#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
string s;
long long k, sz, ans = 0;
long long pw(long long a, long long b) {
  return b ? 1ll * pw(1ll * a * a % MOD, b / 2) * (b & 1 ? a : 1) % MOD : 1;
}
long long ca(long long ind) {
  long long a = (pw(2, k * sz) + MOD - 1) % MOD;
  long long b = (pw(2, sz) + MOD - 1) % MOD;
  long long c = pw(2, ind);
  a = (a * pw(b, MOD - 2)) % MOD;
  return (c * a) % MOD;
}
int main() {
  cin >> s >> k;
  sz = s.size();
  for (int i = 0; i < sz; i++) {
    if (s[i] == '5' || s[i] == '0') {
      if (k == 1)
        ans = (ans + pw(2, i)) % MOD;
      else
        ans = (ans + ca(i)) % MOD;
    }
  }
  return cout << ans << '\n', 0;
}
