#include <bits/stdc++.h>
using namespace std;
int absol(int x);
int main() {
  int n, C, left, right, top, bot;
  char c;
  int xy[10][2] = {{1, 3}, {0, 0}, {1, 0}, {2, 0}, {0, 1},
                   {1, 1}, {2, 1}, {0, 2}, {1, 2}, {2, 2}};
  cin >> n;
  cin >> c;
  C = c;
  C -= 48;
  left = C;
  right = C;
  top = C;
  bot = C;
  for (int i = 1; i < n; i++) {
    cin >> c;
    C = c;
    C -= 48;
    if (xy[C][0] < xy[left][0])
      left = C;
    else if (xy[C][0] > xy[right][0])
      right = C;
    if (xy[C][1] < xy[top][1])
      top = C;
    else if (xy[C][1] > xy[bot][1] || (bot != 0 && (C == 7 || C == 9)))
      bot = C;
  }
  if ((absol(xy[bot][1] - xy[top][1]) == 2 &&
       absol(xy[right][0] - xy[left][0]) == 2 && bot != 8 && bot != 0) ||
      absol(xy[bot][1] - xy[top][1]) == 3) {
    cout << "YES" << endl;
  } else
    cout << "NO" << endl;
  return 0;
}
int absol(int x) {
  if (x < 0)
    return x * -1;
  else
    return x;
}
