#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:167177216")
long long mod = 1000 * 1000 * 1000 + 7;
long long binpow(long long a, long long b) {
  if (b == 0) return 1;
  if (b % 2 == 1) return (a * binpow(a, b - 1)) % mod;
  long long bb = binpow(a, b / 2);
  return (bb * bb) % mod;
}
int main() {
  long long a[111111];
  a[0] = 1;
  a[1] = 2;
  for (int i = 2; i <= 100000; i++) a[i] = (a[i - 1] * 2) % mod;
  string s;
  getline(cin, s);
  long long k;
  cin >> k;
  int len = s.length();
  long long ans = 0;
  long long all = binpow(2, len);
  long long obr = binpow(all - 1, mod - 2);
  for (int i = 0; i < s.length(); i++)
    if (s[i] == '0' || s[i] == '5') {
      ans = (ans + (a[i] * (binpow(all, k) - 1) % mod) * obr) % mod;
    }
  cout << ans << endl;
  return 0;
}
