#include <bits/stdc++.h>
using namespace std;
int INP, AM, REACHEOF;
char BUF[(1 << 12) + 1], *inp = BUF;
const long double PI = acos((long double)-1.0);
const long long MOD = 1000000007LL;
char s[100111];
int r, p2[100111];
long long power(long long x, int k) {
  if (k == 0) return 1;
  if (k == 1) return x % MOD;
  long long mid = power(x, k >> 1);
  mid = mid * mid % MOD;
  if (k & 1)
    return mid * x % MOD;
  else
    return mid;
}
long long inverse(long long x) { return power(x, MOD - 2); }
int main() {
  p2[0] = 1;
  for (int i = (1), _b = (100000); i <= _b; i++) p2[i] = (p2[i - 1] * 2) % MOD;
  while (gets(s)) {
    scanf("%d\n", &r);
    int l = strlen(s);
    long long res = 0, x = p2[l];
    for (int i = 0, _a = (l); i < _a; i++) {
      if (s[i] == '0' || s[i] == '5') {
        long long t = (power(x, r) - 1 + MOD) % MOD;
        t = t * inverse((x - 1 + MOD) % MOD) % MOD;
        res = (res + p2[i] * t) % MOD;
      }
    }
    cout << res % MOD << endl;
  }
  return 0;
}
