#include <bits/stdc++.h>
using namespace std;
const bool testing = false;
const int mod = 1000 * 1000 * 1000 + 7;
long long power(long long a, long long b) {
  long long k = 1;
  for (; b; b /= 2, a = a * a % mod)
    if (b & 1) k = k * a % mod;
  return k;
}
void program() {
  string s;
  cin >> s;
  long long n, k;
  cin >> k;
  long long ans = 0;
  for (n = 0; n < s.size(); ++n)
    if (s[n] == '0' || s[n] == '5') ans += power(2, n), ans %= mod;
  ans = ans * ((power(2, n * k) - 1 + mod) % mod) % mod;
  n = (power(2, n) - 1 + mod) % mod;
  cout << ans * power(n, mod - 2) % mod << endl;
}
int main() {
  if (!testing) {
    program();
    return 0;
  }
  FILE* fin = NULL;
  fin = fopen("in.txt", "w+");
  fprintf(fin, "1256\n1\n");
  fclose(fin);
  freopen("in.txt", "r", stdin);
  printf("test case(1) => expected : \n");
  printf("4\n");
  printf("test case(1) => founded  : \n");
  program();
  fin = fopen("in.txt", "w+");
  fprintf(fin, "13990\n2\n");
  fclose(fin);
  freopen("in.txt", "r", stdin);
  printf("test case(2) => expected : \n");
  printf("528\n");
  printf("test case(2) => founded  : \n");
  program();
  fin = fopen("in.txt", "w+");
  fprintf(fin, "555\n2\n");
  fclose(fin);
  freopen("in.txt", "r", stdin);
  printf("test case(3) => expected : \n");
  printf("63\n");
  printf("test case(3) => founded  : \n");
  program();
  return 0;
}
