#include <bits/stdc++.h>
using namespace std;
char a[100010];
long long k, n;
long long modulo(long long a, long long b) {
  if (a >= 0) return a % b;
  long long c = a / b * -1;
  a += b * (c + 1);
  return a;
}
long long get_inverse(long long a, long long b) {
  long long mod = a;
  long long r, q, y;
  long long y2 = 0, y1 = 1;
  while (a != 1) {
    r = a % b;
    q = a / b;
    y = y2 - q * y1;
    a = b;
    b = r;
    y2 = y1;
    y1 = y;
  }
  return modulo(y2, mod);
}
long long modPow(long long a, long long n) {
  if (n == 0) return 1;
  long long ans = modPow(a, n / 2);
  ans = (ans * ans) % 1000000007;
  if (n & 1) ans = (ans * a) % 1000000007;
  return ans;
}
long long getS(long long i, long long n, long long k) {
  long long ret = modPow(2, i);
  long long atas = modPow(2, k * n) - 1;
  if (atas < 0) atas += 1000000007;
  long long bawah = modPow(2, n) - 1;
  if (bawah < 0) bawah += 1000000007;
  bawah = get_inverse(1000000007, bawah);
  atas = (atas * bawah) % 1000000007;
  return (ret * atas) % 1000000007;
}
int main() {
  scanf("%s", a);
  scanf("%I64d ", &k);
  long long ans = 0;
  n = strlen(a);
  for (int i = 0; i < (int)(n); i++) {
    if (a[i] == '0' || a[i] == '5') {
      ans = (ans + getS(i, n, k)) % 1000000007;
    }
  }
  cout << ans << endl;
}
