#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>
#include <stack>
#include<set>
#include<tuple>
#include<time.h>
#include<list>

#define DIV 998244353
using namespace std;
using ll = long long;
using ldb = long double;

int main() {
	string s; cin >> s;
	vector<int> cnt(10);
	int len = s.size();
	for (int i = 0; i < len; i++) {
		cnt[s[i] - '0']++;
	}

	if (len == 1) {
		if (cnt[8] == 1) cout << "Yes" << endl;
		else cout << "No" << endl;
	}

	else if (len == 2) {
		bool flag = false;
		for (int i = 0; i < 100; i += 8) {
			vector<int> ned(10);
			int temp = i;
			ned[temp % 10]++;
			temp /= 10;
			ned[temp % 10]++;
			bool hachi = true;
			for (int j = 0; j <= 9; j++) {
				if (cnt[j] < ned[j]) {
					hachi = false;
					break;
				}
			}

			if (hachi) {
				flag = true;
				break;
			}
		}

		if (flag) cout << "Yes" << endl;
		else cout << "No" << endl;
	}
	

	else {
		bool flag = false;
		for (int i = 0; i <= 1000; i += 8) {
			vector<int> ned(10);
			int temp = i;
			ned[temp % 10]++;
			temp /= 10;
			ned[temp % 10]++;
			temp /= 10;
			ned[temp % 10]++;
			bool hachi = true;
			for (int j = 0; j <= 9; j++) {
				//printf("ned[%d]=%d\n", j, ned[j]);
				if (cnt[j] < ned[j]) {
					hachi = false;
					break;
				}
			}

			if (hachi) {
				flag = true;
				//cout << "i=" << i << endl;
				break;
			}
		}

		if (flag) cout << "Yes" << endl;
		else cout << "No" << endl;
	}
}
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)

using namespace std;
using ll = long long;

int main() {
    int n;

    cin >> n;

    bool ans = true;
    int ok[200][200] = {};
    vector<int> a(n), b(n);
    vector<int> h(n * 2);

    rep(i, n) {
        cin >> a[i] >> b[i];
        a[i]--;
        b[i]--;
        if (a[i] != -2 && b[i] != -2 && a[i] >= b[i]) ans = false; 
    }
    rep(i, n) {
        if (a[i] != -2 && b[i] == -2) {
            if (h[a[i]] != 0) ans = false;
            h[a[i]] = 1;
        }
        if (b[i] != -2 && a[i] == -2) {
            if (h[b[i]] != 0) ans = false;
            h[b[i]] = -1;
        }
        if (a[i] != -2 && b[i] != -2) {
            if (h[a[i]] != 0 || h[b[i]] != 0) ans = false;
            h[a[i]] = 2;
            h[b[i]] = -2;
            ok[a[i]][b[i]] = 1;
        }
    }
    // h[i] = -2,-1,0,1,2
    rep(i, n * 2) rep(j, i){ // j < i
        if (ok[j][i] == 1) continue;
        if (h[i] == 0 && h[j] == 0) continue;
        if (h[i] == -1 && h[j] == 0) continue;
        if (h[i] == 0 && h[j] == 1) continue;
        ok[j][i] = -1;
    }
    if (!ans) {
        cout << "No" << endl;
        return 0;
    }
    // 7,10,17,19,28,32
    // last = 0,2,4,6,...
    // i = 1,3,5,7,...
    vector<int> ed;
    ed.push_back(0);
    for (int i = 1; i < n * 2; i += 2) {
        for (int last : ed) {
            int mid = (i + last + 1) / 2;
            bool check = true;
            for (int j = mid; j <= i; j++) {
                if (ok[last + j - mid][j] == -1) check = false;
            }
            if (check) {
                ed.push_back(i + 1);
                break;
            }
        }
    }

    if (ed[ed.size() - 1] == n * 2) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}