#include <bits/stdc++.h>
using namespace std;
template <class T>
T gcd(T x, T y) {
  while (T t = x % y) x = y, y = t;
  return y;
}
const double eps = 1e-10;
const double PI = acos(-1.);
const int INF = 1000000000;
const int MOD = 1000000007;
const double E = 2.7182818284590452353602874713527;
bool isdig(char x) { return x >= '0' && x <= '9'; }
bool isup(char x) { return x >= 'A' && x <= 'Z'; }
bool islow(char x) { return x >= 'a' && x <= 'z'; }
bool islet(char x) { return isup(x) || islow(x); }
string S;
int N;
int L;
void get_data() {
  cin >> S >> N;
  L = ((int)(S).size());
}
long long f_pow(long long x, int n) {
  long long r = 1;
  while (n) {
    if (n & 1) r = (r * x) % MOD;
    n >>= 1;
    x = (x * x) % MOD;
  }
  return r;
}
struct Matrix {
  long long v[2][2];
  void ini() {
    v[0][0] = 1;
    v[0][1] = 0;
    v[1][0] = 0;
    v[1][1] = 1;
  }
  void set(int n) {
    v[0][0] = f_pow(2, n);
    v[0][1] = 1;
    v[1][0] = 0;
    v[1][1] = 1;
  }
};
Matrix mul(Matrix a, Matrix b) {
  Matrix r;
  for (int i = 0; i < 2; i++)
    for (int j = 0; j < 2; j++) {
      r.v[i][j] = 0;
      for (int k = 0; k < 2; k++) {
        r.v[i][j] += a.v[i][k] * b.v[k][j];
        r.v[i][j] %= MOD;
      }
    }
  return r;
}
Matrix f_mul(int n, int s) {
  Matrix r, x;
  r.ini();
  x.set(s);
  while (n) {
    if (n & 1) r = mul(r, x);
    n >>= 1;
    x = mul(x, x);
  }
  return r;
}
long long cal(int s) {
  Matrix t = f_mul(N, L);
  return f_pow(2, s) * t.v[0][1] % MOD;
}
void run() {
  long long r = 0;
  for (int i = 0; i < L; i++) {
    if (S[i] == '0' || S[i] == '5') {
      r += cal(i);
      r %= MOD;
    }
  }
  cout << r << endl;
}
int main(int argc, char *argv[]) {
  {
    get_data();
    run();
  }
  return EXIT_SUCCESS;
}
