#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
    string s;
    cin >> s;
    map<ll, ll> mp;
    for(int i=0; i<s.size(); i++) {
        int x = s[i] - '0';
        mp[x]++;
    }
    if(s == "8") {
        cout << "Yes" << endl;
        return 0;
    }
    if(s.size() == 2) {
        int x = (s[0] - '0') * 10 + (s[1] - '0');
        int y = (s[1] - '0') * 10 + (s[0] - '0');
        if(x % 8 == 0 || y % 8 == 0) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    for(int i=1; i<10; i++) {
        if(mp[i] <= 0) continue;
        mp[i]--;
        for(int j=1; j<10; j++) {
            if(mp[j] <= 0) continue;
            mp[j]--;
            for(int k=1; k<10; k++) {
                if(mp[k] <= 0) continue;
                int a = i, b = j, c = k;
                int m = a * 100 + b * 10 + c;
                if(m % 8 == 0) {
                    cout << "Yes" << endl;
                    return 0;
                }
            }
            mp[j]++;
        }
        mp[i]++;
    }
    cout << "No" << endl;
}
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <climits>

#define rep(i, n) for(int i = 0; i < n; i++)
#define per(i, n) for(int i = n - 1; i >= 0; i--)
using ll = long long;
using ld = long double;
#define vi vector<int>
#define vvi vector<vi>
#define vl vector<ll>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define all(a) (a).begin(), (a).end()
#define mod 998244353
using namespace std;
ll modPow(ll a, ll n, ll p){
  if(!n) return 1;
  if(n == 1) return a % p;
  if(n & 1) return (a * modPow(a, n - 1, p)) % p;
  ll t = modPow(a, n / 2, p);
  return (t * t) % p;
}
struct UnionFind {
  vector<int> d;
  int n;
  UnionFind(int n): n(n), d(n,-1) {}
  int root(int x) {
    if (d[x] < 0) return x;
    return d[x] = root(d[x]);
  }
  bool unite(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y) return false;
    if (d[x] > d[y]) swap(x,y);
    d[x] += d[y];
    d[y] = x;
    return true;
  }
  bool same(int x, int y){
    return root(x) == root(y);
  }
  int size(int x){
    return -d[root(x)];
  }
  int gorup_num(){
    int res = 0;
    rep(i, n) if(d[i] < 0) res++;
    return res;
  }
};
int main(){
  int n;
  cin >> n;
  UnionFind tree(n);
  rep(i, n){
    int f; cin >> f;
    tree.unite(i, f - 1);
  }
  cout << modPow(2, tree.gorup_num(), mod) - 1 << "\n";
}