#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<deque>
#include<queue>
#include<stack>
using namespace std;
#define int long long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define dup(x,y) (((x)+(y)-1)/(y))
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef pair<int, int>P;
const int MOD = 1e9 + 7;
//const int MOD = 998244353;
const int INF = 1e18;
const long double PI = (acos(-1));



signed main() {
	string S;
	cin >> S;
	if (S.size() == 1) {
		if (S[0] == '8')cout << "Yes";
		else cout << "No";
		return 0;
	}
	if (S.size() <= 2) {
		int a = '1' + S[0] - 1;
		int b = '1' + S[1] - 1;
		int c = 10 * a + b;
		int d = 10 * b + a;
		if (c % 8 == 0 || d % 8 == 0) {
			cout << "Yes";
		}
		else cout << "No";
		return 0;
	}
	map<int, int>m;
	for (auto i : S)m[i]++;
	for (int i = 1; i <= 9; i++) {
		for (int j = 1; j <= 9; j++) {
			for (int k = 1; k <= 9; k++) {
				char ci = '1' + i - 1;
				char cj = '1' + j - 1;
				char ck = '1' + k - 1;
				m[ci]--; m[cj]--; m[ck]--;
				if (m[ci] < 0 || m[cj] < 0 || m[ck] < 0) {
					m[ci]++; m[cj]++ + m[ck]++;
					continue;
				}
				int num = i * 100 + j * 10 + k;
				if (num % 8 == 0) {
					cout << "Yes";
					return 0;
				}
				m[ci]++; m[cj]++ + m[ck]++;
			}
		}
	}
	cout << "No";
}
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
using namespace std;

int naive(int N, string S, string T)
{
    map<string, int> M;
    M[S] = 0;

    for (int d=0; d<100; d++)
    {
        for (auto it: M)
        {
            string s = it.first;
            int n = it.second;
            if (n==d)
            {
                for (int i=1; i<N; i++)
                    if (s[i]=='1')
                    {
                        string s2 = s;
                        s2[i] = '0';
                        s2[i-1] = s2[i-1]^1;
                        if (M.count(s2)==0)
                            M[s2] = n+1;
                    }
            }
        }
    }

    if (M.count(T)==0)
        return -1;
    return M[T];
}

long long solve(int N, string S, string T)
{
    long long ans = 0;
    int p1 = 0;
    for (int i=0; i<N; i++)
    {
        if (S[i]=='0' && T[i]=='1')
        {
            p1 = max(p1, i+1);
            while (p1<N && S[p1]=='0')
                p1++;
            if (p1>=N)
                return -1;

            S[p1] = '0';
            S[i] = '1';
            ans += p1-i;
        }
        else if (S[i]=='1' && T[i]=='0')
        {
            p1 = max(p1, i+1);
            while (p1<N && S[p1]=='0')
                p1++;
            if (p1>=N)
                return -1;

            S[i] = '0';
            S[p1] = '0';
            ans += p1-i;
        }
    }
    return ans;
}

int main()
{
    //while (true)
    //{
    //    int N = 8;
    //    string S;
    //    for (int i=0; i<N; i++)
    //        S += "01"[rand()%2];
    //    string T;
    //    for (int i=0; i<N; i++)
    //        T += "01"[rand()%2];

    //    int a1 = solve(N, S, T);
    //    int a2 = naive(N, S, T);
    //    //cout<<a1<<" "<<a2<<endl;
    //    if (a1!=a2)
    //    {
    //        cout<<N<<endl;
    //        cout<<S<<endl;
    //        cout<<T<<endl;
    //        cout<<a1<<" "<<a2<<endl;
    //        return 0;
    //    }
    //}

    int N;
    cin>>N;
    string S;
    cin>>S;
    string T;
    cin>>T;

    cout<<solve(N, S, T)<<endl;
}
