#include <bits/stdc++.h>
using namespace std;
int M = 1000000007;
int gcd(int a, int b, int& x, int& y) {
  if (a == 0) {
    x = 0;
    y = 1;
    return b;
  }
  int x1, y1;
  int d = gcd(b % a, a, x1, y1);
  x = y1 - (b / a) * x1;
  y = x1;
  return d;
}
int obr(int a) {
  int x, y;
  int g = gcd(a, M, x, y);
  if (x < 0) {
    x = M - ((-x) % M);
  }
  return x % M;
}
int pow(long long a, int n) {
  long long res = 1;
  while (n)
    if (n & 1) {
      res = (res * a) % M;
      --n;
    } else {
      a = (a * a) % M;
      n >>= 1;
    }
  return res % M;
}
int main() {
  string s;
  int n, k;
  cin >> s;
  n = s.length();
  cin >> k;
  vector<bool> a(n);
  for (int i = 0; i < n; ++i) {
    if (s[i] == '0' || s[i] == '5') {
      a[i] = true;
    } else {
      a[i] = false;
    }
  }
  vector<long long> dv(n + 1);
  dv[0] = 1;
  for (int i = 1; i <= n; ++i) {
    dv[i] = (dv[i - 1] * 2) % M;
  }
  long long ans = 0;
  for (int i = 0; i < n; ++i) {
    if (a[i]) {
      ans = (ans + dv[i]) % M;
    }
  }
  long long gobr = obr(dv[n] - 1);
  long long geom = ((pow(dv[n], k) + M - 1) % M);
  cout << (((geom * gobr) % M) * ans) % M << endl;
  return 0;
}
