#include <bits/stdc++.h>
using namespace std;
long long Q = 1000000007;
int n, m;
long long power(long long x) {
  long long a = 2, ans = 1;
  while (x) {
    if (x & 1) ans *= a, ans %= Q;
    a *= a, a %= Q, x >>= 1;
  }
  return ans;
}
long long cal(int x) {
  if (x == 1) return 1;
  long long ans;
  if (x % 2 == 0)
    ans = (1 + power((long long)(x >> 1) * n)) % Q * cal(x >> 1) % Q;
  else
    ans = cal(x - 1) + power((long long)(x - 1) * n) % Q;
  return ans;
}
char s[100003];
void work() {
  int i, j, k;
  long long ans = 0;
  scanf("%s", s + 1);
  scanf("%d", &m), n = strlen(s + 1);
  long long p = cal(m);
  for (i = n; i > 0; --i)
    if (s[i] == '5' || s[i] == '0') {
      ans += p * power(i - 1) % Q;
      ans %= Q;
    }
  cout << ans;
}
int main() {
  work();
  return 0;
}
