#include <bits/stdc++.h>
using namespace std;
void Get(int &T) {
  char C;
  bool F = 0;
  for (; C = getchar(), C < '0' || C > '9';)
    if (C == '-') F = 1;
  for (T = C - '0'; C = getchar(), C >= '0' && C <= '9'; T = T * 10 + C - '0')
    ;
  F && (T = -T);
}
char S[1000005];
int N;
int K;
void Init() {
  scanf("%s", S + 1);
  N = strlen(S + 1);
  Get(K);
}
long long Pow(long long X, long long Y) {
  long long Ans = 1;
  for (; Y; Y >>= 1) {
    if (Y & 1) (Ans *= X) %= (1000000007);
    (X *= X) %= (1000000007);
  }
  return Ans;
}
long long Calc(long long K) {
  if (K == 0) return 0;
  if (K == 1) return 1;
  long long Ans1 = Calc(K >> 1);
  (Ans1 *= (1 + Pow(2, (K >> 1) * N))) %= (1000000007);
  if (K & 1) (Ans1 += Pow(2, (K - 1) * N)) %= (1000000007);
  return Ans1;
}
long long Ans;
void Debug() {
  long long Ans0 = 0;
  long long Ans1;
  for (int k = 1; k <= 100000; k++) {
    (Ans0 += Pow(2, (long long)(k - 1) * N)) %= (1000000007);
    Ans1 = Calc(k);
    if (Ans0 != Ans1) printf("%I64d %I64d\n", Ans0, Ans1);
  }
}
void Work() {
  long long X = Calc(K);
  for (int i = 1; i <= N; i++)
    if (S[i] == '0' || S[i] == '5') (Ans += Pow(2, i - 1) * X) %= (1000000007);
}
void Output() { printf("%I64d\n", Ans); }
int main() {
  Init();
  Work();
  Output();
  return 0;
}
