#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long bigmod(long long p, long long e, long long M) {
  if (e == 0) return 1;
  if (e % 2 == 0) {
    long long t = bigmod(p, e / 2, M);
    return (t * t) % M;
  }
  return (bigmod(p, e - 1, M) * p) % M;
}
long long modinverse(long long a, long long M) { return bigmod(a, M - 2, M); }
bool is_prime[1000001];
long prime[1000001];
bool sieve() {
  long i, j;
  prime[0] = 2;
  int k = 1;
  int sq = (sqrt(1000001));
  for (i = 3; i <= sq; i += 2) {
    if (!is_prime[i]) {
      for (j = i * i; j <= 1000001; j += (2 * i)) is_prime[j] = 1;
    }
  }
  for (j = 3; j <= 1000001; j += 2) {
    if (!is_prime[j]) {
      prime[k++] = j;
    }
  }
}
long NOD(long n) {
  int i, j, k;
  long sq = sqrt(n);
  long res = 1;
  for (i = 0; prime[i] <= sq; i++) {
    int cnt = 1;
    if (n % prime[i] == 0) {
      while (n % prime[i] == 0) {
        cnt++;
        n = n / prime[i];
        if (n == 1) break;
      }
      res *= cnt;
      sq = sqrt(n);
    }
  }
  if (n > 1) res *= 2;
  return res;
}
int main() {
  long long i, j, k;
  long long n;
  string num;
  cin >> num;
  cin >> k;
  long long l = num.length();
  long long res = 0;
  long long up = (bigmod(2ll, k * l, 1000000007) % 1000000007 - 1) % 1000000007;
  long long dn = (bigmod(2ll, l, 1000000007) % 1000000007 - 1) % 1000000007;
  long long common =
      ((up % 1000000007) * modinverse(dn, 1000000007) % 1000000007) %
      1000000007;
  for (i = 0; i < l; i++) {
    int cn = num[i] - '0';
    if (cn % 5 == 0) {
      res = ((((bigmod(2ll, i, 1000000007) % 1000000007) % 1000000007) *
              (common % 1000000007)) %
                 1000000007 +
             res) %
            1000000007;
    }
  }
  cout << res << endl;
  return 0;
}
