#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
char shu[600010];
long long make(long long x, long long b) {
  long long ans = 1;
  while (b) {
    if (b % 2 == 1) ans = ans * x % 1000000007;
    x = x % 1000000007 * x % 1000000007;
    b /= 2;
  }
  return ans;
}
long long dp[70];
long long play(long long x, long long b, long long n, long long cs) {
  if (n == 1) return x;
  if (dp[cs] != 0) return dp[cs];
  long long tp = 0;
  tp += play(x, b, n / 2, cs + 1) % 1000000007 * make(b, n / 2) % 1000000007;
  tp += play(x, b, n / 2, cs + 1) % 1000000007;
  tp %= 1000000007;
  if (n % 2 == 1) {
    tp += x * make(b, n - 1) % 1000000007;
  }
  tp %= 1000000007;
  return dp[cs] = tp;
}
int main() {
  long long k;
  long long ans = 0, tp, b;
  while (~scanf("%s", shu)) {
    ans = 0;
    scanf("%I64d", &k);
    int l = strlen(shu);
    if (k == 0) {
      puts("0");
      continue;
    }
    tp = 1;
    for (int i = 0; i < l; i++) {
      if (shu[i] == '0' || shu[i] == '5') {
        ans += tp;
        ans %= 1000000007;
      }
      tp *= 2;
      tp %= 1000000007;
    }
    long long s1 = make(tp, k) - 1;
    long long s2 = make(tp - 1, 1000000007 - 2);
    printf("%I64d\n", s1 * s2 % 1000000007 * ans % 1000000007);
  }
  return 0;
}
