#include "bits/stdc++.h"

#define MOD 1000000007
#define rep(i, n) for(ll i=0; i < (n); i++)
#define rrep(i, n) for(ll i=(n)-1; i >=0; i--)
#define ALL(v) v.begin(),v.end()
#define rALL(v) v.rbegin(),v.rend()
#define FOR(i, j, k) for(ll i=j;i<k;i++)
#define debug_print(var) cerr << #var << "=" << var <<endl;
#define DUMP(i, v)for(ll i=0;i<v.size();i++)cerr<<v[i]<<" "
#define fi first
#define se second

using namespace std;
typedef long long int ll;
typedef vector<ll> llvec;
typedef vector<double> dvec;
typedef pair<ll, ll> P;
typedef long double ld;
struct edge{ll x, c;};

ll mod(ll a, ll mod){
  ll res = a%mod;
  if(res<0)res=res + mod;
  return res;
}

ll modpow(ll a, ll n, ll mod){
  ll res=1;
  while(n>0){
    if(n&1) res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll modinv(ll a, ll mod){
  ll b=mod, u=1, v=0;
  while(b){
    ll t=a/b;
    a-=t*b; swap(a, b);
    u-=t*v; swap(u, v);
  }
  u%=mod;
  if(u<0)u+=mod;
  return u;
}

ll gcd(ll a, ll b){
  ll r = a%b;
  if(r==0) return b;
  else return gcd(b, a%b);
}

bool is_prime(ll n){
  ll i = 2;
  if(n==1)return false;
  if(n==2)return true;
  bool res = true;
  while(i*i <n){
    if(n%i==0){
      res = false;
    }
    i = i+1;
  }

  //if(i==1)res = false;
  if(n%i==0)res=false;
  return res;
}
/**************************************
** A main function starts from here  **
***************************************/
int main(){
  llvec v(4);
  ll ans = 1e18;
  rep(i, 4)cin >> v[i];
  rep(i, 4)ans = min(ans,v[i]);
  cout<< ans << endl;
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define MOD int(1e9+7)
#define INF int(1e9+7)
#define LINF ll(1e18+7)
#define PI acos(-1)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define P pair<ll,ll>
#define chmax(x,y) (x = max(x,y))
#define chmin(x,y) (x = min(x,y))

int main(){
  string s;
  cin>>s;
  map<int,int> mp;
  rep(i,s.size()){
    int num=(int)(s[i]-'0');
    mp[num]++;
  }
  if(s.size()==1){
    if(mp[8]==1) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
  }
  if(s.size()==2){
    for(int i=10; i<100; i++){
      if(i%8!=0) continue;
      bool ok=1;
      map<int,int> cnt;
      int tmp=i;
      rep(j,2){
        int d=tmp%10;
        cnt[d]++;
        tmp/=10;
      }
      for(auto x : cnt){
        if(x.second>mp[x.first]) ok=0;
      }
      if(ok){
        cout<<"Yes"<<endl;
        return 0;
      }
    }
    cout<<"No"<<endl;
    return 0;
  }
  for(int i=100; i<1000; i++){
    if(i%8!=0) continue;
    bool ok=1;
    map<int,int> cnt;
    int tmp=i;
    rep(j,3){
      int d=tmp%10;
      cnt[d]++;
      tmp/=10;
    }
    for(auto x : cnt){
      if(x.second>mp[x.first]) ok=0;
    }
    if(ok){
      cout<<"Yes"<<endl;
      return 0;
    }
  }
  cout<<"No"<<endl;
}