#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
const int maxn=2e5+10;
int n,m,t,is,cnt,ans;
string p;
int sum[10],q[150];
int main(){
#ifdef ONLINE_JUDGE
#else
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
#endif
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(2);
    memset(q,0,sizeof(q));
    memset(sum,0,sizeof(sum));
    int c=0;
    for(int i=104;;i+=8){
        if(i>=1000)break;
        q[c++]=i;
    }
    // for(int i=0;i<c;i++)cout<<q[i]<<"\n";
    // return 0;
    cin>>p;
    bool is=false;
    for(int i=0;i<p.length();i++)++sum[p[i]-'0'];
    if(p.length()==1&&(p[0]-'0')%8==0)is=true;
    else if(p.length()==2){
        int g=(p[0]-'0')+(p[1]-'0')*10;
        if(g%8==0)is=true;
        g=(p[1]-'0')+(p[0]-'0')*10;
        if(g%8==0)is=true;
    }
    else {
        for(int i=0;i<c;i++){
            int a=q[i]%10,b=q[i]/10%10,c=q[i]/100;
            --sum[a],--sum[b],--sum[c];
            if(sum[a]>=0&&sum[b]>=0&&sum[c]>=0){
                is=true;
                break;
            }
            ++sum[a],++sum[b],++sum[c];
        }
    }
    cout<<(is?"Yes":"No")<<"\n";
    return 0;
    //good job!
}
#include <bits/stdc++.h>
const int N = 200005, P = 1e9 + 7;
char s[N]; int n, K, c[16], fac[20], ifac[20];
int qpow(int a, int b) {
	int t = 1;
	for (; b; b >>= 1, a = 1LL * a * a % P)
		if (b & 1) t = 1LL * t * a % P;
	return t;
}
int idx(char c) {
	if (isdigit(c)) return c - '0';
	else return c - 'A' + 10;
}
int C(int n, int m) {
	if (m > n || m < 0) return 0;
	return 1LL * fac[n] * ifac[m] % P * ifac[n - m] % P;
}
int f(int m, int n) {
	// K - m
	int k = K - m, ans = 0;
	if (n < k) return 0;
	for (int i = 0; i <= k; i++) {
		ans = (ans + 1LL * C(k, i) * qpow(P - 1, k - i) % P * qpow(i + m, n)) % P;
	}
	return 1LL * ans * C(16 - m, k) % P;
}
int main() {
	scanf("%s%d", s + 1, &K); n = strlen(s + 1);
	fac[0] = ifac[0] = 1;
	for (int i = 1; i <= 16; i++) fac[i] = 1LL * fac[i - 1] * i % P;
	ifac[16] = qpow(fac[16], P - 2);
	for (int i = 15; i; i--) ifac[i] = 1LL * ifac[i + 1] * (i + 1) % P;
	int tot = 0, ans = 0;
	for (int i = 1; i <= n; i++) {
		int a = idx(s[i]);
		for (int j = 0; j <= a; j++) {
			if (i == 1 && j == 0 || i != n && j == a) continue;
			int _tot = tot + (c[j] == 0);
			ans = (ans + f(_tot, n - i)) % P;
		}
		if (c[a] == 0) tot++;
		c[a] = 1;
	}
	for (int i = 2; i <= n; i++) ans = (ans + 15LL * f(1, n - i)) % P;
	printf("%d", ans);
	return 0;
}