#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
string a;
long long k;
long long mygcd(long long p, long long q, long long &x, long long &y) {
  long long t = p;
  if (q != 0) {
    t = mygcd(q, p % q, y, x);
    y -= (p / q) * x;
  } else {
    x = 1;
    y = 0;
  }
  return t;
}
long long myinv(long long x, long long y) {
  long long p, q, t;
  mygcd(x, y, p, q);
  t = ((long long)y + p % y) % y;
  return t;
}
long long mypow(long long x, long long y) {
  long long t = 1;
  while (y != 0) {
    if (y & 1) t = t * x % MOD;
    x = x * x % MOD;
    y >>= 1;
  }
  return t;
}
int main() {
  cin >> a;
  scanf("%d", &k);
  long long ans = 0, t, p = 1;
  for (int i = 0; i < a.length(); i++) {
    if (a[i] == '0' || a[i] == '5') ans = (ans + p) % MOD;
    p = p * 2 % MOD;
  }
  t = (long long)ans * (mypow(p, k) - 1 + MOD) % MOD * myinv(p - 1, MOD) % MOD;
  printf("%I64d\n", t);
  return 0;
}
