// Problem: C - Comma
// Contest: AtCoder - Panasonic Programming Contest (AtCoder Beginner Contest 195)
// URL: https://atcoder.jp/contests/abc195/tasks/abc195_c
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
// Date: 2021-03-13 22:42:44
// --------by Herio--------

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull; 
const int N=1e3+5,M=2e4+5,inf=0x3f3f3f3f,mod=1e9+7;
#define mst(a,b) memset(a,b,sizeof a)
#define PII pair<int,int>
#define fi first
#define se second
#define pb emplace_back
#define SZ(a) (int)a.size()
#define IOS ios::sync_with_stdio(false),cin.tie(0) 
void Print(int *a,int n){
	for(int i=1;i<n;i++)
		printf("%d ",a[i]);
	printf("%d\n",a[n]); 
}
int a[20];
ll dp[22][22][2][2];
ll dfs(int x,int c,bool li,bool lead){
	if(!x){
		//printf("c=%d\n",c);
		return (c-1)/3;
	}
	ll &s=dp[x][c][li][lead];
	if(~s) return s;
	s=0;
	int mx=li?a[x]:9;
	for(int i=0;i<=mx;i++)
		s+=dfs(x-1,(lead&&!i)?c:c+1,li&(i==mx),lead&&!i);
	return s;
}
ll fun(ll n){
	int w=0;while(n) a[++w]=n%10,n/=10;
	return dfs(w,0,1,1);
}
int main(){
	ll n;scanf("%lld",&n);mst(dp,-1);
	printf("%lld\n",fun(n));
	return 0;
}

#include <fstream>
#include <numeric>
#include <unordered_set>
#include <sstream>
#include <cassert>
#include <tuple>
#include <iomanip>
#include <random>
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <chrono>
#include <stack>
#include <string>
#include <bitset>
#include <unordered_map>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>

#define rep(i,x,y) for(int i = x; i <= y; ++i)
#define repr(i,x,y) for(int i = x; i >= y; --i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x.size())
#define pb push_back
#define endl "\n" // interactive problem
#define ll long long
#define int long long

using namespace std;

const int N = (int)(1e5) + 322;
const int inf = (int)(1e9) + 322;
const long long INF = (long long)(1e18) + 322;
const int mod = (int)(1e9) + 7;

void solve() {
    string s; cin >> s;
    if (sz(s) <= 4) {
        sort(all(s));
        do {
            if (stoi(s) % 8 == 0) {
                cout << "Yes";
                return;
            }
        } while (next_permutation(all(s)));
    }
    unordered_map <char, int> cnt;
    for(auto c : s) cnt[c]++;
    for(int i = 8; i < 1000; i += 8) {
        string cur = to_string(i);
        while (sz(cur) < 3) cur += '0';
        unordered_map <char, int> no;
        for(auto c : cur) no[c]++;
        bool good = true;
        for(auto it : no) {
            if (cnt[it.first] < it.second) good = false;
        }
        if (good) {
            cout << "Yes";
            return;
        }
    }
    cout << "No";

}

signed main () {
    ios_base :: sync_with_stdio(false);
    cin.tie(0);
//    freopen("student.in", "r", stdin);
//    freopen("student.out", "w", stdout);
    int t = 1;//cin >> t;
    for(int tt = 1; tt <= t; ++tt) {
        solve();
    }
    return 0;
}
