#include <bits/stdc++.h>
using namespace std;
const int maxn = 200005;
const int logn = 18;
const int inf = (int)1e9 + 5;
const long long mod = (long long)1e9 + 7;
const long long base = 2204234849;
const long long l_inf = (long long)4e18;
const long double pi = acos(-1.0);
const long double eps = 1e-12;
int x[10] = {1, 0, 1, 2, 0, 1, 2, 0, 1, 2};
int y[10] = {3, 0, 0, 0, 1, 1, 1, 2, 2, 2};
int n;
char d[maxn];
bool good(int x, int y) {
  return (x >= 0 && x <= 2 && y >= 0 && y <= 2) || (x == 1 && y == 3);
}
int main() {
  ios_base::sync_with_stdio(false);
  cout.precision(20);
  cout << fixed;
  srand(566);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> d[i];
    d[i] -= '0';
  }
  if (n == 1) {
    cout << "NO\n";
    exit(0);
  }
  int cnt = 0;
  for (int i = 0; i < 10; i++) {
    bool ok = true;
    int a = x[i], b = y[i];
    for (int j = 1; j < n && ok; j++) {
      a += x[d[j]] - x[d[j - 1]];
      b += y[d[j]] - y[d[j - 1]];
      if (!good(a, b)) ok = false;
    }
    cnt += ok;
  }
  if (cnt == 1) {
    cout << "YES\n";
  } else {
    cout << "NO\n";
  }
  return 0;
}
