#include <bits/stdc++.h>
using namespace std;
int MOD = (int)1e+9 + 7;
long long fpow(long long b, long long exp, int M) {
  long long res = 1;
  long long base = b;
  for (long long ex = exp; ex; ex >>= 1) {
    if (ex & 1) res = (res % M * base % M) % M;
    base = (base % M * base % M) % M;
  }
  return res;
}
long long m_inverse(long long q, int M) { return fpow(q, M - 2, M) % M; }
int main() {
  long long K;
  string a;
  cin >> a;
  cin >> K;
  int N = a.size();
  long long res = 0;
  long long use = (fpow(2, N * K, MOD) + MOD - 1) % MOD;
  long long dow = m_inverse((fpow(2, N, MOD) + MOD - 1) % MOD, MOD);
  long long q = (use % MOD * dow % MOD) % MOD;
  for (int i = 0; i < N; i++) {
    if (a[i] == '0' or a[i] == '5') {
      long long pos = (long long)i;
      res += (fpow(2, pos, MOD) % MOD * q % MOD) % MOD;
      res %= MOD;
    }
  }
  cout << res << endl;
}
