#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000000 + 7;
const double eps = 1e-8;
const int maxn = 300000;
long long Pow(long long x, long long y, long long c) {
  if (y == 0) return 1;
  long long ans = Pow(x, y / 2, c);
  ans = ans * ans % c;
  if (y % 2) ans = ans * x % c;
  return ans;
}
char str[maxn];
int main() {
  while (scanf("%s", str) == 1) {
    int re;
    scanf("%d", &re);
    long long ans = 0;
    int len = strlen(str);
    int cnt = 0;
    for (int i = (0); i < (len); ++i) {
      if (str[i] == '0' || str[i] == '5') {
        long long b = (Pow(2, len, INF) - 1);
        b = Pow(b, INF - 2, INF);
        ans = (ans + b *
                         (Pow(2, cnt, INF) *
                          (Pow(2, (long long)len * re, INF) - 1) % INF) %
                         INF) %
              INF;
      }
      cnt++;
    }
    cout << ans << endl;
  }
  return 0;
}
