#include "bits/stdc++.h"

using namespace std;

long long calc(int n){
    long long ret=1ll*(n*(n+1ll))/2ll;
    return ret;
}

void solve(){
    string s;
    cin>>s;
    int n=s.length();
    if(n==1){
        if(s[0]=='8'){
            cout<<"Yes\n";
        }
        else{
            cout<<"No\n";
        }
        return;
    }
    else if(n==2){
        int num1=(s[0]-'0')*10+s[1]-'0';
        int num2=(s[1]-'0')*10+s[0]-'0';
        if(num1%8==0 || num2%8==0){
            cout<<"Yes\n";
        }
        else{
            cout<<"No\n";
        }
        return;
    }
    int cnt[10];
    fill(cnt,cnt+10,0);
    for(auto c:s){
        cnt[c-'0']++;
    }
    // vector<vector<int>> req;
    for(int i=104;i<1000;i+=8){
        vector<int> temp(10,0);
        int j=i;
        while(j>0){
            temp[(j%10)]++;
            j/=10;
        }
        bool flag=false;
        for(j=0;j<10;j++){
            if(cnt[j]<temp[j]){
                flag=true;
                break;
            }
        }
        if(flag){
            continue;
        }
        cout<<"Yes\n";
        return;
    }
    cout<<"No\n";
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

using ll = long long;
using ld = long double;
using ordered_set = tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>;

void fastio() {
	cin.tie(nullptr);
	cin.sync_with_stdio(false);
}

const ll MOD = 1e9+7;
const ll INF = 1e18;
const ll N = 2e5+5;

#define S second
#define F first
#define vt vector
#define rep(i, st, en) for(ll i = (st); i < (en); ++i)
#define repr(i, en, st) for(ll i = (en); i >= (st); --i)

static bool dp[101][100001] = {0};

int main() {
	fastio();

	ll n;
	cin >> n;

	vt<ll> t(n);
	ll net = 0;
	rep(i, 0, n) {
		cin >> t[i];
		net += t[i];
	}
	
	dp[0][0] = dp[0][t[0]] = 1;

	ll mxt = 1e5;
	rep(i, 1, n) {
		rep(j, 0, mxt+1) {
			if (dp[i-1][j] || (j >= t[i] && dp[i-1][j-t[i]])) {
				dp[i][j] = 1;
			}
		}
	}

	ll ans = 0;
	ll neth = net/2;
	rep(i, 0, neth+1) {
		if (dp[n-1][i]) {
			ans = i;
		}
	}

	ans = max(ans, net-ans);
	cout << ans << '\n';


}