#include <bits/stdc++.h>
using namespace std;
long long modExp(long long x, long long y, long long m) {
  long long r = 1LL;
  while (y) {
    if (y & 1) r = (1LL * r * x) % m;
    x = (1LL * x * x) % m;
    y >>= 1;
  }
  return r % m;
}
long long two[100005];
int main() {
  two[0] = 1;
  for (int i = (int)1; i < (int)100005; i++)
    two[i] = (1LL * 2 * two[i - 1]) % 1000000007;
  string s;
  long long k;
  while (cin >> s) {
    cin >> k;
    long long res = 0LL;
    long long len = 1LL * s.size();
    long long r = modExp(2LL, len, 1000000007);
    long long rn = modExp(r, k, 1000000007);
    rn--;
    if (rn < 0) rn += 1000000007;
    long long inv = modExp(r - 1LL, 1000000007 - two[1], 1000000007);
    for (int i = (int)0; i < (int)s.size(); i++) {
      if (s[i] == '0' || s[i] == '5') {
        long long a1 = two[i];
        long long sum = (1LL * a1 * rn) % 1000000007;
        sum = (1LL * sum * inv) % 1000000007;
        res = (res + sum) % 1000000007;
      }
    }
    cout << res << endl;
  }
  return 0;
}
