using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
    class _689A
    {
        static void Main(string[] args)
        {
            int n = Int32.Parse(Console.ReadLine());
            var seq = Console.ReadLine().Select(x => (x-'0')).ToList();
            int[] left = new int[] {-1, -1, 1, 2, -1, 4, 5, -1, 7, 8 };
            int[] right = new int[] {-1, 2, 3, -1, 5, 6, -1, 8, 9, -1};
            int[] up = new int[] {8, -1, -1, -1, 1, 2, 3, 4, 5, 6 };
            int[] down = new int[] {-1, 4, 5, 6, 7, 8, 9, -1, 0, -1 };
            if (isCorrect(seq, left) || isCorrect(seq, right) || isCorrect(seq, up) || isCorrect(seq, down))
            {
                Console.WriteLine("NO");
            }
            else
            {
                Console.WriteLine("YES");
            }
        }
        static bool isCorrect(List<int> source, int[] mode)
        {
            foreach(var x in source)
            {
                int to = mode[x];
                if (to == -1)
                    return false;
            }
            return true;
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Globalization;
using System.IO;
using System.Net;

namespace ConsoleApplication6
{
    class Program
    {     static int[] ceni;
        static void Main(string[] args)
        {
            int n = Convert.ToInt32(Console.ReadLine());
            string str = Console.ReadLine();
            int[] nabor = new int[n];
            int[] vertik = new int[n];
            int[] gorizont = new int[n];
            for (int i = 0; i < n; i++) {
                nabor[i] = Convert.ToInt32(str[i].ToString());

            }
            for (int i = 0; i < n; i++) {
                if (nabor[i] % 3 > 0) {
                    vertik[i] = nabor[i] % 3;
                    gorizont[i] = (nabor[i] / 3) + 1;

                }
                else {

                    if (nabor[i] > 0)
                    { gorizont[i] = (nabor[i] / 3);
                      vertik[i] = 3;

                    }
                    else {
                        vertik[i] = 2;
                        gorizont[i] = 4; }
                }
            }
            int maxvertik = vertik.Max();
            int minvertik = vertik.Min();
            int maxgorizont = gorizont.Max();
            int mingorizont = gorizont.Min();
            bool sdvigg=true;
            bool sdvigv=true;

            if((mingorizont==1)&&(maxgorizont==4)){
                sdvigv = false;
                sdvigg = false;
            }
            if ((mingorizont == 1) && (maxgorizont == 3)) {
                for(int i=0;i<n;i++){
                if(((vertik[i]==3)||(vertik[i]==1))&&(gorizont[i]==3)){
                 sdvigv = false;
                 break;
                }

                }
            }
            if ((minvertik == 1) && (maxvertik == 3)) {
                sdvigg = false;
            }

            if ((sdvigv==false)&&(sdvigg==false))
            {
                Console.WriteLine("YES");

            }
            else { Console.WriteLine("NO"); }
            Console.ReadLine();
        }
    }
}

    using System;
    using System.Collections.Generic;
    using System.Globalization;
    using System.IO;
    using System.Linq;
    using System.Runtime.CompilerServices;
    using System.Runtime.InteropServices;
    using System.Threading;

    namespace Codeforces
    {
        class Program : IDisposable
        {
            private static readonly TextReader textReader = new StreamReader(Console.OpenStandardInput());
            private static readonly TextWriter textWriter = new StreamWriter(Console.OpenStandardOutput());

            void Solve()
            {
                var s1 = Console.ReadLine();
                var number = Console.ReadLine();
                if(number.Length == 1)
                    Console.WriteLine("NO");
                else
                {
                    var dict = new Dictionary<char, Tuple<int, int>>()
                    {
                        {'1', new Tuple<int, int>(0,0)},
                        {'2', new Tuple<int, int>(1,0)},
                        {'3', new Tuple<int, int>(2,0)},
                        {'4', new Tuple<int, int>(0,1)},
                        {'5', new Tuple<int, int>(1,1)},
                        {'6', new Tuple<int, int>(2,1)},
                        {'7', new Tuple<int, int>(0,2)},
                        {'8', new Tuple<int, int>(1,2)},
                        {'9', new Tuple<int, int>(2,2)},
                        {'0', new Tuple<int, int>(1,3)},
                    };

                    var coords = dict[number[0]];
                    var xBeg = coords.Item1;
                    var yBeg = coords.Item2;
                    coords = dict[number[1]];
                    var xEnd = coords.Item1;
                    var yEnd = coords.Item2;
                    var xPath = xEnd - xBeg;
                    var yPath = yEnd - yBeg;
                    var paths = FindInitialPaths(xBeg, yBeg, xPath, yPath);
                    if(paths.Count == 0)
                        Console.WriteLine("YES");
                    else
                    {
                        bool print = true;
                        bool success = true;
                        foreach (var tuple in paths)
                        {
                            var nextCoord = new Tuple<int, int>(tuple.Item1, tuple.Item2);
                            success = true;
                            for (int i = 1; i < number.Length - 1; i++)
                            {
                                coords = dict[number[i]];
                                xBeg = coords.Item1;
                                yBeg = coords.Item2;
                                coords = dict[number[i+1]];
                                xEnd = coords.Item1;
                                yEnd = coords.Item2;
                                xPath = xEnd - xBeg;
                                yPath = yEnd - yBeg;
                                nextCoord = NextCoord(nextCoord.Item1, nextCoord.Item2, xPath, yPath);
                                if (nextCoord.Item1 == -1 && nextCoord.Item2 == -1)
                                {
                                    success = false;
                                    break;
                                }
                            }
                            if (success)
                            {
                                Console.WriteLine("NO");
                                print = false;
                                break;
                            }
                        }
                        if(print)
                            Console.WriteLine("YES");

                    }
                }
            }

            static List<Tuple<int,int>> FindInitialPaths(int x, int y, int xPath, int yPath)
            {
                var list = new List<Tuple<int, int>>();
                for (int i = 0; i < 3; i++)
                {
                    for (int j = 0; j < 4; j++)
                    {
                        if (!(i == x && j == y) && !(i==0 && j==3) && !(i==2 && j==3))
                        {
                            var nX = i + xPath;
                            var nY = j + yPath;

                            if((nX>=0 && nX<=2&&nY>=0 && nY<=2) || (nX == 1 && nY == 3))
                                list.Add(new Tuple<int, int>(nX, nY));
                        }
                    }
                }
                return list;
            }

            static Tuple<int, int> NextCoord(int x, int y, int xPath, int yPath)
            {
                var nX = x + xPath;
                var nY = y + yPath;
                if ((nX >= 0 && nX <= 2 && nY >= 0 && nY <= 2) || (nX == 1 && nY == 3))
                    return new Tuple<int, int>(nX, nY);
                return new Tuple<int, int>(-1,-1);
            }

            static void Main(string[] args)
            {
                var p = new Program();
                p.Solve();
                //Console.ReadLine();
                p.Dispose();
            }

            #region Helpers

            private static int ReadInt()
            {
                return int.Parse(textReader.ReadLine());
            }

            private static long ReadLong()
            {
                return long.Parse(textReader.ReadLine());
            }

            private static int[] ReadIntArray()
            {
                return textReader.ReadLine().Split(' ').Select(int.Parse).ToArray();
            }
            #endregion

            public void Dispose()
            {
                textReader.Close();
                textWriter.Close();
            }
        }
    }

using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;

namespace TaskA
{
    class Program
    {
        static void Main(string[] args)
        {
            new Solver().Solve().OutputResult();
        }

        private class ExtendedReader : StreamReader
        {
            private static readonly char Separator = ' ';

            public ExtendedReader(Stream stream) : base(stream) { }
            public ExtendedReader(Stream stream, bool detectEncodingFromByteOrderMarks) : base(stream, detectEncodingFromByteOrderMarks) { }
            public ExtendedReader(Stream stream, Encoding encoding) : base(stream, encoding) { }
            public ExtendedReader(Stream stream, Encoding encoding, bool detectEncodingFromByteOrderMarks) : base(stream, encoding, detectEncodingFromByteOrderMarks) { }
            public ExtendedReader(Stream stream, Encoding encoding, bool detectEncodingFromByteOrderMarks, int bufferSize) : base(stream, encoding, detectEncodingFromByteOrderMarks, bufferSize) { }
            public ExtendedReader(Stream stream, Encoding encoding, bool detectEncodingFromByteOrderMarks, int bufferSize, bool leaveOpen) : base(stream, encoding, detectEncodingFromByteOrderMarks, bufferSize, leaveOpen) { }
            public ExtendedReader(string path) : base(path) { }
            public ExtendedReader(string path, bool detectEncodingFromByteOrderMarks) : base(path, detectEncodingFromByteOrderMarks) { }
            public ExtendedReader(string path, Encoding encoding) : base(path, encoding) { }
            public ExtendedReader(string path, Encoding encoding, bool detectEncodingFromByteOrderMarks) : base(path, encoding, detectEncodingFromByteOrderMarks) { }
            public ExtendedReader(string path, Encoding encoding, bool detectEncodingFromByteOrderMarks, int bufferSize) : base(path, encoding, detectEncodingFromByteOrderMarks, bufferSize) { }

            public char ReadChar()
            {
                return (char)this.Read();
            }

            public double ReadDoubleFromArray()
            {
                StringBuilder sb = new StringBuilder();
                char ch = this.ReadChar();
                while (ch != Separator && ch != '\n')
                {
                    sb.Append(ch);
                    ch = this.ReadChar();
                }
                return Convert.ToDouble(sb.ToString());
            }

            public int ReadInt()
            {
                return int.Parse(this.ReadLine());
            }

            public Int64 ReadInt64()
            {
                return Int64.Parse(this.ReadLine());
            }

            public int[] ReadIntArray()
            {
                return this.ReadLine().Split(' ').Select(int.Parse).ToArray();
            }

            public char[] ReadCharArray()
            {
                return this.ReadLine().ToCharArray();
            }

            public string ReadString()
            {
                return this.ReadLine();
            }

            public string[] ReadStringArray()
            {
                return this.ReadLine().Split(' ').ToArray();
            }

            public Int64[] ReadInt64Array()
            {
                return this.ReadLine().Split(Separator).Select(Int64.Parse).ToArray();
            }

            public Double[] ReadDoubleArray()
            {
                return this.ReadLine().Split(Separator).Select(Double.Parse).ToArray();
            }
        }

        private abstract class SolverBase
        {
            protected readonly ExtendedReader _reader;
            protected readonly TextWriter _writer;

            protected SolverBase()
            {
#if DEBUG
                _reader = new ExtendedReader("input.txt");
                //_writer = new StreamWriter("output.txt");
                _writer = new StreamWriter(Console.OpenStandardOutput());
#else
                _reader = new ExtendedReader(Console.OpenStandardInput());
                _writer = new StreamWriter(Console.OpenStandardOutput());
#endif
            }

            public abstract Solver Solve();

            public abstract void OutputResult();
        }

        private class Solver : SolverBase
        {
            private bool result = false;

            public override Solver Solve()
            {
                // link to task: http://codeforces.com/problemset/problem/688/A

                var n = _reader.ReadInt();
                var s = _reader.ReadString();

                result = ShiftLeft(s) || ShiftRight(s) || ShiftUp(s) || ShiftDown(s);
                result = !result;

                return this;
            }

            private bool ShiftDown(string s)
            {
                return !s.Replace('0', '-').Replace('7', '-').Replace('9', '-').Contains("-");
            }

            private bool ShiftUp(string s)
            {
                return !s.Replace('1', '-').Replace('2', '-').Replace('3', '-').Contains("-");
            }

            private bool ShiftRight(string s)
            {
                return !s.Replace('0', '-').Replace('3', '-').Replace('6', '-').Replace('9', '-').Contains("-");
            }

            private bool ShiftLeft(string s)
            {
                return !s.Replace('0', '-').Replace('1', '-').Replace('4', '-').Replace('7', '-').Contains("-");
            }

            public override void OutputResult()
            {
                string answer = result ? "YES" : "NO";

                _writer.WriteLine(answer);
                _writer.Dispose();
            }
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string buf = Console.ReadLine();
            string st = Console.ReadLine();
            bool left, right, down, up;
            left = right = down = up = true;
            if (st.Contains("1") || st.Contains("4") || st.Contains("7") || st.Contains("0"))
            {
                left = false;
            }
            if (st.Contains("3") || st.Contains("6") || st.Contains("9") || st.Contains("0"))
            {
                right = false;
            }
            if (st.Contains("1") || st.Contains("2") || st.Contains("3"))
            {
                up = false;
            }
            if (st.Contains("7") || st.Contains("0") || st.Contains("9"))
            {
                down = false;
            }
            if (left || right || down || up)
            {
                Console.WriteLine("NO");
            }
            else
            {
                Console.WriteLine("YES");
            }
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;

namespace ConsoleApplication2
{
    class Program
    {

        private int n;
        private string s;
        private static int[,] pos = { { 3, 1 }, { 0, 0 }, { 0, 1 }, { 0, 2 }, { 1, 0 }, { 1, 1 }, { 1, 2 }, { 2, 0 }, { 2, 1 }, { 2, 2 } };

        public void ReadInput()
        {
            n = Convert.ToInt32(Console.ReadLine());
            s = Console.ReadLine();
        }

        public bool MatchRecursively(int curNum, int curStrPos)
        {
            if (curStrPos == s.Length - 1) return true;

            int num1 = (int)Char.GetNumericValue(s[curStrPos]);
            int num2 = (int)Char.GetNumericValue(s[curStrPos + 1]);
            int diff1 = pos[num2, 0] - pos[num1, 0];
            int diff2 = pos[num2, 1] - pos[num1, 1];
            int newCurPos1 = pos[curNum, 0] + diff1;
            int newCurPos2 = pos[curNum, 1] + diff2;
            int newCurNum;
            if (newCurPos1 >= 0 && newCurPos1 <= 3 && newCurPos2 >= 0 && newCurPos2 <= 2) newCurNum = newCurPos1 * 3 + newCurPos2 + 1;
            else return false;
            if (newCurNum >= 1 && newCurNum <= 9) return MatchRecursively(newCurNum, curStrPos + 1);
            else if (newCurNum == 11) return MatchRecursively(0, curStrPos + 1);
            else return false;

        }

        static void Main(string[] args)
        {

            bool fl = true;

            Program p = new Program();
            p.ReadInput();

            for (int i = 0; i <= 9; i++)
            {
                if (i == (int)Char.GetNumericValue(p.s[0])) continue;
                if (p.MatchRecursively(i, 0)) { Console.WriteLine("NO"); fl = false; break; }
            }

            if (fl) Console.WriteLine("YES");

        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _689A
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = Convert.ToInt32(Console.ReadLine());
            string s = Console.ReadLine();
            List<int> digits = new List<int>();

            int[] rows = { 3, 0, 0, 0, 1, 1, 1, 2, 2, 2 };
            int[] cols = { 1, 0, 1, 2, 0, 1, 2, 0, 1, 2 };

            for (int i = 0; i < n;i++)
            {
                if (!digits.Contains((int)(s[i] - '0'))) digits.Add((int)(s[i] - '0'));
            }

            int minrow = digits.Select(d => rows[d]).Min();
            int maxrow = digits.Select(d => rows[d]).Max();
            int mincol = digits.Select(d => cols[d]).Min();
            int maxcol = digits.Select(d => cols[d]).Max();

            if (minrow > 0 || maxrow < 2 || (mincol > 0 && maxrow < 3) || (maxcol < 2 && maxrow < 3) || (maxrow == 2 && !digits.Contains(7) && !digits.Contains(9)))
            {
                Console.WriteLine("NO");
            }
            else
            {
                Console.WriteLine("YES");
            }

        }
    }
}

using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;

namespace Olymp
{
  public class ProblemSolver
  {
    private Tokenizer input;

    public void Solve()
    {
      int n = input.NextInt();
      string s = input.NextToken();
      var r = new int[] { 4, 1, 1, 1, 2, 2, 2, 3, 3, 3 };
      var c = new int[] { 2, 1, 2, 3, 1, 2, 3, 1, 2, 3 };
      string[] m = new string[]
      {
        ".....",
        ".123.",
        ".456.",
        ".789.",
        "..0..",
        "....."
      };
      for (int dx = -1; dx <= 1; dx++)
      {
        for (int dy = -1; dy <= 1; dy++)
        {
          if (dx == 0 && dy == 0)
            continue;
          bool canShift = true;
          for (int i = 0; i < n; i++)
          {
            int d = s[i] - '0';
            if (m[r[d] + dx][c[d] + dy] == '.')
            {
              canShift = false;
              break;
            }
          }
          if (canShift)
          {
            Console.Write("NO");
            return;
          }
        }
      }
      Console.Write("YES");
    }

    public ProblemSolver(TextReader input)
    {
      this.input = new Tokenizer(input);
    }
  }

  #region Service classes

  public class Tokenizer
  {
    private TextReader reader;

    public int NextInt()
    {
      var c = SkipWS();
      if (c == -1)
        throw new EndOfStreamException();
      bool isNegative = false;
      if (c == '-' || c == '+')
      {
        isNegative = c == '-';
        c = this.reader.Read();
        if (c == -1)
          throw new InvalidOperationException();
      }
      if (!char.IsDigit((char)c))
        throw new InvalidOperationException();
      int result = (char)c - '0';
      c = this.reader.Read();
      while (c > 0 && !char.IsWhiteSpace((char)c))
      {
        if (!char.IsDigit((char)c))
          throw new InvalidOperationException();
        result = result * 10 + (char)c - '0';
        c = this.reader.Read();
      }
      if (isNegative)
        result = -result;
      return result;
    }

    public string ReadLine()
    {
      return reader.ReadLine();
    }

    public long NextLong()
    {
      return long.Parse(this.NextToken());
    }

    public double NextDouble()
    {
      return double.Parse(this.NextToken(), CultureInfo.InvariantCulture);
    }

    public int[] ReadIntArray(int n)
    {
      int[] a = new int[n];
      for (int i = 0; i < n; i++)
        a[i] = NextInt();
      return a;
    }

    public long[] ReadLongArray(int n)
    {
      long[] a = new long[n];
      for (int i = 0; i < n; i++)
        a[i] = NextLong();
      return a;
    }

    public double[] ReadDoubleArray(int n)
    {
      double[] a = new double[n];
      for (int i = 0; i < n; i++)
        a[i] = NextDouble();
      return a;
    }

    public string NextToken()
    {
      var c = SkipWS();
      if (c == -1)
        return null;
      var sb = new StringBuilder();
      while (c > 0 && !char.IsWhiteSpace((char)c))
      {
        sb.Append((char)c);
        c = this.reader.Read();
      }
      return sb.ToString();
    }

    private int SkipWS()
    {
      int c = this.reader.Read();
      if (c == -1)
        return c;
      while (c > 0 && char.IsWhiteSpace((char)c))
        c = this.reader.Read();
      return c;
    }

    public Tokenizer(TextReader reader)
    {
      this.reader = reader;
    }
  }

  class Program
  {
    public static void Main(string[] args)
    {
      var solver = new ProblemSolver(Console.In);
      solver.Solve();
    }
  }

  #endregion
}

using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Security;
using System.Security.Cryptography;

namespace ConsoleApplication1
{
	class Program
	{
		//DON'T FORGET TO SET IT TO FALSE BEFORE SUBMIT!!!!
		public const bool useFiles = false;

		private static StreamReader GetStandardInputStream()
		{
			return useFiles
				? new StreamReader(@"in.txt")
				: new StreamReader(Console.OpenStandardInput());
		}

		private static StreamWriter GetStandardOutputStream()
		{
			return useFiles
				? new StreamWriter(@"out.txt")
				: new StreamWriter(Console.OpenStandardOutput());
		}

		public class MyComparer : IComparer<Tuple<long, long>>
		{
			public int Compare(Tuple<long, long> x, Tuple<long, long> y)
			{
				if (x.Item2 > y.Item2)
				{
					return 1;
				}
				else if (x.Item2 == y.Item2)
				{
					if (x.Item1 > y.Item1)
					{
						return -1;
					}
					else if (x.Item1 == y.Item1)
					{
						return 0;
					}
					else
					{
						return 1;
					}
				}
				else
				{
					return -1;
				}
			}
		}

		public class Graph
		{
			private List<int>[] adj;

			public Graph(int n)
			{
				adj = new List<int>[n];

				for (int i = 0; i < n; i++)
				{
					adj[i] = new List<int>();
				}
			}

			public void AddEdge(int v, int w)
			{
				adj[v].Add(w);
				adj[w].Add(v);
			}

			public int[] GetAdj(int v)
			{
				return adj[v].ToArray();
			}

			public int V()
			{
				return adj.Count();
			}
		}

		public class WeightedNode
		{
			public int Weight { get; set; }

			public int A { get; set; }
			public int B { get; set; }

			public int GetOther(int s)
			{
				return A == s
					? B
					: A;
			}

			public override string ToString()
			{
				return string.Format("{0} -> {1} (W: {2})", this.A, this.B, this.Weight);
			}
		}

		public class WeightedGraph
		{
			private List<WeightedNode>[] adj;

			public WeightedGraph(int n)
			{
				adj = new List<WeightedNode>[n];

				for (int i = 0; i < n; i++)
					adj[i] = new List<WeightedNode>();
			}

			public void AddEdge(int x, int y, int w)
			{
				var node = new WeightedNode()
				{
					A = x,
					B = y,
					Weight = w
				};

				adj[x].Add(node);
				adj[y].Add(node);
			}

			public WeightedNode[] GetAdj(int v)
			{
				return adj[v].ToArray();
			}

			public int V()
			{
				return adj.Count();
			}
		}

		public class DFS
		{
			private Queue<int> q;
			private bool[] marked;
			private int[] distTo;

			public DFS(Graph g, int s)
			{
				q = new Queue<int>();
				marked = new bool[g.V()];
				distTo = new int[g.V()];

				q.Enqueue(s);
				marked[s] = true;
				distTo[s] = 0;

				while (q.Any())
				{
					var cur = q.Dequeue();
					var adj = g.GetAdj(cur);

					foreach (var v in adj)
					{
						if (!marked[v])
						{
							q.Enqueue(v);
							marked[v] = true;
							distTo[v] = distTo[cur] + 1;
						}
					}
				}
			}

			public int GetDistance(int v)
			{
				return marked[v] ? distTo[v] : -1;
			}
		}

		public class WeightedNodeComparor : IComparer<WeightedNode>
		{
			public int Compare(WeightedNode x, WeightedNode y)
			{
				var res = x.Weight.CompareTo(y.Weight);

				if (res != 0)
					return res;

				var r1 = x.A.CompareTo(y.A);
				var r2 = x.B.CompareTo(y.B);

				if (r1 == 0 && r2 == 0)
					return 0;

				return 1;
			}
		}

		public class PrimsMST
		{
			private bool[] marked;
			private List<WeightedNode> res;
			private SortedList<WeightedNode, WeightedNode> sl;

			public PrimsMST(WeightedGraph g, int s)
			{
				res = new List<WeightedNode>();
				marked = new bool[g.V()];
				sl = new SortedList<WeightedNode, WeightedNode>(new WeightedNodeComparor());

				marked[s] = true;
				Visit(g, s);

				while (sl.Any() && res.Count() < g.V() - 1)
				{
					var next = sl.First();
					sl.Remove(next.Key);

					var val = next.Value;

					if (marked[val.A] && marked[val.B])
						continue;

					res.Add(val);

					if (!marked[val.A])
					{
						marked[val.A] = true;
						Visit(g, val.A);
					}

					if (!marked[val.B])
					{
						marked[val.B] = true;
						Visit(g, val.B);
					}

				}

			}

			public void Visit(WeightedGraph g, int s)
			{
				foreach (var v in g.GetAdj(s))
				{
					if (!marked[v.GetOther(s)])
						sl.Add(v, v);
				}
			}

			public List<WeightedNode> GetMST()
			{
				return res;
			}

		}

		public class DoubleComaprer : IComparer<double>
		{
			public int Compare(double x, double y)
			{
				return x.CompareTo(y);
			}
		}

		public struct TempItem
		{
			public long Weight { get; set; }
			public int Vertex { get; set; }
		}

		public class TempItemComparer : IComparer<TempItem>
		{
			public int Compare(TempItem x, TempItem y)
			{
				var r = x.Weight.CompareTo(y.Weight);

				if (r != 0)
					return r;

				var r2 = x.Vertex.CompareTo(y.Vertex);
				return r2;
			}
		}

		public class DejkstraSP
		{
			public long?[] distTo;
			private int[] edgeTo;
			private SortedList<TempItem, int> pq;

			public DejkstraSP(WeightedGraph g, int s)
			{
				distTo = new long?[g.V()];
				edgeTo = new int[g.V()];
				pq = new SortedList<TempItem, int>(new TempItemComparer());

				distTo[s] = 0;

				pq.Add(new TempItem() { Vertex = s, Weight = 0 }, s);
				while (pq.Any())
				{
					var v = pq.First();
					pq.Remove(v.Key);

					foreach (var edge in g.GetAdj(v.Value))
					{
						relax(edge, v.Value);
					}
				}
			}

			private void relax(WeightedNode v, int cur)
			{
				int a = cur;
				int b = v.GetOther(cur);

				if (distTo[b] == null || distTo[b] > distTo[a] + v.Weight)
				{
					distTo[b] = distTo[a] + v.Weight;
					edgeTo[b] = a;

					if (pq.ContainsValue(b))
					{
						var val = pq.First(x => x.Value == b);
						pq.Remove(val.Key);
						pq.Add(new TempItem() { Vertex = b, Weight = distTo[b].Value }, b);

					}
					else
					{
						pq.Add(new TempItem() { Vertex = b, Weight = distTo[b].Value }, b);
					}
				}
			}
		}

		static void Main(string[] args)
		{
			using (var input = GetStandardInputStream())
			using (var output = GetStandardOutputStream())
			{
				var n = ParseInt(input);
				var otherNums = input.ReadLine().ToCharArray().Select(x => int.Parse(x.ToString())).ToArray();

				var arr = new bool[10];

				foreach (var otherNum in otherNums)
				{
					arr[otherNum] = true;
				}

				var flag1 = false;
				var flag2 = false;

				if ((arr[1] || arr[2] || arr[3]) && (arr[7] || arr[9]))
					flag1 = true;

				if ((arr[1] || arr[2] || arr[3]) && arr[0])
				{
					output.WriteLine("YES");
					return;
				}

				if ((arr[1] || arr[4] || arr[7]) && (arr[3] || arr[6] || arr[9]))
					flag2 = true;

				if (flag1 && flag2)
					output.WriteLine("YES");
				else
				{
					output.WriteLine("NO");
				}

			}
		}

		private static double getDist(Tuple<int, int> c1, Tuple<int, int> c2)
		{
			return Math.Sqrt(Math.Pow(c1.Item1 - c2.Item1, 2.0) + Math.Pow(c1.Item2 - c2.Item2, 2.0));
		}

		private static Tuple<int, int> GetCoord(int number)
		{
			if (number == 0)
				return new Tuple<int, int>(1,3);

			var y = (number - 1) / 3;
			var x = number - (y*3) - 1;

			return new Tuple<int, int>(x,y);
		}

		private static long Factorial(int numb)
		{
			if (numb == 0)
				return 1;

			long res = 1;
			for (int i = numb; i > 1; i--)
				res *= i;
			return res;
		}

		private static double partialSum(double p, double q)
		{
			if (Math.Abs(p - 1) < double.Epsilon)
				return 1;

			double a = p,
				d = p,
				r = q;

			var res = (a/(1 - r)) + ((r*d)/((1 - r)*(1 - r)));
			return res;
		}

		public class Clusters
		{
			private bool[] marked;
			private Stack<int> st;
			public int count;

			private int[,] fromStr(string[] zombies)
			{
				var n = zombies.Length;
				var matrix = new int[n, n];
				int i = 0;

				foreach (var str in zombies)
				{
					var inStr = str;
					var ar = new List<int>();

					foreach (var c in inStr)
					{
						ar.Add(int.Parse(c.ToString()));
					}

					for (var j = 0; j < n; j++)
					{
						matrix[i, j] = ar[j];
					}
					i++;
				}

				return matrix;
			}
			public Clusters(string[] zmb_str)
			{
				var n = zmb_str.Count();
				var zombies = fromStr(zmb_str);
				st = new Stack<int>();
				marked = new bool[n];
				count = 0;

				for (int v = 0; v < n; v++)
				{
					if (!marked[v])
						dfs(ref zombies, v, n);
				}

				marked = new bool[n];
				foreach (var e in reverserPostOrder())
				{
					if (!marked[e])
					{
						dfs(ref zombies, e, n);
						count++;
					}
				}
			}

			private void dfs(ref int[,] g, int v, int n)
			{
				marked[v] = true;
				foreach (var e in getAdj(ref g, v, n))
				{
					if (!marked[e]) dfs(ref g, e, n);
				}
				st.Push(v);
			}

			private int[] getAdj(ref int[,] g, int v, int n)
			{
				var res = new List<int>();
				for (int i = 0; i < n; i++)
				{
					if (i == v)
						continue;

					if (g[v, i] == 1)
					{
						res.Add(i);
					}
				}

				return res.ToArray();
			}

			public int[] reverserPostOrder()
			{
				return st.ToArray();
			}
		}

		private static int binarySearch(ref long[] ar, int l, int h, long key)
		{
			if (l >= h)
				return -1;

			var mid = (l + h) / 2;

			if (ar[mid] == key)
				return mid;

			if (key > ar[mid])
				return binarySearch(ref ar, mid+1, h, key);

			return binarySearch(ref ar, 0, mid, key);
		}

		private static int[] ParseIntString(StreamReader input)
		{
			return input.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
		}

		private static int ParseInt(StreamReader input)
		{
			return int.Parse(input.ReadLine());
		}

		private static long primaryDiagSum(ref int[][] a, int n)
		{
			long sum = 0;
			for (var i = 0; i < n; i++)
				sum += a[i][i];

			return sum;
		}

		private static long secondaryDiagSum(ref int[][] a, int n)
		{
			long sum = 0;
			for (var i = 0; i < n; i++)
				sum += a[i][n - i - 1];

			return sum;
		}

		private static int GetIdx(int n, int lastAns, int x)
		{
			return (x ^ lastAns) % n;
		}

		private static int getHourGlassSum(ref int[][] ar, int x, int y)
		{
			var sum = 0;

			sum += ar[x][y];
			sum += ar[x][y + 1];
			sum += ar[x][y + 2];

			sum += ar[x + 1][y + 1];

			sum += ar[x + 2][y];
			sum += ar[x + 2][y + 1];
			sum += ar[x + 2][y + 2];

			return sum;
		}

		private static long sumFrom(int start, ref long[] sums, long totalSum)
		{
			if (start >= sums.Length)
				return 0;

			return totalSum - sums[start - 1];
		}

		public int ReadSingleInt(StreamReader input)
		{
			var line = input.ReadLine();
			return int.Parse(line);
		}

		public string ReadString()
		{
			return Console.ReadLine();
		}

		public int[] ReadInts(char sep = ' ')
		{
			var line = Console.ReadLine();
			var arr = line.Split(sep).Select(x => int.Parse(x)).ToArray();

			return arr;
		}

	}
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CSLearning
{
    internal class cf361
    {
        public static bool CanDown(string str)
        {
            if (str.Contains("7") || str.Contains("0") || str.Contains("9"))
                return false;
            else
                return true;
        }

        public static bool CanUp(string str)
        {
            if (str.Contains("1") || str.Contains("2") || str.Contains("3"))
                return false;
            else
                return true;
        }

        public static bool CanLeft(string str)
        {
            if (str.Contains("1") || str.Contains("4") || str.Contains("7") || str.Contains("0"))
                return false;
            else
                return true;
        }

        public static bool CanRight(string str)
        {
            if (str.Contains("3") || str.Contains("6") || str.Contains("9") || str.Contains("0"))
                return false;
            else
                return true;
        }

        private static void Main(string[] args)
        {
            var n = Convert.ToInt32(Console.ReadLine());
            var str = Console.ReadLine();
            if (CanUp(str) || CanDown(str) || CanLeft(str) || CanRight(str))
                Console.WriteLine("NO");
            else
                Console.WriteLine("YES");
            //Console.ReadKey();
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace a
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            string s = Console.ReadLine();

            bool[] ls = new bool[10];
            for (int i = 0; i < s.Length; i++)
            {
                ls[s[i] - '0'] = true;
            }
            bool[] yoko = new bool[3];
            bool[] tate = new bool[4];

            if(ls[0])
            {
                yoko[1] = true;
                tate[3] = true;
            }

            for (int i = 1; i < 10; i++)
            {
                if(ls[i])
                {
                    yoko[(i - 1) % 3] = true;
                    tate[(i - 1) / 3] = true;
                }
            }
            if (tate[3])//0
            {
                if (tate[0])
                {
                    Console.WriteLine("YES");
                    return;
                }
                else
                {
                    Console.WriteLine("NO");
                    return;
                }
            }
            if((tate[0]&&tate[2]) && yoko[0]&&yoko[2])
            {
                if (ls[7] || ls[9])
                {
                    Console.WriteLine("YES");
                    return;
                }
                else
                {
                    Console.WriteLine("NO");
                    return;
                }
            }
            else
            {
                Console.WriteLine("NO");
                return;
            }

        }
    }
}

using System;
using System.IO;
using System.Text;

namespace Mike_and_Cellphone
{
    internal class Program
    {
        private static readonly StreamReader reader = new StreamReader(Console.OpenStandardInput(1024*10), Encoding.ASCII, false, 1024*10);
        private static readonly StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(1024*10), Encoding.ASCII, 1024*10);

        private static void Main(string[] args)
        {
            string s = reader.ReadLine();
            s = reader.ReadLine();

            var keyboard = new char[10][];
            keyboard[0] = ".......".ToCharArray();
            keyboard[1] = ".......".ToCharArray();
            keyboard[2] = ".......".ToCharArray();
            keyboard[3] = "..123..".ToCharArray();
            keyboard[4] = "..456..".ToCharArray();
            keyboard[5] = "..789..".ToCharArray();
            keyboard[6] = "...0...".ToCharArray();
            keyboard[7] = ".......".ToCharArray();
            keyboard[8] = ".......".ToCharArray();
            keyboard[9] = ".......".ToCharArray();

            var x = new int[s.Length];
            var y = new int[s.Length];

            for (int i = 0; i < s.Length; i++)
            {
                for (int j = 3; j <= 6; j++)
                {
                    for (int k = 2; k < 5; k++)
                    {
                        if (s[i] == keyboard[j][k])
                        {
                            x[i] = j;
                            y[i] = k;
                            goto mbox;
                        }
                    }
                }
                mbox:
                ;
            }

            for (int j = 3; j <= 6; j++)
            {
                for (int k = 2; k < 5; k++)
                {
                    if (keyboard[j][k] != '.' && keyboard[j][k] != s[0])
                    {
                        int xx = j, yy = k;
                        bool ok = true;
                        for (int i = 1; i < x.Length; i++)
                        {
                            xx += x[i] - x[i - 1];
                            yy += y[i] - y[i - 1];

                            if (keyboard[xx][yy] == '.')
                            {
                                ok = false;
                                break;
                            }
                        }
                        if (ok)
                        {
                            writer.WriteLine("NO");
                            writer.Flush();
                            return;
                        }
                    }
                }
            }

            writer.WriteLine("YES");
            writer.Flush();
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _689A
{
    class Program
    {
        struct Vector { public int X, Y; }

        static void Main()
        {
            int n = int.Parse(Console.ReadLine());
            string number = Console.ReadLine();
            var numberVectors = new Vector[n];
            numberVectors[0] = new Vector() { X = 0, Y = 0 };
            Tuple<int, int> startCoords = NumberToCoords(int.Parse(number.Substring(0, 1)));
            for (int i = 1; i < n; i++)
            {
                int previous = int.Parse(number.Substring(i - 1, 1));
                int current = int.Parse(number.Substring(i, 1));
                Tuple<int, int> prevCoords = NumberToCoords(previous), currCoords = NumberToCoords(current);
                Vector currVector = new Vector()
                {
                    X = currCoords.Item1 - prevCoords.Item1,
                    Y = currCoords.Item2 - prevCoords.Item2
                };
                numberVectors[i] = currVector;
            }

            bool result = true;
            for (int startX = 0; startX < 3; startX++)
            {
                for (int startY = 0; startY < 4; startY++)
                {
                    if ((startY == 3 && (startX == 0 || startX == 2)) ||
                        (startX == startCoords.Item1 && startY == startCoords.Item2))
                        continue;

                    bool correct = true;
                    int x = startX, y = startY;
                    foreach (var vector in numberVectors)
                    {
                        x += vector.X; y += vector.Y;
                        if (x < 0 || x > 2 || y < 0 || y > 3 || (y == 3 && (x == 0 || x == 2)))
                        {
                            correct = false;
                            break;
                        }
                    }

                    if (correct)
                    {
                        result = false;
                        break;
                    }
                }
            }

            Console.WriteLine(result ? "YES" : "NO");
            //Console.ReadLine();
        }

        static Tuple<int, int> NumberToCoords(int number)
        {
            switch (number)
            {
                case 0: return new Tuple<int, int>(1, 3);
                case 1: return new Tuple<int, int>(0, 0);
                case 2: return new Tuple<int, int>(1, 0);
                case 3: return new Tuple<int, int>(2, 0);
                case 4: return new Tuple<int, int>(0, 1);
                case 5: return new Tuple<int, int>(1, 1);
                case 6: return new Tuple<int, int>(2, 1);
                case 7: return new Tuple<int, int>(0, 2);
                case 8: return new Tuple<int, int>(1, 2);
                case 9: return new Tuple<int, int>(2, 2);
                default: return null;
            }
        }
    }
}

using System;
using System.Globalization;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Threading;

namespace Codeforces
{
    class Program : ProgramBase
    {
        private const long commonMod = 1000000007;

        static void Main(string[] args)
        {
            var p = new Program();
            var x = p.Get();
            p.Out(x);
        }

        object Get()
        {
            checked
            {
                var n = ReadIntToken();
                var num = Read();
                if (!num.Contains("7") && !num.Contains("0") && !num.Contains("9"))
                    return "NO";
                if (!num.Contains("1") && !num.Contains("2") && !num.Contains("3"))
                    return "NO";
                if (!num.Contains("1") && !num.Contains("4") && !num.Contains("7") && !num.Contains("0"))
                    return "NO";

                if (!num.Contains("3") && !num.Contains("6") && !num.Contains("9") && !num.Contains("0"))
                    return "NO";
                return "YES";
            }
        }
        public struct Pair<T1, T2>
        {
            public T1 Item1 { get; set; }
            public T2 Item2 { get; set; }
            public static Pair<T1, T2> Create(T1 item1, T2 item2)
            {
                return new Pair<T1, T2> { Item1 = item1, Item2 = item2 };
            }
        }

        class Automata
        {
            bool[] terminals;
            public int sigma;
            public int len;
            public int[,] jumps;

            public void Create()
            {
                var a = ReadInts();
                len = a[0];
                sigma = a[2];
                var ts = ReadInts();
                terminals = new bool[len];
                for (int i = 0; i < ts.Length; i++)
                    terminals[ts[i]] = true;
                jumps = new int[len, sigma];
                for (int i = 0; i < len * sigma; i++)
                {
                    var b = Console.ReadLine().Split(' ');
                    jumps[Convert.ToInt32(b[0]), b[1][0] - 'a'] = Convert.ToInt32(b[2]);
                }
            }
            protected int[] ReadInts()
            {
                return Console.ReadLine().Split(' ').Select(x => Convert.ToInt32(x)).ToArray();
            }

            public bool IsTerminal(int s)
            {
                return terminals[s];
            }
        }
    }

    abstract class ProgramBase
    {
        bool? prod = null;
        StreamReader f;
        Queue<string> tokens;
        protected string FileName { private get; set; }

        protected string Read()
        {
            if (f == null)
                f = string.IsNullOrEmpty(FileName)
                    ? new StreamReader(Console.OpenStandardInput())
                    : new StreamReader((GetProd() ? "" : "c:\\dev\\") + FileName);
            return f.ReadLine();
        }

        protected string ReadToken()
        {
            if (tokens == null || tokens.Count == 0)
                tokens = new Queue<string>(Read().Split(' '));
            return tokens.Dequeue();
        }
        protected int ReadInt() { return int.Parse(Read()); }

        protected int ReadIntToken() { return int.Parse(ReadToken()); }

        protected int[] ReadInts()
        {
            var tokens = Read().Split(' ');
            var result = new int[tokens.Length];
            for (int i = 0; i < tokens.Length; i++)
                result[i] = int.Parse(tokens[i]);
            return result;
        }

        protected long ReadLongToken() { return long.Parse(ReadToken()); }

        protected long ReadLong() { return long.Parse(Read()); }

        protected long[] ReadLongs()
        {
            var tokens = Read().Split(' ');
            var result = new long[tokens.Length];
            for (int i = 0; i < tokens.Length; i++)
                result[i] = long.Parse(tokens[i]);
            return result;
        }

        public void Out(object r)
        {
            if (string.IsNullOrEmpty(FileName))
                Console.WriteLine(r);
            else if (GetProd())
                File.WriteAllText(FileName, r.ToString());
            else
                Console.WriteLine(r);
        }

        private bool GetProd()
        {

            if (!prod.HasValue)
                try
                {
                    prod = Environment.MachineName != "RENADEEN-W7";
                }
                catch (Exception)
                {
                    prod = true;
                }
            return prod.Value;
        }
    }

    public static class Huj
    {
        public static T MinBy<T>(this IEnumerable<T> source, Func<T, double> func) where T : class
        {
            T result = null;
            var min = double.MaxValue;
            foreach (var item in source)
            {
                var current = func(item);
                if (min > current)
                {
                    min = current;
                    result = item;
                }
            }
            return result;
        }

        public static T MaxBy<T>(this IEnumerable<T> source, Func<T, double> func, T defaultValue = default(T))
        {
            T result = defaultValue;
            var max = double.MinValue;
            foreach (var item in source)
            {
                var current = func(item);
                if (max < current)
                {
                    max = current;
                    result = item;
                }
            }
            return result;
        }

        public static string JoinStrings(this IEnumerable<string> source, string delimeter)
        {
            return string.Join(delimeter, source.ToArray());
        }

        public static string JoinStrings(this IEnumerable<int> source, string delimeter)
        {
            return source.Select(x => x.ToString()).JoinStrings(delimeter);
        }
    }
}

using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;

namespace CF317
{
	internal class Program
	{
		private static void Main(string[] args)
		{
			var sr = new InputReader(Console.In);
			//var sr = new InputReader(new StreamReader("input.txt"));
			var task = new Task();
			using (var sw = Console.Out)
			//using (var sw = new StreamWriter("output.txt"))
			{
				task.Solve(sr, sw);
				//Console.ReadKey();
			}
		}
	}

	internal class Task
	{
		public void Solve(InputReader sr, TextWriter sw)
		{
			var n = sr.NextInt32();
			var number = sr.NextString();
			var matrix = new[,] {
				{ '1', '2', '3' },
				{ '4', '5', '6' },
				{ '7', '8', '9' },
				{ '?', '0', '?' }
			};
			var operations = new List<Tuple<int, int>>();
			var sourceI = 0;
			var sourceJ = 0;
			for (var i = 0; i < n; i++) {
				var digit = number[i];
				var currI = 0;
				var currJ = 0;
				for (var k = 0; k < 4; k++) {
					for (var l = 0; l < 3; l++) {
						if (matrix[k, l] == digit) {
							currI = k;
							currJ = l;
						}
					}
				}
				if (operations.Count == 0) {
					operations.Add(new Tuple<int, int>(currI, currJ));
					sourceI = currI;
					sourceJ = currJ;
				}
				else {
					operations.Add(new Tuple<int, int>(currI - sourceI, currJ - sourceJ));
					sourceI = currI;
					sourceJ = currJ;
				}
			}
			var canCount = 0;
			for (var k = 0; k < 4; k++) {
				for (var l = 0; l < 3; l++) {
					if (k == 3 && l != 1) {
						continue;
					}
					var currI = k;
					var currJ = l;
					var can = true;
					for (var i = 1; i < operations.Count; i++) {
						var next = operations[i];
						if (!Can(currI, next.Item1, currJ, next.Item2)) {
							can = false;
							break;
						}
						else {
							currI += next.Item1;
							currJ += next.Item2;
						}
					}
					if (can) {
						canCount++;
					}
				}
			}

			if (canCount > 1) {
				sw.WriteLine("NO");
			}
			else {
				sw.WriteLine("YES");
			}
		}

		private bool Can(int i,int dI, int j, int dJ)
		{
			if (i + dI == 3) {
				if (j + dJ == 1) {
					return true;
				}
				else {
					return false;
				}
			}

			if (i + dI >= 0 && i + dI < 3 && j + dJ >= 0 && j + dJ < 3)
				return true;

			return false;
		}
	}
}

internal class InputReader : IDisposable
{
	private bool isDispose;
	private readonly TextReader sr;

	public InputReader(TextReader stream)
	{
		sr = stream;
	}

	public void Dispose()
	{
		Dispose(true);
		GC.SuppressFinalize(this);
	}

	public string NextString()
	{
		var result = sr.ReadLine();
		return result;
	}

	public int NextInt32()
	{
		return Int32.Parse(NextString());
	}

	public long NextInt64()
	{
		return Int64.Parse(NextString());
	}

	public string[] NextSplitStrings()
	{
		return NextString()
			.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
	}

	public T[] ReadArray<T>(Func<string, CultureInfo, T> func)
	{
		return NextSplitStrings()
			.Select(s => func(s, CultureInfo.InvariantCulture))
			.ToArray();
	}

	public T[] ReadArrayFromString<T>(Func<string, CultureInfo, T> func, string str)
	{
		return
			str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
				.Select(s => func(s, CultureInfo.InvariantCulture))
				.ToArray();
	}

	protected void Dispose(bool dispose)
	{
		if (!isDispose) {
			if (dispose)
				sr.Close();
			isDispose = true;
		}
	}

	~InputReader()
	{
		Dispose(false);
	}
}

using System;
using System.Collections.Generic;

namespace a
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            string s = Console.ReadLine();
            bool b1 = false, b2 = false, b3 = false, b4 = false, b5 = false;
            for (int i = 0; i < n; i++)
            {
                int c = s[i] - '0';
                if (c == 1 || c == 4 || c == 7)
                {
                    b1 = true;
                }
                if (c == 3 || c == 6 || c == 9)
                {
                    b2 = true;
                }
                if (c == 1 || c == 2 || c == 3)
                {
                    b3 = true;
                }
                if (c == 7 || c == 0 || c == 9)
                {
                    b4 = true;
                }
                if (c == 0)
                {
                    b5 = true;
                }
            }
            bool r = b1 && b2 && b3 && b4 || (b5 && b3);
            Console.WriteLine(r ? "YES" : "NO");
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _689A
{
    class Program
    {
        static void Main(string[] args)
        {
            Solution sol = new Solution();
            int n = int.Parse(Console.ReadLine());
            string str = Console.ReadLine();
            Console.WriteLine(sol.GetOtherNumber(str) ? "YES" : "NO");
        }
    }

    public class Solution
    {
        IDictionary<int, int[]> mp = new Dictionary<int, int[]>()
        {
            { '0', new [] { 0, 1 } },
            { '1', new [] { 3, 0 } },
            { '2', new [] { 3, 1 } },
            { '3', new [] { 3, 2 } },
            { '4', new [] { 2, 0 } },
            { '5', new [] { 2, 1 } },
            { '6', new [] { 2, 2 } },
            { '7', new [] { 1, 0 } },
            { '8', new [] { 1, 1 } },
            { '9', new [] { 1, 2 } }
        };

        public bool GetOtherNumber(string n)
        {
            List<int[]> steps = new List<int[]>();

            for (int i = 1; i < n.Length; ++i)
                steps.Add(new[] { mp[n[i]][0] - mp[n[i - 1]][0], mp[n[i]][1] - mp[n[i - 1]][1] });

            bool fl = true;
            for(int i = 0; i < 10; ++i, fl = true)
            {
                if (i == n[0] - '0')
                    continue;

                int x = mp[i + '0'][0];
                int y = mp[i + '0'][1];
                int j = 0;
                for (; j < steps.Count; j++)
                {
                    x += steps[j][0];
                    y += steps[j][1];
                    if (OutOfTheBox(x, y))
                    {
                        fl = false;
                        break;
                    }
                }
                if (fl)
                    return false;
            }
            return true;
        }

        public bool OutOfTheBox(int x, int y)
        {
            if (x == 0 && y == 1)
                return false;
            return x <= 0 || x > 3 || y < 0 || y > 2;
        }
    }
}

/* Date: 29.01.2019 * Time: 21:45 */
//

/*
�	fflush(stdout) � ����� C++;
�	System.out.flush() � Java;
�	stdout.flush() � Python;
�	flush(output) � Pascal;

*/

using System;
using System.Globalization;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

class Example
{
	public static void Main (string[] args)
	{
# if ( ! ONLINE_JUDGE )
		StreamReader sr = new StreamReader ("C:\\TRR\\2019\\Task\\07 Codeforces\\000\\A.TXT");
		StreamWriter sw = new StreamWriter ("C:\\TRR\\2019\\Task\\07 Codeforces\\000\\A.OUT");
# endif

		NumberFormatInfo nfi = NumberFormatInfo.InvariantInfo;

		int n;

# if ( ONLINE_JUDGE )
		n = int.Parse (Console.ReadLine ());
# else
		n = int.Parse (sr.ReadLine ());
# endif

		string s;

# if ( ONLINE_JUDGE )
		s = Console.ReadLine ();
# else
		s = sr.ReadLine ();
		sw.WriteLine (s);
# endif

		bool ok = true;
		int [] a = new int [n];
		for ( int i=0; i < s.Length; i++ )
		{
			a [i] = (s [i].GetHashCode ()) % 256;
# if ( ! ONLINE_JUDGE )
			sw.Write (a [i] + " ");
# endif
		}

		bool up=true, left=true, right=true, down=true;
		for ( int i=0; i < s.Length; i++ )
		{
			if ( s [i] == '7' || s [i] == '0' || s [i] == '9' )
				down = false;
			if ( s [i] == '1' || s [i] == '2' || s [i] == '3' )
				up = false;
			if ( s [i] == '1' || s [i] == '4' || s [i] == '7' || s [i] == '0' )
				left = false;
			if ( s [i] == '3' || s [i] == '6' || s [i] == '9' || s [i] == '0' )
				right = false;
		}

		ok = (down || up || left || right);

# if ( ONLINE_JUDGE )
		if ( ok )
			Console.WriteLine ("NO");
		else
			Console.WriteLine ("YES");
# else
		sw.WriteLine ();
		if ( ok )
			sw.WriteLine ("NO");
		else
			sw.WriteLine ("YES");
		sw.Close ();
# endif

	}
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class cf1
{
    static void Main()
    {
        int int_digits = int.Parse(Console.ReadLine());
        string str_number = Console.ReadLine();
        string str_result = "NO";

        int digit2;
        bool b_half1 = false;
        bool b_half2 = false;

        foreach (char digit in str_number)
        {
            digit2 = int.Parse(digit.ToString());
            switch (digit2)
            {
                case 1:
                    if (str_number.Contains("9") || str_number.Contains("0"))
                    {
                        str_result = "YES";
                    }
                    if (str_number.Contains("3")||str_number.Contains("6"))
                    {
                        b_half1 = true;
                    }
                    if (str_number.Contains("7"))
                    {
                        b_half2 = true;
                    }
                    break;
                case 2:
                    if (str_number.Contains("0"))
                    {
                        str_result = "YES";
                    }
                    if (str_number.Contains("7") || str_number.Contains("9"))
                    {
                        b_half2 = true;
                    }
                    break;
                case 3:
                    if (str_number.Contains("0") || str_number.Contains("7"))
                    {
                        str_result = "YES";
                    }
                    if (str_number.Contains("7") || str_number.Contains("9"))
                    {
                        b_half2 = true;
                    }
                    break;
                case 4:
                    if (str_number.Contains("6")||str_number.Contains("3")||str_number.Contains("9"))
                    {
                        b_half1 = true;
                    }
                    break;
                case 7:
                    if (str_number.Contains("9")||str_number.Contains("3")||str_number.Contains("6"))
                    {
                        b_half1 = true;
                    }
                    break;
            }
        }
        if (b_half1==true & b_half2 == true)
        {
            str_result = "YES";
        }
        Console.WriteLine(str_result);
    }
}

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AlgoTraining.Codeforces.A_s
{
    public class FastScanner : StreamReader
    {
        private string[] _line;
        private int _iterator;

        public FastScanner(Stream stream) : base(stream)
        {
            _line = null;
            _iterator = 0;
        }
        public int NextInt()
        {
            if (_line == null || _iterator >= _line.Length)
            {
                _line = base.ReadLine().Split(' ');
                _iterator = 0;
            }
            if (_line.Count() == 0) throw new IndexOutOfRangeException("Input string is empty");
            return Convert.ToInt32(_line[_iterator++]);
        }
        public long NextLong()
        {
            if (_line == null || _iterator >= _line.Length)
            {
                _line = base.ReadLine().Split(' ');
                _iterator = 0;
            }
            if (_line.Count() == 0) throw new IndexOutOfRangeException("Input string is empty");
            return Convert.ToInt64(_line[_iterator++]);
        }
    }
    class MikeAndPhone361
    {
        private static int[,] digits = new int[4, 3]
        {
            {1, 2, 3},
            {4, 5, 6},
            {7, 8, 9},
            {-1, 0, -1},
        };

        public static void Main(string[] args)
        {
            using (FastScanner fs = new FastScanner(new BufferedStream(Console.OpenStandardInput())))
            using (StreamWriter writer = new StreamWriter(new BufferedStream(Console.OpenStandardOutput())))
            {
                int n = fs.NextInt();
                int[] a = new int[n];
                List<int[]> d = new List<int[]>();
                string s = fs.ReadLine();
                for (int i = 0; i < n; i++)
                {
                    a[i] = int.Parse("" + s[i]);
                    if (i > 0) d.Add(GetDiff(a[i - 1], a[i]));
                }

                for (int i = 0; i < 4; i++)
                {
                    for (int j = 0; j < 3; j++)
                    {
                        if (digits[i, j] == a[0]) continue;
                        if (digits[i, j] != -1 && IsValid(i, j, d))
                        {
                            writer.WriteLine("NO");
                            return;
                        }
                    }
                }
                writer.WriteLine("YES");
            }
        }
        private static bool IsValid(int i, int j, List<int[]> d)
        {
            try
            {
                foreach (int[] v in d)
                {
                    i += v[0];
                    j += v[1];
                    if (digits[i, j] == -1) return false;
                }
                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }

        private static int[] GetDiff(int d1, int d2)
        {
            int i1 = 0, i2 = 0, j1 = 0, j2 = 0;
            for (int i = 0; i < 4; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    if (digits[i, j] == d1)
                    {
                        i1 = i;
                        j1 = j;
                    }
                    if (digits[i, j] == d2)
                    {
                        i2 = i;
                        j2 = j;
                    }
                }
            }
            return new int[] { i2 - i1, j2 - j1 };
        }
    }
}

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
class Solution
{

  static void Main(String[] args)
  {
    string[] valid = new string[8] {
      "0000000",
      "0000000",
      "0011100",
      "0011100",
      "0011100",
      "0001000",
      "0000000",
      "0000000"
    };
    int[] row = new int[] {5,2,2,2,3,3,3,4,4,4};
    int[] col = new int[] {3,2,3,4,2,3,4,2,3,4};

    int count = int.Parse(Console.ReadLine());
    string digits = Console.ReadLine();
    bool found = false;
    for (int i = 0; i < 10; ++i)
    {
      bool v = true;
      int idx = (int)digits[0]-(int)'0';
      int or = row[idx]-row[i];
      int oc = col[idx]-col[i];
      if (or == 0 && oc == 0)
      {
        continue;
      }
      for (int j = 0; j < count; ++j)
      {
        idx = (int)digits[j]-(int)'0';
        int ir = row[idx] - or;
        int ic = col[idx] - oc;
        if (ir<0 || ir>7 || ic < 0 || ic > 6 || valid[ir][ic] == '0')
        {
          v = false;
          break;
        }
      }
      if (v)
      {
        found = true;
        break;
      }
    }
    if (found)
    {
      Console.WriteLine("NO");
    }
    else
    {
      Console.WriteLine("YES");
    }
  }
}

using System;
using System.Collections;
using System.Collections.Generic;

namespace A
{
    class Program
    {
        public class TupleList<T1, T2, T3> : List<Tuple<int, int, string>>
        {
            public void Add(int item1, int item2, string s)
            {
                Add(new Tuple<int, int, string>(item1, item2, s));
            }
        }
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            string input = Console.ReadLine();
            int most_left = 2;
            int most_right = 0;
            int most_up = 4;
            int most_down = 1;
            bool is_8_only_most_down = false;

            for(int i = 0; i< n; i++)
            {
                int input_number = 0;
                if (input[i] - '0' == 0) input_number = 11;
                else input_number = input[i] - '0';
                if (most_right != 2 && (input_number-1) % 3 > most_right) most_right = (input_number-1)%3;
                if (most_left != 0 && (input_number-1) % 3 < most_left) most_left= (input_number-1) % 3;
                if (most_up != 1 && (input_number+2) / 3 < most_up) most_up = (input_number+2)/3;
                if (most_down != 4 && (input_number+2) / 3 > most_down) most_down = (input_number+2)/3;
                if (!is_8_only_most_down && input_number == 8 && most_down <= 3) is_8_only_most_down = true;
                if (input_number == 7 || input_number == 9) is_8_only_most_down = false;
                if (input_number == 11) is_8_only_most_down = false;
            }

            if (most_right - most_left == 2 && most_down - most_up == 2)
            {
                if (most_up == 2) Console.WriteLine("NO");
                else if (is_8_only_most_down) Console.WriteLine("NO");
                else Console.WriteLine("YES");
            }
            else if (most_down - most_up == 3) Console.WriteLine("YES");
            else Console.WriteLine("NO");

        }
    }
}

using System;
using System.Collections.Generic;
using System.IO;

namespace prA {
    class Program {
#if ONLINE_JUDGE
        private static readonly StreamReader reader = new StreamReader(Console.OpenStandardInput(1024 * 10), System.Text.Encoding.ASCII, false, 1024 * 10);
        private static readonly StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(1024 * 10), System.Text.Encoding.ASCII, 1024 * 10);
#else
        private static readonly StreamWriter writer = new StreamWriter(@"..\..\output");
        private static readonly StreamReader reader = new StreamReader(@"..\..\input");
#endif

        static void Main(string[] args) {
            int[] x = {2, 1, 2, 3, 1, 2, 3, 1, 2, 3};
            int[] y = {4, 1, 1, 1, 2, 2, 2, 3, 3, 3};
            int n = Next();
            reader.ReadLine();
            string s = reader.ReadLine();
            int[] dx = new int[n - 1];
            int[] dy = new int[n - 1];
            for (int i = 1; i < n; i++) {
                int cur = s[i] - '0';
                int prev = s[i - 1] - '0';
                dx[i - 1] = x[cur] - x[prev];
                dy[i - 1] = y[cur] - y[prev];
            }
            int ans = 0;
            for (int i = 0; i <= 9; i++) {
                bool good = true;
                int cx = x[i];
                int cy = y[i];
                for (int j = 0; j < n - 1 && good; j++) {
                    cx += dx[j];
                    cy += dy[j];
                    if (cx < 1 || cx > 3)
                        good = false;
                    if (cy < 1 || cy > 4)
                        good = false;
                    if (cy == 4 && cx != 2)
                        good = false;
                }
                if (good)
                    ans++;
            }

            writer.Write(ans == 1 ? "YES" : "NO");
            writer.Flush();
#if !ONLINE_JUDGE
            writer.Close();
#endif
        }
        private static int Next() {
            int c;
            int res = 0;
            do {
                c = reader.Read();
                if(c == -1)
                    return res;
            } while(c != '-' && (c < '0' || c > '9'));
            int sign = 1;
            if(c == '-') {
                sign = -1;
                c = reader.Read();
            }
            res = c - '0';
            while(true) {
                c = reader.Read();
                if(c < '0' || c > '9')
                    return res * sign;
                res *= 10;
                res += c - '0';
            }
        }
    }
}

using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;

// (づ°ω°)づﾐe★゜・。。・゜゜・。。・゜☆゜・。。・゜゜・。。・゜
public class Solver
{
    int[] xr = { 3, 0, 0, 0, 1, 1, 1, 2, 2, 2 };
    int[] xc = { 1, 0, 1, 2, 0, 1, 2, 0, 1, 2 };

    public void Solve()
    {
        int n = ReadInt();
        if (n == 1)
        {
            Write("NO");
            return;
        }
        string s = ReadToken();

        bool ans = true;
        for (int i = 0; i < 10; i++)
            if (s[0] - '0' != i)
            {
                int r = xr[i];
                int c = xc[i];
                bool ok = true;
                for (int j = 1; j < n; j++)
                {
                    int dr = xr[s[j] - '0'] - xr[s[j - 1] - '0'];
                    int dc = xc[s[j] - '0'] - xc[s[j - 1] - '0'];
                    r += dr;
                    c += dc;
                    if (r < 0 || r > 3 || (r == 3 && c != 1) || c < 0 || c > 2)
                        ok = false;
                }
                if (ok)
                    ans = false;
            }

        Write(ans ? "YES" : "NO");
    }

    #region Main

    protected static TextReader reader;
    protected static TextWriter writer;
    static void Main()
    {
#if DEBUG
        reader = new StreamReader("..\\..\\input.txt");
        //reader = new StreamReader(Console.OpenStandardInput());
        writer = Console.Out;
        //writer = new StreamWriter("..\\..\\output.txt");
#else
        reader = new StreamReader(Console.OpenStandardInput());
        writer = new StreamWriter(Console.OpenStandardOutput(),Encoding.ASCII);
        //reader = new StreamReader("input.txt");
        //writer = new StreamWriter("output.txt");
#endif
        try
        {
            new Solver().Solve();
            //var thread = new Thread(new Solver().Solve, 1024 * 1024 * 128);
            //thread.Start();
            //thread.Join();
        }
        catch (Exception ex)
        {
#if DEBUG
            Console.WriteLine(ex);
#else
            throw;
#endif
        }
        reader.Close();
        writer.Close();
    }

    #endregion

    #region Read / Write
    private static Queue<string> currentLineTokens = new Queue<string>();
    private static string[] ReadAndSplitLine() { return reader.ReadLine().Split(new[] { ' ', '\t', }, StringSplitOptions.RemoveEmptyEntries); }
    public static string ReadToken() { while (currentLineTokens.Count == 0)currentLineTokens = new Queue<string>(ReadAndSplitLine()); return currentLineTokens.Dequeue(); }
    public static int ReadInt() { return int.Parse(ReadToken()); }
    public static long ReadLong() { return long.Parse(ReadToken()); }
    public static double ReadDouble() { return double.Parse(ReadToken(), CultureInfo.InvariantCulture); }
    public static int[] ReadIntArray() { return ReadAndSplitLine().Select(int.Parse).ToArray(); }
    public static long[] ReadLongArray() { return ReadAndSplitLine().Select(long.Parse).ToArray(); }
    public static double[] ReadDoubleArray() { return ReadAndSplitLine().Select(s => double.Parse(s, CultureInfo.InvariantCulture)).ToArray(); }
    public static int[][] ReadIntMatrix(int numberOfRows) { int[][] matrix = new int[numberOfRows][]; for (int i = 0; i < numberOfRows; i++)matrix[i] = ReadIntArray(); return matrix; }
    public static int[][] ReadAndTransposeIntMatrix(int numberOfRows)
    {
        int[][] matrix = ReadIntMatrix(numberOfRows); int[][] ret = new int[matrix[0].Length][];
        for (int i = 0; i < ret.Length; i++) { ret[i] = new int[numberOfRows]; for (int j = 0; j < numberOfRows; j++)ret[i][j] = matrix[j][i]; } return ret;
    }
    public static string[] ReadLines(int quantity) { string[] lines = new string[quantity]; for (int i = 0; i < quantity; i++)lines[i] = reader.ReadLine().Trim(); return lines; }
    public static void WriteArray<T>(IEnumerable<T> array) { writer.WriteLine(string.Join(" ", array)); }
    public static void Write(params object[] array) { WriteArray(array); }
    public static void WriteLines<T>(IEnumerable<T> array) { foreach (var a in array)writer.WriteLine(a); }
    private class SDictionary<TKey, TValue> : Dictionary<TKey, TValue>
    {
        public new TValue this[TKey key]
        {
            get { return ContainsKey(key) ? base[key] : default(TValue); }
            set { base[key] = value; }
        }
    }
    private static T[] Init<T>(int size) where T : new() { var ret = new T[size]; for (int i = 0; i < size; i++)ret[i] = new T(); return ret; }
    #endregion
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Numerics;

class PairVariable : IComparable<PairVariable>
{
    public int a, b;
    public int c;
    public PairVariable()
    {
        a = b = 0;
        c = 0;
    }
    public PairVariable(string s)
    {
        string[] q = s.Split();
        a = int.Parse(q[0]);
        b = int.Parse(q[1]);
        c = 0;

    }

    public PairVariable(int a, int b, int c)
    {
        this.a = a;
        this.b = b;
        this.c = c;

    }

    public int CompareTo(PairVariable other)
    {
        return this.b.CompareTo(other.b);
    }
}

namespace ConsoleApplication3
{
    class Program
    {

        static bool isPrime(int n)
        {
            for (int i = 2; i <= Math.Sqrt(n); i++)
            {
                if (n % i == 0)
                {
                    return false;
                }
            }
            return true;
        }
        static int gcd(int a, int b)
        {
            if (b == 0)
            {
                return a;
            }
            else
            {
                return gcd(b, a % b);
            }
        }
        static long factorial(int a)
        {
            long s = 1;
            for (long i = 1; i <= a; i++)
            {
                s *= i;
            }
            return s;
        }

        static void Main(string[] args)
        {
            string[] ss = Console.ReadLine().Split();
            int n = int.Parse(ss[0]);
            string s = Console.ReadLine();
            int[] a = new int[n];
            for (int i = 0; i < s.Length; i++)
            {
                a[i] = int.Parse(s[i].ToString());
            }
            bool f = false;
            for (int i = 0; i < n; i++)
            {
                if (a[i] == 1 || a[i] == 2 || a[i] == 3)
                {
                    f = true;
                }
            }
            if (!f)
            {
                Console.WriteLine("NO");
                return;
            }
            f = false;
            for (int i = 0; i < n; i++)
            {
                if (a[i] == 3 || a[i] == 6 || a[i] == 9 || a[i] == 0)
                {
                    f = true;
                }
            }
            if (!f)
            {
                Console.WriteLine("NO");
                return;
            }
            f = false;
            for (int i = 0; i < n; i++)
            {
                if (a[i] == 1 || a[i] == 4 || a[i] == 7 || a[i] == 0)
                {
                    f = true;
                }
            }
            if (!f)
            {
                Console.WriteLine("NO");
                return;
            }
            f = false;
            for (int i = 0; i < n; i++)
            {
                if (a[i] == 7 || a[i] == 0 || a[i] == 9)
                {
                    f = true;
                }
            }
            if (!f)
            {
                Console.WriteLine("NO");
                return;
            }
            Console.WriteLine("YES");
        }
    }
}

using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Numerics;

namespace contest
{

    class contest
    {

        static void Main(string[] args)
        {

            //int n = int.Parse(Console.ReadLine());
            //var input = Console.ReadLine().Split().Select(int.Parse).ToArray();

            //var num = Console.ReadLine().Split().Select(int.Parse).ToArray();

            int n = int.Parse(Console.ReadLine());
            string s = (Console.ReadLine());

            bool only = true;

            var memoA = new int[n];
            var memoB = new int[n];
            for(int i =0; i< n; i++)
            {

                int tmp = s[i]-'0';

                if (tmp == 0)
                {
                    memoA[i] = 8;
                }
                else if (tmp == 3) memoA[i] = -1;
                else memoA[i] = tmp - 3;

                if(tmp ==0)
                {
                    memoB[i] = 11;
                }
                else if(tmp ==8) memoB[i] = 0;
                else memoB[i] = tmp + 3;

            }

            if (!memoA.Any(c => c < 0 || c >= 10) || !memoB.Any(c => c < 0 || c >= 10)) only = false;

            memoA = new int[n];
            memoB = new int[n];
            for (int i = 0; i < n; i++)
            {

                int tmp = s[i] - '0';

                if (tmp == 1)
                {
                    memoA[i] = -1;
                }
                else if (tmp == 4 || tmp ==7) memoA[i] = -1;
                else memoA[i] = tmp - 1;

                if (tmp == 0)
                {
                    memoB[i] = 11;
                }
                else if (tmp == 3 || tmp==6) memoB[i] = 11;
                else memoB[i] = tmp + 1;

            }
            if (!memoA.Any(c => c < 0 || c >= 10) || !memoB.Any(c => c < 0 || c >= 10)) only = false;

            if (only) Console.WriteLine("YES");
            else Console.WriteLine("NO");

        }

    }

}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication4
{
    class Program
    {
        static void Main(string[] args)
        {
            int number = Convert.ToInt32(Console.ReadLine());
            string digits = Console.ReadLine();
            int[,] jaggedArray = new int[4,3];
            int[] array = new int[number];
            int[] firstArray = new int[number];
            int[] secondArray = new int[number];
            int[] difOne = new int[number];
            int[] difTwo = new int[number];
            for (int i = 0; i < 4; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    if((j + 1) + (i * 3) == 10)
                    {
                        jaggedArray[i,j] = -1;
                    }
                    else if((j + 1) + (i * 3) == 11)
                    {
                        jaggedArray[i,j] = 0;
                    }
                    else if((j + 1) + (i * 3) == 12)
                    {
                        jaggedArray[i,j] = -1;
                    }
                    else
                    {
                        jaggedArray[i,j] = (j + 1) + (i*3);
                    }
                }
            }
            for (int i = 0; i < number; i++)
            {
                array[i] = (int)Char.GetNumericValue(digits[i]);
                for (int j = 0; j < 4; j++)
                {
                    for (int k = 0; k < 3; k++)
                    {
                        if(jaggedArray[j,k] == array[i])
                        {
                            firstArray[i] = j;
                            secondArray[i] = k;
                            if(i == 0)
                            {
                                difOne[i] = 0;
                                difTwo[i] = 0;
                            }
                            else
                            {
                                difOne[i] = firstArray[i - 1] - firstArray[i];
                                difTwo[i] = secondArray[i - 1] - secondArray[i];
                            }
                            break;
                        }
                    }
                }
            }
            bool error = false;

            for (int i = 0; i <= 9; i++)
            {
                if (i != array[0])
                {
                    error = true;
                    try
                    {
                        for (int j = 0; j < 4; j++)
                        {
                            for (int k = 0; k < 3; k++)
                            {
                                if (i == jaggedArray[j, k])
                                {
                                    int n = 0;
                                    int m = 0;
                                    for (int l = 0; l < number; l++)
                                    {
                                        if (jaggedArray[n - difOne[l] + j, m - difTwo[l] +k] != -1)
                                        {
                                            n = n - difOne[l];
                                            m = m - difTwo[l];
                                        }
                                        else
                                        {
                                            error = false;
                                        }
                                    }
                                }
                            }
                        }
                        if (error)
                        {
                            break;
                        }

                    }
                    catch (Exception)
                    {
                        error = false;
                    }
                }

            }

            if(error == false)
            {
                Console.WriteLine("YES");
            }
            else
            {
                Console.WriteLine("NO");
            }

        }
    }
}

using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

class Program
{
    private static int[,] mat = new int[10, 4];

    static void solve(StreamReader reader, StreamWriter writer)
    {
        for (int i = 0; i <= 9; ++i)
            for (int j = 0; j <= 3; ++j)
                mat[i, j] = -1;
        mat[1, 1] = 2;
        mat[1, 2] = 4;
        mat[3, 2] = 6;
        mat[3, 3] = 2;
        mat[9, 3] = 8;
        mat[9, 0] = 6;
        mat[7, 0] = 4;
        mat[7, 1] = 8;
        mat[2, 1] = 3;
        mat[2, 2] = 5;
        mat[2, 3] = 1;
        mat[4, 0] = 1;
        mat[4, 1] = 5;
        mat[4, 2] = 7;
        mat[6, 2] = 9;
        mat[6, 3] = 5;
        mat[6, 0] = 3;
        mat[8, 0] = 5;
        mat[8, 1] = 9;
        mat[8, 2] = 0;
        mat[8, 3] = 7;
        mat[0, 0] = 8;
        mat[5, 0] = 2;
        mat[5, 1] = 6;
        mat[5, 2] = 8;
        mat[5, 3] = 4;
        int n = reader.ReadInt();
        var s = reader.ReadLine();
        bool can = false;
        for (int i = 0; i <= 3; ++i)
        {
            var could = true;
            for (int h = 0; h < n; ++h)
            {
                if (mat[s[h] - '0', i] == -1)
                    could = false;
            }
            can |= could;
        }
        writer.WriteLine(can? "NO": "YES");
    }

    #region launch
    static void Main(string[] args)
    {
        using (var writer = new FormattedStreamWriter(Console.OpenStandardOutput()))
        {
            using (var reader = new StreamReader(
#if CODECHIEF_LOCAL
    "input.txt"
#else
Console.OpenStandardInput()
#endif
))
            {
                solve(reader, writer);
            }
        }
    }
    #endregion
}

#region helpers
class FormattedStreamWriter : StreamWriter
{
    public FormattedStreamWriter(Stream stream)
        : base(stream)
    {
    }

    public override IFormatProvider FormatProvider
    {
        get
        {
            return CultureInfo.InvariantCulture;
        }
    }
}

static class IOExtensions
{
    public static string ReadString(this StreamReader reader)
    {
        return reader.ReadToken();
    }

    public static int ReadInt(this StreamReader reader)
    {
        return int.Parse(reader.ReadToken(), CultureInfo.InvariantCulture);
    }

    public static long ReadLong(this StreamReader reader)
    {
        return long.Parse(reader.ReadToken(), CultureInfo.InvariantCulture);
    }

    public static double ReadDouble(this StreamReader reader)
    {
        return double.Parse(reader.ReadToken(), CultureInfo.InvariantCulture);
    }

    static Queue<string> buffer = new Queue<string>(100);

    static string ReadToken(this StreamReader reader)
    {
        while (buffer.Count == 0)
        {
            reader.ReadLine().Split(new[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries).ToList().ForEach((t) =>
            {
                buffer.Enqueue(t);
            });
        }
        return buffer.Dequeue();
    }
}
#endregion

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;

namespace codeforces
{
	class Program
	{
		public const int Osn = 1000000007;

		public class Pair
		{
			public long First;

			public long Second;
		}

		public class PairComparer : IComparer<Pair>
		{
			public int Compare(Pair x, Pair y)
			{
				if (x.First > y.First || (x.First == y.First && x.Second > y.Second))
					return -1;
				return 1;
			}
		}

		public static long GetGcd(long a, long b)
		{
			while (true)
			{
				if (b == 0)
					return a;
				var a1 = a;
				a = b;
				b = a1 % b;
			}
		}

		public static void WriteYesNo(bool x, string yes = "YES", string no = "NO")
		{
			if (x)
				Console.WriteLine(yes);
			else
			{
				Console.WriteLine(no);
			}
		}

		public static string ReadString()
		{
			return Console.ReadLine();
		}

		public static List<int> ReadListOfInts()
		{
			var s = Console.ReadLine();
			return s.Split(' ').Select(int.Parse).ToList();
		}

		public static List<long> ReadListOfLongs()
		{
			var s = Console.ReadLine();
			return s.Split(' ').Select(long.Parse).ToList();
		}

		public static int ReadInt()
		{
			var s = Console.ReadLine();
			return int.Parse(s);
		}

		public static long ReadLong()
		{
			var s = Console.ReadLine();
			return long.Parse(s);
		}

		public class Vertex
		{
			public int Was;

			public List<int> Edges;
		}

		public static List<Vertex> Graph = new List<Vertex>();

		public static bool Dfs(int u)
		{
			if (Graph[u].Was == 1) return true;
			if (Graph[u].Was == 2) return false;
			Graph[u].Was = 1;
			foreach (var t in Graph[u].Edges)
			{
				if (Dfs(t)) return true;
			}

			Graph[u].Was = 2;
			return false;
		}

		public static bool IsPrime(int x)
		{
			for (var j = 2; j * j <= x; ++j)
				if (x % j == 0)
					return false;
			return true;
		}

		public class LinkedVertex
		{
			public int Next;

			public int Prev;

			public int Value;
		}

		public static int BinarySearch(List<int> list, int value)
		{
			var l = -1;
			var r = list.Count;
			while (r - l > 1)
			{
				var m = (r + l) / 2;
				if (list[m] >= value)
					r = m;
				else
					l = m;
			}

			return r;
		}

		private static void Main()
		{
			var n = ReadInt();
			var s = ReadString();
			var phone = new Dictionary<char, Pair>();
			phone.Add('1', new Pair { First = 0, Second = 0 });
			phone.Add('2', new Pair { First = 0, Second = 1 });
			phone.Add('3', new Pair { First = 0, Second = 2 });
			phone.Add('4', new Pair { First = 1, Second = 0 });
			phone.Add('5', new Pair { First = 1, Second = 1 });
			phone.Add('6', new Pair { First = 1, Second = 2 });
			phone.Add('7', new Pair { First = 2, Second = 0 });
			phone.Add('8', new Pair { First = 2, Second = 1 });
			phone.Add('9', new Pair { First = 2, Second = 2 });
			phone.Add('0', new Pair { First = 3, Second = 1 });
			var ct = 0;
			var diffs = new List<Pair> { new Pair { First = 0, Second = 0 } };
			for (var i = 1; i < s.Length; ++i)
				diffs.Add(new Pair { First = phone[s[i]].First - phone[s[i - 1]].First, Second = phone[s[i]].Second - phone[s[i - 1]].Second });
			for (var i = '0'; i <= '9'; ++i)
			{
				var curx = phone[i].First;
				var cury = phone[i].Second;
				var good = true;
				for (var j = 0; j < n; ++j)
				{
					curx += diffs[j].First;
					cury += diffs[j].Second;
					if (curx < 0 || curx > 3 || cury < 0 || cury > 2 || (curx == 3 && cury != 1))
						good = false;
				}

				if (good)
					ct++;
			}
			WriteYesNo(ct == 1);
			Console.ReadLine();
		}
	}
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Globalization;
using System.IO;
using System.Net;

namespace ConsoleApplication6
{
    class Program
    {     static int[] ceni;
        static void Main(string[] args)
        {
            int n = Convert.ToInt32(Console.ReadLine());
            string str = Console.ReadLine();
            int[] nabor = new int[n];
            int[] vertik = new int[n];
            int[] gorizont = new int[n];
            for (int i = 0; i < n; i++) {
                nabor[i] = Convert.ToInt32(str[i].ToString());

            }
            for (int i = 0; i < n; i++) {
                if (nabor[i] % 3 > 0) {
                    vertik[i] = nabor[i] % 3;
                    gorizont[i] = (nabor[i] / 3) + 1;

                }
                else {

                    if (nabor[i] > 0)
                    { gorizont[i] = (nabor[i] / 3);
                      vertik[i] = 3;

                    }
                    else {
                        vertik[i] = 2;
                        gorizont[i] = 4; }
                }
            }
            int maxvertik = vertik.Max();
            int minvertik = vertik.Min();
            int maxgorizont = gorizont.Max();
            int mingorizont = gorizont.Min();
            bool sdvigg=true;
            bool sdvigv=true;

            if((mingorizont==1)&&(maxgorizont==4)){
                sdvigv = false;
            }
            if ((mingorizont == 1) && (maxgorizont == 3)) {
                for(int i=0;i<n;i++){
                if(((vertik[i]==3)||(vertik[i]==1))&&(gorizont[i]==3)){
                 sdvigv = false;
                 break;
                }

                }
            }
            if ((minvertik == 1) && (maxvertik == 3)) {
                sdvigg = false;
            }

            if ((sdvigv==false)&&(sdvigg==false))
            {
                Console.WriteLine("YES");

            }
            else { Console.WriteLine("NO"); }
            Console.ReadLine();
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Globalization;
using System.IO;
using System.Net;

namespace ConsoleApplication6
{
    class Program
    {     static int[] ceni;
        static void Main(string[] args)
        {
            int n = Convert.ToInt32(Console.ReadLine());
            string str = Console.ReadLine();
            int[] nabor = new int[n];
            int[] vertik = new int[n];
            int[] gorizont = new int[n];
            for (int i = 0; i < n; i++) {
                nabor[i] = Convert.ToInt32(str[i].ToString());

            }
            for (int i = 0; i < n; i++) {
                if (nabor[i] % 3 > 0) {
                    vertik[i] = nabor[i] % 3;
                    gorizont[i] = (nabor[i] / 3) + 1;

                }
                else {

                    if (nabor[i] > 0)
                    { gorizont[i] = (nabor[i] / 3);
                      vertik[i] = 3;

                    }
                    else {
                        vertik[i] = 2;
                        gorizont[i] = 4; }
                }
            }
            int maxvertik = vertik.Max();
            int minvertik = vertik.Min();
            int maxgorizont = gorizont.Max();
            int mingorizont = gorizont.Min();
            bool sdvigg=true;
            bool sdvigv=true;

            if((mingorizont==1)&&(maxgorizont==4)){
                sdvigv = false;
            }
            if ((mingorizont == 1) && (maxgorizont == 3)) {
                for(int i=0;i<n;i++){
                if(((vertik[i]==3))&&(gorizont[i]==3)){
                 sdvigv = false;
                 break;
                }

                }
            }
            if ((minvertik == 1) && (maxvertik == 3)) {
                sdvigg = false;
            }

            if ((sdvigv==false)&&(sdvigg==false))
            {
                Console.WriteLine("YES");

            }
            else { Console.WriteLine("NO"); }
            Console.ReadLine();
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string st = Console.ReadLine();
            bool left, right, down, up;
            left = right = down = up = true;
            if (st.Contains("1") || st.Contains("4") || st.Contains("7") || st.Contains("0"))
            {
                left = false;
            }
            if (st.Contains("3") || st.Contains("6") || st.Contains("9") || st.Contains("0"))
            {
                right = false;
            }
            if (st.Contains("1") || st.Contains("2") || st.Contains("3"))
            {
                up = false;
            }
            if (st.Contains("7") || st.Contains("0") || st.Contains("9"))
            {
                down = false;
            }
            if (left || right || down || up)
            {
                Console.WriteLine("YES");
            }
            else
            {
                Console.WriteLine("NO");
            }
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string st = Console.ReadLine();
            bool left, right, down, up;
            left = right = down = up = true;
            if (st.Contains("1") || st.Contains("4") || st.Contains("7") || st.Contains("0"))
            {
                left = false;
            }
            if (st.Contains("3") || st.Contains("4") || st.Contains("5") || st.Contains("0"))
            {
                right = false;
            }
            if (st.Contains("1") || st.Contains("2") || st.Contains("3"))
            {
                up = false;
            }
            if (st.Contains("7") || st.Contains("0") || st.Contains("9"))
            {
                down = false;
            }
            if (left || right || down || up)
            {
                Console.WriteLine("YES");
            }
            else
            {
                Console.WriteLine("NO");
            }
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string st = Console.ReadLine();
            bool left, right, down, up;
            left = right = down = up = true;
            if (st.Contains("1") || st.Contains("4") || st.Contains("7") || st.Contains("0"))
            {
                left = false;
            }
            if (st.Contains("3") || st.Contains("6") || st.Contains("9") || st.Contains("0"))
            {
                right = false;
            }
            if (st.Contains("1") || st.Contains("2") || st.Contains("3"))
            {
                up = false;
            }
            if (st.Contains("7") || st.Contains("0") || st.Contains("9"))
            {
                down = false;
            }
            if (left || right || down || up)
            {
                Console.WriteLine("NO");
            }
            else
            {
                Console.WriteLine("YES");
            }
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;

namespace ConsoleApplication2
{
    class Program
    {

        private int n;
        private string s;
        private static int[,] pos = { { 3, 1 }, { 0, 0 }, { 0, 1 }, { 0, 2 }, { 1, 0 }, { 1, 1 }, { 1, 2 }, { 2, 0 }, { 2, 1 }, { 2, 2 } };

        public void ReadInput()
        {
            n = Convert.ToInt32(Console.ReadLine());
            s = Console.ReadLine();
        }

        public bool MatchRecursively(int curNum, int curStrPos)
        {
            if (curStrPos == s.Length - 1) return true;

            int num1 = (int)Char.GetNumericValue(s[curStrPos]);
            int num2 = (int)Char.GetNumericValue(s[curStrPos + 1]);
            int diff1 = pos[num2, 0] - pos[num1, 0];
            int diff2 = pos[num2, 1] - pos[num1, 1];
            int newCurPos1 = pos[curNum, 0] + diff1;
            int newCurPos2 = pos[curNum, 1] + diff2;
            int newCurNum;
            if (newCurPos1 >= 0 && newCurPos1 <= 3 && newCurPos2 >= 0 && newCurPos2 <= 2) newCurNum = (newCurPos1 - 1) * 3 + newCurPos2;
            else return false;
            if (newCurNum >= 1 && newCurNum <= 9) return MatchRecursively(newCurNum, curStrPos + 1);
            else if (newCurNum == 11) return MatchRecursively(0, curStrPos + 1);
            else return false;

        }

        static void Main(string[] args)
        {

            bool fl = true;

            Program p = new Program();
            p.ReadInput();

            for (int i = 0; i <= 9; i++)
            {
                if (i == (int)Char.GetNumericValue(p.s[0])) continue;
                if (p.MatchRecursively(i, 0)) { Console.WriteLine("NO"); fl = false; break; }
            }

            if (fl) Console.WriteLine("YES");

        }
    }
}

using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;

namespace Olymp
{
  public class ProblemSolver
  {
    private Tokenizer input;

    public void Solve()
    {
      int n = input.NextInt();
      string s = input.NextToken();
      var r = new int[] { 4, 1, 1, 1, 2, 2, 2, 3, 3, 3 };
      var c = new int[] { 2, 1, 2, 3, 1, 2, 3, 1, 2, 3 };
      string[] m = new string[6]
      {
        ".....",
        ".***.",
        ".***.",
        ".***.",
        "..*..",
        "....."
      };
      for (int dx = -1; dx <= 1; dx += 2)
      {
        for (int dy = -1; dy <= 1; dy += 2)
        {
          bool canShift = true;
          for (int i = 0; i < n; i++)
          {
            int d = s[i] - '0';
            if (m[r[d] + dx][c[d] + dy] == '.')
            {
              canShift = false;
              break;
            }
          }
          if (canShift)
          {
            Console.Write("NO");
            return;
          }
        }
      }
      Console.Write("YES");
    }

    public ProblemSolver(TextReader input)
    {
      this.input = new Tokenizer(input);
    }
  }

  #region Service classes

  public class Tokenizer
  {
    private TextReader reader;

    public int NextInt()
    {
      var c = SkipWS();
      if (c == -1)
        throw new EndOfStreamException();
      bool isNegative = false;
      if (c == '-' || c == '+')
      {
        isNegative = c == '-';
        c = this.reader.Read();
        if (c == -1)
          throw new InvalidOperationException();
      }
      if (!char.IsDigit((char)c))
        throw new InvalidOperationException();
      int result = (char)c - '0';
      c = this.reader.Read();
      while (c > 0 && !char.IsWhiteSpace((char)c))
      {
        if (!char.IsDigit((char)c))
          throw new InvalidOperationException();
        result = result * 10 + (char)c - '0';
        c = this.reader.Read();
      }
      if (isNegative)
        result = -result;
      return result;
    }

    public string ReadLine()
    {
      return reader.ReadLine();
    }

    public long NextLong()
    {
      return long.Parse(this.NextToken());
    }

    public double NextDouble()
    {
      return double.Parse(this.NextToken(), CultureInfo.InvariantCulture);
    }

    public int[] ReadIntArray(int n)
    {
      int[] a = new int[n];
      for (int i = 0; i < n; i++)
        a[i] = NextInt();
      return a;
    }

    public long[] ReadLongArray(int n)
    {
      long[] a = new long[n];
      for (int i = 0; i < n; i++)
        a[i] = NextLong();
      return a;
    }

    public double[] ReadDoubleArray(int n)
    {
      double[] a = new double[n];
      for (int i = 0; i < n; i++)
        a[i] = NextDouble();
      return a;
    }

    public string NextToken()
    {
      var c = SkipWS();
      if (c == -1)
        return null;
      var sb = new StringBuilder();
      while (c > 0 && !char.IsWhiteSpace((char)c))
      {
        sb.Append((char)c);
        c = this.reader.Read();
      }
      return sb.ToString();
    }

    private int SkipWS()
    {
      int c = this.reader.Read();
      if (c == -1)
        return c;
      while (c > 0 && char.IsWhiteSpace((char)c))
        c = this.reader.Read();
      return c;
    }

    public Tokenizer(TextReader reader)
    {
      this.reader = reader;
    }
  }

  class Program
  {
    public static void Main(string[] args)
    {
      var solver = new ProblemSolver(Console.In);
      solver.Solve();
    }
  }

  #endregion
}

using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Security;
using System.Security.Cryptography;

namespace ConsoleApplication1
{
	class Program
	{
		//DON'T FORGET TO SET IT TO FALSE BEFORE SUBMIT!!!!
		public const bool useFiles = false;

		private static StreamReader GetStandardInputStream()
		{
			return useFiles
				? new StreamReader(@"in.txt")
				: new StreamReader(Console.OpenStandardInput());
		}

		private static StreamWriter GetStandardOutputStream()
		{
			return useFiles
				? new StreamWriter(@"out.txt")
				: new StreamWriter(Console.OpenStandardOutput());
		}

		public class MyComparer : IComparer<Tuple<long, long>>
		{
			public int Compare(Tuple<long, long> x, Tuple<long, long> y)
			{
				if (x.Item2 > y.Item2)
				{
					return 1;
				}
				else if (x.Item2 == y.Item2)
				{
					if (x.Item1 > y.Item1)
					{
						return -1;
					}
					else if (x.Item1 == y.Item1)
					{
						return 0;
					}
					else
					{
						return 1;
					}
				}
				else
				{
					return -1;
				}
			}
		}

		public class Graph
		{
			private List<int>[] adj;

			public Graph(int n)
			{
				adj = new List<int>[n];

				for (int i = 0; i < n; i++)
				{
					adj[i] = new List<int>();
				}
			}

			public void AddEdge(int v, int w)
			{
				adj[v].Add(w);
				adj[w].Add(v);
			}

			public int[] GetAdj(int v)
			{
				return adj[v].ToArray();
			}

			public int V()
			{
				return adj.Count();
			}
		}

		public class WeightedNode
		{
			public int Weight { get; set; }

			public int A { get; set; }
			public int B { get; set; }

			public int GetOther(int s)
			{
				return A == s
					? B
					: A;
			}

			public override string ToString()
			{
				return string.Format("{0} -> {1} (W: {2})", this.A, this.B, this.Weight);
			}
		}

		public class WeightedGraph
		{
			private List<WeightedNode>[] adj;

			public WeightedGraph(int n)
			{
				adj = new List<WeightedNode>[n];

				for (int i = 0; i < n; i++)
					adj[i] = new List<WeightedNode>();
			}

			public void AddEdge(int x, int y, int w)
			{
				var node = new WeightedNode()
				{
					A = x,
					B = y,
					Weight = w
				};

				adj[x].Add(node);
				adj[y].Add(node);
			}

			public WeightedNode[] GetAdj(int v)
			{
				return adj[v].ToArray();
			}

			public int V()
			{
				return adj.Count();
			}
		}

		public class DFS
		{
			private Queue<int> q;
			private bool[] marked;
			private int[] distTo;

			public DFS(Graph g, int s)
			{
				q = new Queue<int>();
				marked = new bool[g.V()];
				distTo = new int[g.V()];

				q.Enqueue(s);
				marked[s] = true;
				distTo[s] = 0;

				while (q.Any())
				{
					var cur = q.Dequeue();
					var adj = g.GetAdj(cur);

					foreach (var v in adj)
					{
						if (!marked[v])
						{
							q.Enqueue(v);
							marked[v] = true;
							distTo[v] = distTo[cur] + 1;
						}
					}
				}
			}

			public int GetDistance(int v)
			{
				return marked[v] ? distTo[v] : -1;
			}
		}

		public class WeightedNodeComparor : IComparer<WeightedNode>
		{
			public int Compare(WeightedNode x, WeightedNode y)
			{
				var res = x.Weight.CompareTo(y.Weight);

				if (res != 0)
					return res;

				var r1 = x.A.CompareTo(y.A);
				var r2 = x.B.CompareTo(y.B);

				if (r1 == 0 && r2 == 0)
					return 0;

				return 1;
			}
		}

		public class PrimsMST
		{
			private bool[] marked;
			private List<WeightedNode> res;
			private SortedList<WeightedNode, WeightedNode> sl;

			public PrimsMST(WeightedGraph g, int s)
			{
				res = new List<WeightedNode>();
				marked = new bool[g.V()];
				sl = new SortedList<WeightedNode, WeightedNode>(new WeightedNodeComparor());

				marked[s] = true;
				Visit(g, s);

				while (sl.Any() && res.Count() < g.V() - 1)
				{
					var next = sl.First();
					sl.Remove(next.Key);

					var val = next.Value;

					if (marked[val.A] && marked[val.B])
						continue;

					res.Add(val);

					if (!marked[val.A])
					{
						marked[val.A] = true;
						Visit(g, val.A);
					}

					if (!marked[val.B])
					{
						marked[val.B] = true;
						Visit(g, val.B);
					}

				}

			}

			public void Visit(WeightedGraph g, int s)
			{
				foreach (var v in g.GetAdj(s))
				{
					if (!marked[v.GetOther(s)])
						sl.Add(v, v);
				}
			}

			public List<WeightedNode> GetMST()
			{
				return res;
			}

		}

		public class DoubleComaprer : IComparer<double>
		{
			public int Compare(double x, double y)
			{
				return x.CompareTo(y);
			}
		}

		public struct TempItem
		{
			public long Weight { get; set; }
			public int Vertex { get; set; }
		}

		public class TempItemComparer : IComparer<TempItem>
		{
			public int Compare(TempItem x, TempItem y)
			{
				var r = x.Weight.CompareTo(y.Weight);

				if (r != 0)
					return r;

				var r2 = x.Vertex.CompareTo(y.Vertex);
				return r2;
			}
		}

		public class DejkstraSP
		{
			public long?[] distTo;
			private int[] edgeTo;
			private SortedList<TempItem, int> pq;

			public DejkstraSP(WeightedGraph g, int s)
			{
				distTo = new long?[g.V()];
				edgeTo = new int[g.V()];
				pq = new SortedList<TempItem, int>(new TempItemComparer());

				distTo[s] = 0;

				pq.Add(new TempItem() { Vertex = s, Weight = 0 }, s);
				while (pq.Any())
				{
					var v = pq.First();
					pq.Remove(v.Key);

					foreach (var edge in g.GetAdj(v.Value))
					{
						relax(edge, v.Value);
					}
				}
			}

			private void relax(WeightedNode v, int cur)
			{
				int a = cur;
				int b = v.GetOther(cur);

				if (distTo[b] == null || distTo[b] > distTo[a] + v.Weight)
				{
					distTo[b] = distTo[a] + v.Weight;
					edgeTo[b] = a;

					if (pq.ContainsValue(b))
					{
						var val = pq.First(x => x.Value == b);
						pq.Remove(val.Key);
						pq.Add(new TempItem() { Vertex = b, Weight = distTo[b].Value }, b);

					}
					else
					{
						pq.Add(new TempItem() { Vertex = b, Weight = distTo[b].Value }, b);
					}
				}
			}
		}

		static void Main(string[] args)
		{
			using (var input = GetStandardInputStream())
			using (var output = GetStandardOutputStream())
			{
				var n = ParseInt(input);
				var otherNums = input.ReadLine().ToCharArray().Select(x => int.Parse(x.ToString())).ToArray();

				var arr = new bool[10];

				foreach (var otherNum in otherNums)
				{
					arr[otherNum] = true;
				}

				var flag1 = false;
				var flag2 = false;

				if ((arr[1] || arr[2] || arr[3]) && (arr[7] || arr[9]))
					flag1 = true;

				if ((arr[1] || arr[2] || arr[3]) && arr[0])
				{
					output.WriteLine("YES");
					return;
				}

				if ((arr[1] || arr[4] || arr[7]) && (arr[3] || arr[6] || arr[9]))
					flag2 = true;

				if (flag1 || flag2)
					output.WriteLine("YES");
				else
				{
					output.WriteLine("NO");
				}

			}
		}

		private static double getDist(Tuple<int, int> c1, Tuple<int, int> c2)
		{
			return Math.Sqrt(Math.Pow(c1.Item1 - c2.Item1, 2.0) + Math.Pow(c1.Item2 - c2.Item2, 2.0));
		}

		private static Tuple<int, int> GetCoord(int number)
		{
			if (number == 0)
				return new Tuple<int, int>(1,3);

			var y = (number - 1) / 3;
			var x = number - (y*3) - 1;

			return new Tuple<int, int>(x,y);
		}

		private static long Factorial(int numb)
		{
			if (numb == 0)
				return 1;

			long res = 1;
			for (int i = numb; i > 1; i--)
				res *= i;
			return res;
		}

		private static double partialSum(double p, double q)
		{
			if (Math.Abs(p - 1) < double.Epsilon)
				return 1;

			double a = p,
				d = p,
				r = q;

			var res = (a/(1 - r)) + ((r*d)/((1 - r)*(1 - r)));
			return res;
		}

		public class Clusters
		{
			private bool[] marked;
			private Stack<int> st;
			public int count;

			private int[,] fromStr(string[] zombies)
			{
				var n = zombies.Length;
				var matrix = new int[n, n];
				int i = 0;

				foreach (var str in zombies)
				{
					var inStr = str;
					var ar = new List<int>();

					foreach (var c in inStr)
					{
						ar.Add(int.Parse(c.ToString()));
					}

					for (var j = 0; j < n; j++)
					{
						matrix[i, j] = ar[j];
					}
					i++;
				}

				return matrix;
			}
			public Clusters(string[] zmb_str)
			{
				var n = zmb_str.Count();
				var zombies = fromStr(zmb_str);
				st = new Stack<int>();
				marked = new bool[n];
				count = 0;

				for (int v = 0; v < n; v++)
				{
					if (!marked[v])
						dfs(ref zombies, v, n);
				}

				marked = new bool[n];
				foreach (var e in reverserPostOrder())
				{
					if (!marked[e])
					{
						dfs(ref zombies, e, n);
						count++;
					}
				}
			}

			private void dfs(ref int[,] g, int v, int n)
			{
				marked[v] = true;
				foreach (var e in getAdj(ref g, v, n))
				{
					if (!marked[e]) dfs(ref g, e, n);
				}
				st.Push(v);
			}

			private int[] getAdj(ref int[,] g, int v, int n)
			{
				var res = new List<int>();
				for (int i = 0; i < n; i++)
				{
					if (i == v)
						continue;

					if (g[v, i] == 1)
					{
						res.Add(i);
					}
				}

				return res.ToArray();
			}

			public int[] reverserPostOrder()
			{
				return st.ToArray();
			}
		}

		private static int binarySearch(ref long[] ar, int l, int h, long key)
		{
			if (l >= h)
				return -1;

			var mid = (l + h) / 2;

			if (ar[mid] == key)
				return mid;

			if (key > ar[mid])
				return binarySearch(ref ar, mid+1, h, key);

			return binarySearch(ref ar, 0, mid, key);
		}

		private static int[] ParseIntString(StreamReader input)
		{
			return input.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
		}

		private static int ParseInt(StreamReader input)
		{
			return int.Parse(input.ReadLine());
		}

		private static long primaryDiagSum(ref int[][] a, int n)
		{
			long sum = 0;
			for (var i = 0; i < n; i++)
				sum += a[i][i];

			return sum;
		}

		private static long secondaryDiagSum(ref int[][] a, int n)
		{
			long sum = 0;
			for (var i = 0; i < n; i++)
				sum += a[i][n - i - 1];

			return sum;
		}

		private static int GetIdx(int n, int lastAns, int x)
		{
			return (x ^ lastAns) % n;
		}

		private static int getHourGlassSum(ref int[][] ar, int x, int y)
		{
			var sum = 0;

			sum += ar[x][y];
			sum += ar[x][y + 1];
			sum += ar[x][y + 2];

			sum += ar[x + 1][y + 1];

			sum += ar[x + 2][y];
			sum += ar[x + 2][y + 1];
			sum += ar[x + 2][y + 2];

			return sum;
		}

		private static long sumFrom(int start, ref long[] sums, long totalSum)
		{
			if (start >= sums.Length)
				return 0;

			return totalSum - sums[start - 1];
		}

		public int ReadSingleInt(StreamReader input)
		{
			var line = input.ReadLine();
			return int.Parse(line);
		}

		public string ReadString()
		{
			return Console.ReadLine();
		}

		public int[] ReadInts(char sep = ' ')
		{
			var line = Console.ReadLine();
			var arr = line.Split(sep).Select(x => int.Parse(x)).ToArray();

			return arr;
		}

	}
}

using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Security;
using System.Security.Cryptography;

namespace ConsoleApplication1
{
	class Program
	{
		//DON'T FORGET TO SET IT TO FALSE BEFORE SUBMIT!!!!
		public const bool useFiles = false;

		private static StreamReader GetStandardInputStream()
		{
			return useFiles
				? new StreamReader(@"in.txt")
				: new StreamReader(Console.OpenStandardInput());
		}

		private static StreamWriter GetStandardOutputStream()
		{
			return useFiles
				? new StreamWriter(@"out.txt")
				: new StreamWriter(Console.OpenStandardOutput());
		}

		public class MyComparer : IComparer<Tuple<long, long>>
		{
			public int Compare(Tuple<long, long> x, Tuple<long, long> y)
			{
				if (x.Item2 > y.Item2)
				{
					return 1;
				}
				else if (x.Item2 == y.Item2)
				{
					if (x.Item1 > y.Item1)
					{
						return -1;
					}
					else if (x.Item1 == y.Item1)
					{
						return 0;
					}
					else
					{
						return 1;
					}
				}
				else
				{
					return -1;
				}
			}
		}

		public class Graph
		{
			private List<int>[] adj;

			public Graph(int n)
			{
				adj = new List<int>[n];

				for (int i = 0; i < n; i++)
				{
					adj[i] = new List<int>();
				}
			}

			public void AddEdge(int v, int w)
			{
				adj[v].Add(w);
				adj[w].Add(v);
			}

			public int[] GetAdj(int v)
			{
				return adj[v].ToArray();
			}

			public int V()
			{
				return adj.Count();
			}
		}

		public class WeightedNode
		{
			public int Weight { get; set; }

			public int A { get; set; }
			public int B { get; set; }

			public int GetOther(int s)
			{
				return A == s
					? B
					: A;
			}

			public override string ToString()
			{
				return string.Format("{0} -> {1} (W: {2})", this.A, this.B, this.Weight);
			}
		}

		public class WeightedGraph
		{
			private List<WeightedNode>[] adj;

			public WeightedGraph(int n)
			{
				adj = new List<WeightedNode>[n];

				for (int i = 0; i < n; i++)
					adj[i] = new List<WeightedNode>();
			}

			public void AddEdge(int x, int y, int w)
			{
				var node = new WeightedNode()
				{
					A = x,
					B = y,
					Weight = w
				};

				adj[x].Add(node);
				adj[y].Add(node);
			}

			public WeightedNode[] GetAdj(int v)
			{
				return adj[v].ToArray();
			}

			public int V()
			{
				return adj.Count();
			}
		}

		public class DFS
		{
			private Queue<int> q;
			private bool[] marked;
			private int[] distTo;

			public DFS(Graph g, int s)
			{
				q = new Queue<int>();
				marked = new bool[g.V()];
				distTo = new int[g.V()];

				q.Enqueue(s);
				marked[s] = true;
				distTo[s] = 0;

				while (q.Any())
				{
					var cur = q.Dequeue();
					var adj = g.GetAdj(cur);

					foreach (var v in adj)
					{
						if (!marked[v])
						{
							q.Enqueue(v);
							marked[v] = true;
							distTo[v] = distTo[cur] + 1;
						}
					}
				}
			}

			public int GetDistance(int v)
			{
				return marked[v] ? distTo[v] : -1;
			}
		}

		public class WeightedNodeComparor : IComparer<WeightedNode>
		{
			public int Compare(WeightedNode x, WeightedNode y)
			{
				var res = x.Weight.CompareTo(y.Weight);

				if (res != 0)
					return res;

				var r1 = x.A.CompareTo(y.A);
				var r2 = x.B.CompareTo(y.B);

				if (r1 == 0 && r2 == 0)
					return 0;

				return 1;
			}
		}

		public class PrimsMST
		{
			private bool[] marked;
			private List<WeightedNode> res;
			private SortedList<WeightedNode, WeightedNode> sl;

			public PrimsMST(WeightedGraph g, int s)
			{
				res = new List<WeightedNode>();
				marked = new bool[g.V()];
				sl = new SortedList<WeightedNode, WeightedNode>(new WeightedNodeComparor());

				marked[s] = true;
				Visit(g, s);

				while (sl.Any() && res.Count() < g.V() - 1)
				{
					var next = sl.First();
					sl.Remove(next.Key);

					var val = next.Value;

					if (marked[val.A] && marked[val.B])
						continue;

					res.Add(val);

					if (!marked[val.A])
					{
						marked[val.A] = true;
						Visit(g, val.A);
					}

					if (!marked[val.B])
					{
						marked[val.B] = true;
						Visit(g, val.B);
					}

				}

			}

			public void Visit(WeightedGraph g, int s)
			{
				foreach (var v in g.GetAdj(s))
				{
					if (!marked[v.GetOther(s)])
						sl.Add(v, v);
				}
			}

			public List<WeightedNode> GetMST()
			{
				return res;
			}

		}

		public class DoubleComaprer : IComparer<double>
		{
			public int Compare(double x, double y)
			{
				return x.CompareTo(y);
			}
		}

		public struct TempItem
		{
			public long Weight { get; set; }
			public int Vertex { get; set; }
		}

		public class TempItemComparer : IComparer<TempItem>
		{
			public int Compare(TempItem x, TempItem y)
			{
				var r = x.Weight.CompareTo(y.Weight);

				if (r != 0)
					return r;

				var r2 = x.Vertex.CompareTo(y.Vertex);
				return r2;
			}
		}

		public class DejkstraSP
		{
			public long?[] distTo;
			private int[] edgeTo;
			private SortedList<TempItem, int> pq;

			public DejkstraSP(WeightedGraph g, int s)
			{
				distTo = new long?[g.V()];
				edgeTo = new int[g.V()];
				pq = new SortedList<TempItem, int>(new TempItemComparer());

				distTo[s] = 0;

				pq.Add(new TempItem() { Vertex = s, Weight = 0 }, s);
				while (pq.Any())
				{
					var v = pq.First();
					pq.Remove(v.Key);

					foreach (var edge in g.GetAdj(v.Value))
					{
						relax(edge, v.Value);
					}
				}
			}

			private void relax(WeightedNode v, int cur)
			{
				int a = cur;
				int b = v.GetOther(cur);

				if (distTo[b] == null || distTo[b] > distTo[a] + v.Weight)
				{
					distTo[b] = distTo[a] + v.Weight;
					edgeTo[b] = a;

					if (pq.ContainsValue(b))
					{
						var val = pq.First(x => x.Value == b);
						pq.Remove(val.Key);
						pq.Add(new TempItem() { Vertex = b, Weight = distTo[b].Value }, b);

					}
					else
					{
						pq.Add(new TempItem() { Vertex = b, Weight = distTo[b].Value }, b);
					}
				}
			}
		}

		static void Main(string[] args)
		{
			using (var input = GetStandardInputStream())
			using (var output = GetStandardOutputStream())
			{
				var n = ParseInt(input);
				var otherNums = input.ReadLine().ToCharArray().Select(x => int.Parse(x.ToString())).ToArray();

				var arr = new bool[10];

				foreach (var otherNum in otherNums)
				{
					arr[otherNum] = true;
				}

				var flag1 = false;
				var flag2 = false;

				if ((arr[1] || arr[2] || arr[3]) && (arr[7] || arr[9]))
					flag1 = true;

				if ((arr[1] || arr[2] || arr[3]) && arr[0])
					flag2 = true;

				if (flag1 || flag2)
					output.WriteLine("YES");
				else
				{
					output.WriteLine("NO");
				}

			}
		}

		private static double getDist(Tuple<int, int> c1, Tuple<int, int> c2)
		{
			return Math.Sqrt(Math.Pow(c1.Item1 - c2.Item1, 2.0) + Math.Pow(c1.Item2 - c2.Item2, 2.0));
		}

		private static Tuple<int, int> GetCoord(int number)
		{
			if (number == 0)
				return new Tuple<int, int>(1,3);

			var y = (number - 1) / 3;
			var x = number - (y*3) - 1;

			return new Tuple<int, int>(x,y);
		}

		private static long Factorial(int numb)
		{
			if (numb == 0)
				return 1;

			long res = 1;
			for (int i = numb; i > 1; i--)
				res *= i;
			return res;
		}

		private static double partialSum(double p, double q)
		{
			if (Math.Abs(p - 1) < double.Epsilon)
				return 1;

			double a = p,
				d = p,
				r = q;

			var res = (a/(1 - r)) + ((r*d)/((1 - r)*(1 - r)));
			return res;
		}

		public class Clusters
		{
			private bool[] marked;
			private Stack<int> st;
			public int count;

			private int[,] fromStr(string[] zombies)
			{
				var n = zombies.Length;
				var matrix = new int[n, n];
				int i = 0;

				foreach (var str in zombies)
				{
					var inStr = str;
					var ar = new List<int>();

					foreach (var c in inStr)
					{
						ar.Add(int.Parse(c.ToString()));
					}

					for (var j = 0; j < n; j++)
					{
						matrix[i, j] = ar[j];
					}
					i++;
				}

				return matrix;
			}
			public Clusters(string[] zmb_str)
			{
				var n = zmb_str.Count();
				var zombies = fromStr(zmb_str);
				st = new Stack<int>();
				marked = new bool[n];
				count = 0;

				for (int v = 0; v < n; v++)
				{
					if (!marked[v])
						dfs(ref zombies, v, n);
				}

				marked = new bool[n];
				foreach (var e in reverserPostOrder())
				{
					if (!marked[e])
					{
						dfs(ref zombies, e, n);
						count++;
					}
				}
			}

			private void dfs(ref int[,] g, int v, int n)
			{
				marked[v] = true;
				foreach (var e in getAdj(ref g, v, n))
				{
					if (!marked[e]) dfs(ref g, e, n);
				}
				st.Push(v);
			}

			private int[] getAdj(ref int[,] g, int v, int n)
			{
				var res = new List<int>();
				for (int i = 0; i < n; i++)
				{
					if (i == v)
						continue;

					if (g[v, i] == 1)
					{
						res.Add(i);
					}
				}

				return res.ToArray();
			}

			public int[] reverserPostOrder()
			{
				return st.ToArray();
			}
		}

		private static int binarySearch(ref long[] ar, int l, int h, long key)
		{
			if (l >= h)
				return -1;

			var mid = (l + h) / 2;

			if (ar[mid] == key)
				return mid;

			if (key > ar[mid])
				return binarySearch(ref ar, mid+1, h, key);

			return binarySearch(ref ar, 0, mid, key);
		}

		private static int[] ParseIntString(StreamReader input)
		{
			return input.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
		}

		private static int ParseInt(StreamReader input)
		{
			return int.Parse(input.ReadLine());
		}

		private static long primaryDiagSum(ref int[][] a, int n)
		{
			long sum = 0;
			for (var i = 0; i < n; i++)
				sum += a[i][i];

			return sum;
		}

		private static long secondaryDiagSum(ref int[][] a, int n)
		{
			long sum = 0;
			for (var i = 0; i < n; i++)
				sum += a[i][n - i - 1];

			return sum;
		}

		private static int GetIdx(int n, int lastAns, int x)
		{
			return (x ^ lastAns) % n;
		}

		private static int getHourGlassSum(ref int[][] ar, int x, int y)
		{
			var sum = 0;

			sum += ar[x][y];
			sum += ar[x][y + 1];
			sum += ar[x][y + 2];

			sum += ar[x + 1][y + 1];

			sum += ar[x + 2][y];
			sum += ar[x + 2][y + 1];
			sum += ar[x + 2][y + 2];

			return sum;
		}

		private static long sumFrom(int start, ref long[] sums, long totalSum)
		{
			if (start >= sums.Length)
				return 0;

			return totalSum - sums[start - 1];
		}

		public int ReadSingleInt(StreamReader input)
		{
			var line = input.ReadLine();
			return int.Parse(line);
		}

		public string ReadString()
		{
			return Console.ReadLine();
		}

		public int[] ReadInts(char sep = ' ')
		{
			var line = Console.ReadLine();
			var arr = line.Split(sep).Select(x => int.Parse(x)).ToArray();

			return arr;
		}

	}
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace a
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            string s = Console.ReadLine();

            bool[] ls = new bool[10];
            for (int i = 0; i < s.Length; i++)
            {
                ls[s[i] - '0'] = true;
            }
            bool[] yoko = new bool[3];
            bool[] tate = new bool[4];

            if(ls[0])
            {
                yoko[1] = true;
                tate[3] = true;
            }

            for (int i = 1; i < 10; i++)
            {
                if(ls[i])
                {
                    yoko[(i - 1) % 3] = true;
                    tate[(i - 1) / 3] = true;
                }
            }
            if (tate[3])//0
            {
                if (tate[0])
                {
                    Console.WriteLine("YES");
                    return;
                }
                else
                {
                    Console.WriteLine("NO");
                    return;
                }
            }
            if((tate[0]&&tate[2]) && yoko[0]&&yoko[2])
            {
                Console.WriteLine("YES");
                return;
            }
            else
            {
                Console.WriteLine("NO");
                return;
            }

        }
    }
}

using System;
using System.IO;
using System.Text;

namespace Mike_and_Cellphone
{
    internal class Program
    {
        private static readonly StreamReader reader = new StreamReader(Console.OpenStandardInput(1024*10), Encoding.ASCII, false, 1024*10);
        private static readonly StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(1024*10), Encoding.ASCII, 1024*10);

        private static void Main(string[] args)
        {
            string s = reader.ReadLine();
            s = reader.ReadLine();

            var keyboard = new char[10][];
            keyboard[0] = ".......".ToCharArray();
            keyboard[1] = ".......".ToCharArray();
            keyboard[2] = ".......".ToCharArray();
            keyboard[3] = "..123..".ToCharArray();
            keyboard[4] = "..456..".ToCharArray();
            keyboard[5] = "..789..".ToCharArray();
            keyboard[6] = "...0...".ToCharArray();
            keyboard[7] = ".......".ToCharArray();
            keyboard[8] = ".......".ToCharArray();
            keyboard[9] = ".......".ToCharArray();

            var x = new int[s.Length];
            var y = new int[s.Length];

            for (int i = 0; i < s.Length; i++)
            {
                for (int j = 3; j <= 6; j++)
                {
                    for (int k = 2; k < 5; k++)
                    {
                        if (s[i] == keyboard[j][k])
                        {
                            x[i] = j;
                            y[i] = k;
                            goto mbox;
                        }
                    }
                }
                mbox:
                ;
            }

            for (int j = 3; j < 6; j++)
            {
                for (int k = 2; k < 5; k++)
                {
                    if (keyboard[j][k] != '.' && keyboard[j][k] != s[0])
                    {
                        int xx = j, yy = k;
                        bool ok = true;
                        for (int i = 1; i < x.Length; i++)
                        {
                            xx += x[i] - x[i - 1];
                            yy += y[i] - y[i - 1];

                            if (keyboard[xx][yy] == '.')
                            {
                                ok = false;
                                break;
                            }
                        }
                        if (ok)
                        {
                            writer.WriteLine("NO");
                            writer.Flush();
                            return;
                        }
                    }
                }
            }

            writer.WriteLine("YES");
            writer.Flush();
        }
    }
}

using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;

namespace CF317
{
	internal class Program
	{
		private static void Main(string[] args)
		{
			var sr = new InputReader(Console.In);
			//var sr = new InputReader(new StreamReader("input.txt"));
			var task = new Task();
			using (var sw = Console.Out)
			//using (var sw = new StreamWriter("output.txt"))
			{
				task.Solve(sr, sw);
				//Console.ReadKey();
			}
		}
	}

	internal class Task
	{
		public void Solve(InputReader sr, TextWriter sw)
		{
			var n = sr.NextInt32();
			var number = sr.NextString();
			var matrix = new[,] {
				{ '1', '2', '3' },
				{ '4', '5', '6' },
				{ '7', '8', '9' },
				{ '?', '0', '?' }
			};
			var operations = new List<Tuple<int, int>>();
			var sourceI = 0;
			var sourceJ = 0;
			for (var i = 0; i < n; i++) {
				var digit = number[i];
				var currI = 0;
				var currJ = 0;
				for (var k = 0; k < 4; k++) {
					for (var l = 0; l < 3; l++) {
						if (matrix[k, l] == digit) {
							currI = k;
							currJ = l;
						}
					}
				}
				if (operations.Count == 0) {
					operations.Add(new Tuple<int, int>(currI, currJ));
					sourceI = currI;
					sourceJ = currJ;
				}
				else {
					operations.Add(new Tuple<int, int>(currI - sourceI, currJ - sourceJ));
					sourceI = currI;
					sourceJ = currJ;
				}
			}
			var canCount = 0;
			for (var k = 0; k < 4; k++) {
				for (var l = 0; l < 3; l++) {
					if (k == 3 && l != 1) {
						continue;
					}
					var currI = k;
					var currJ = l;
					var can = true;
					for (var i = 1; i < operations.Count; i++) {
						var next = operations[i];
						if (!Can(currI, next.Item1, currJ, next.Item2)) {
							can = false;
							break;
						}
						else {
							currI += next.Item1;
							currJ += next.Item2;
						}
					}
					if (can) {
						canCount++;
					}
				}
			}

			if (canCount > 1) {
				sw.WriteLine("NO");
			}
			else {
				sw.WriteLine("YES");
			}
		}

		private bool Can(int i,int dI, int j, int dJ)
		{
			if (i + dI == 3) {
				if (i + dJ == 1) {
					return true;
				}
				else {
					return false;
				}
			}

			if (i + dI >= 0 && i + dI < 3 && j + dJ >= 0 && j + dJ < 3)
				return true;

			return false;
		}
	}
}

internal class InputReader : IDisposable
{
	private bool isDispose;
	private readonly TextReader sr;

	public InputReader(TextReader stream)
	{
		sr = stream;
	}

	public void Dispose()
	{
		Dispose(true);
		GC.SuppressFinalize(this);
	}

	public string NextString()
	{
		var result = sr.ReadLine();
		return result;
	}

	public int NextInt32()
	{
		return Int32.Parse(NextString());
	}

	public long NextInt64()
	{
		return Int64.Parse(NextString());
	}

	public string[] NextSplitStrings()
	{
		return NextString()
			.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
	}

	public T[] ReadArray<T>(Func<string, CultureInfo, T> func)
	{
		return NextSplitStrings()
			.Select(s => func(s, CultureInfo.InvariantCulture))
			.ToArray();
	}

	public T[] ReadArrayFromString<T>(Func<string, CultureInfo, T> func, string str)
	{
		return
			str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
				.Select(s => func(s, CultureInfo.InvariantCulture))
				.ToArray();
	}

	protected void Dispose(bool dispose)
	{
		if (!isDispose) {
			if (dispose)
				sr.Close();
			isDispose = true;
		}
	}

	~InputReader()
	{
		Dispose(false);
	}
}

using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;

namespace CF317
{
	internal class Program
	{
		private static void Main(string[] args)
		{
			var sr = new InputReader(Console.In);
			//var sr = new InputReader(new StreamReader("input.txt"));
			var task = new Task();
			using (var sw = Console.Out)
			//using (var sw = new StreamWriter("output.txt"))
			{
				task.Solve(sr, sw);
				//Console.ReadKey();
			}
		}
	}

	internal class Task
	{
		public void Solve(InputReader sr, TextWriter sw)
		{
			var n = sr.NextInt32();
			var number = sr.NextString();
			var matrix = new[,] {
				{ '1', '2', '3' },
				{ '4', '5', '6' },
				{ '7', '8', '9' },
				{ '?', '0', '?' }
			};
			var operations = new List<Tuple<int, int>>();
			for (var i = 0; i < n; i++) {
				var digit = number[i];
				var currI = 0;
				var currJ = 0;
				for (var k = 0; k < 4; k++) {
					for (var l = 0; l < 3; l++) {
						if (matrix[k, l] == digit) {
							currI = k;
							currJ = l;
						}
					}
				}
				if (operations.Count == 0) {
					operations.Add(new Tuple<int, int>(currI, currJ));
				}
				else {
					operations.Add(new Tuple<int, int>(currI - operations[operations.Count - 1].Item1, currJ - operations[operations.Count - 1].Item2));
				}
			}
			var canCount = 0;
			for (var k = 0; k < 4; k++) {
				for (var l = 0; l < 3; l++) {
					if (k == 3 && l != 1) {
						continue;
					}
					var currI = k;
					var currJ = l;
					var can = true;
					for (var i = 1; i < operations.Count; i++) {
						var next = operations[i];
						if (!Can(currI, next.Item1, currJ, next.Item2)) {
							can = false;
							break;
						}
						else {
							currI += next.Item1;
							currJ += next.Item2;
						}
					}
					if (can) {
						canCount++;
					}
				}
			}

			if (canCount > 1) {
				sw.WriteLine("NO");
			}
			else {
				sw.WriteLine("YES");
			}
		}

		private bool Can(int i,int dI, int j, int dJ)
		{
			if (i + dI == 3) {
				if (i + dJ == 1) {
					return true;
				}
				else {
					return false;
				}
			}

			if (i + dI >= 0 && i + dI < 3 && j + dJ >= 0 && j + dJ < 3)
				return true;

			return false;
		}
	}
}

internal class InputReader : IDisposable
{
	private bool isDispose;
	private readonly TextReader sr;

	public InputReader(TextReader stream)
	{
		sr = stream;
	}

	public void Dispose()
	{
		Dispose(true);
		GC.SuppressFinalize(this);
	}

	public string NextString()
	{
		var result = sr.ReadLine();
		return result;
	}

	public int NextInt32()
	{
		return Int32.Parse(NextString());
	}

	public long NextInt64()
	{
		return Int64.Parse(NextString());
	}

	public string[] NextSplitStrings()
	{
		return NextString()
			.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
	}

	public T[] ReadArray<T>(Func<string, CultureInfo, T> func)
	{
		return NextSplitStrings()
			.Select(s => func(s, CultureInfo.InvariantCulture))
			.ToArray();
	}

	public T[] ReadArrayFromString<T>(Func<string, CultureInfo, T> func, string str)
	{
		return
			str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
				.Select(s => func(s, CultureInfo.InvariantCulture))
				.ToArray();
	}

	protected void Dispose(bool dispose)
	{
		if (!isDispose) {
			if (dispose)
				sr.Close();
			isDispose = true;
		}
	}

	~InputReader()
	{
		Dispose(false);
	}
}

using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;

namespace CF317
{
	internal class Program
	{
		private static void Main(string[] args)
		{
			var sr = new InputReader(Console.In);
			//var sr = new InputReader(new StreamReader("input.txt"));
			var task = new Task();
			using (var sw = Console.Out)
			//using (var sw = new StreamWriter("output.txt"))
			{
				task.Solve(sr, sw);
				//Console.ReadKey();
			}
		}
	}

	internal class Task
	{
		public void Solve(InputReader sr, TextWriter sw)
		{
			var n = sr.NextInt32();
			var number = sr.NextString();
			var matrix = new[,] {
				{ '1', '2', '3' },
				{ '4', '5', '6' },
				{ '7', '8', '9' },
				{ '?', '0', '?' }
			};
			var operations = new List<Tuple<int, int>>();
			for (var i = 0; i < n; i++) {
				var digit = number[i];
				var currI = 0;
				var currJ = 0;
				for (var k = 0; k < 4; k++) {
					for (var l = 0; l < 3; l++) {
						if (matrix[k, l] == digit) {
							currI = k;
							currJ = l;
						}
					}
				}
				if (operations.Count == 0) {
					operations.Add(new Tuple<int, int>(currI, currJ));
				}
				else {
					operations.Add(new Tuple<int, int>(currI - operations[operations.Count - 1].Item1, currJ - operations[operations.Count - 1].Item2));
				}
			}
			var canCount = 0;
			for (var k = 0; k < 4; k++) {
				for (var l = 0; l < 3; l++) {
					if (k == 3 && l != 1) {
						continue;
					}
					var currI = k;
					var currJ = l;
					var can = true;
					for (var i = 1; i < operations.Count; i++) {
						var next = operations[i];
						if (!Can(currI, next.Item1, currJ, next.Item2)) {
							can = false;
						}
					}
					if (can) {
						canCount++;
					}
				}
			}

			if (canCount > 1) {
				sw.WriteLine("NO");
			}
			else {
				sw.WriteLine("YES");
			}
		}

		private bool Can(int i,int dI, int j, int dJ)
		{
			if (i + dI == 3) {
				if (i + dJ == 1) {
					return true;
				}
				else {
					return false;
				}
			}

			if (i + dI >= 0 && i + dI < 3 && j + dJ >= 0 && j + dJ < 3)
				return true;

			return false;
		}
	}
}

internal class InputReader : IDisposable
{
	private bool isDispose;
	private readonly TextReader sr;

	public InputReader(TextReader stream)
	{
		sr = stream;
	}

	public void Dispose()
	{
		Dispose(true);
		GC.SuppressFinalize(this);
	}

	public string NextString()
	{
		var result = sr.ReadLine();
		return result;
	}

	public int NextInt32()
	{
		return Int32.Parse(NextString());
	}

	public long NextInt64()
	{
		return Int64.Parse(NextString());
	}

	public string[] NextSplitStrings()
	{
		return NextString()
			.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
	}

	public T[] ReadArray<T>(Func<string, CultureInfo, T> func)
	{
		return NextSplitStrings()
			.Select(s => func(s, CultureInfo.InvariantCulture))
			.ToArray();
	}

	public T[] ReadArrayFromString<T>(Func<string, CultureInfo, T> func, string str)
	{
		return
			str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
				.Select(s => func(s, CultureInfo.InvariantCulture))
				.ToArray();
	}

	protected void Dispose(bool dispose)
	{
		if (!isDispose) {
			if (dispose)
				sr.Close();
			isDispose = true;
		}
	}

	~InputReader()
	{
		Dispose(false);
	}
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class cf1
{
    static void Main()
    {
        int int_digits = int.Parse(Console.ReadLine());
        string str_number = Console.ReadLine();
        string str_result = "NO";

        int digit2;
        bool b_half1 = false;
        bool b_half2 = false;

        foreach (char digit in str_number)
        {
            digit2 = int.Parse(digit.ToString());
            switch (digit2)
            {
                case 1:
                    if (str_number.Contains("9") || str_number.Contains("0"))
                    {
                        str_result = "YES";
                    }
                    if (str_number.Contains("3")||str_number.Contains("6"))
                    {
                        b_half1 = true;
                    }
                    if (str_number.Contains("7"))
                    {
                        b_half2 = true;
                    }
                    break;
                case 2:
                    if (str_number.Contains("0"))
                    {
                        str_result = "YES";
                    }
                    if (str_number.Contains("7") || str_number.Contains("8") || str_number.Contains("9"))
                    {
                        b_half2 = true;
                    }
                    break;
                case 3:
                    if (str_number.Contains("0") || str_number.Contains("7"))
                    {
                        str_result = "YES";
                    }
                    if (str_number.Contains("7") || str_number.Contains("8") || str_number.Contains("9"))
                    {
                        b_half2 = true;
                    }
                    break;
                case 4:
                    if (str_number.Contains("6")||str_number.Contains("3")||str_number.Contains("9"))
                    {
                        b_half1 = true;
                    }
                    break;
                case 7:
                    if (str_number.Contains("9")||str_number.Contains("3")||str_number.Contains("6"))
                    {
                        b_half1 = true;
                    }
                    break;
            }
        }
        if (b_half1==true & b_half2 == true)
        {
            str_result = "YES";
        }
        Console.WriteLine(str_result);
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class cf1
{
    static void Main()
    {
        int int_digits = int.Parse(Console.ReadLine());
        string str_number = Console.ReadLine();
        string str_result = "NO";

        int digit2;

        foreach (char digit in str_number)
        {
            digit2 = int.Parse(digit.ToString());
            switch (digit2)
            {
                case 1:
                    if (str_number.Contains("9") || str_number.Contains("0"))
                    {
                        str_result = "YES";
                    }
                    break;
                case 2:
                    if (str_number.Contains("0"))
                    {
                        str_result = "YES";
                    }
                    break;
                case 3:
                    if (str_number.Contains("0") || str_number.Contains("7"))
                    {
                        str_result = "YES";
                    }
                    break;
            }
        }
        Console.WriteLine(str_result);
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class cf1
{
    static void Main()
    {
        int int_digits = int.Parse(Console.ReadLine());
        string str_number = Console.ReadLine();
        string str_result = "NO";

        int digit2;
        bool b_half1 = false;
        bool b_half2 = false;

        foreach (char digit in str_number)
        {
            digit2 = int.Parse(digit.ToString());
            switch (digit2)
            {
                case 1:
                    if (str_number.Contains("9") || str_number.Contains("0"))
                    {
                        str_result = "YES";
                    }
                    if (str_number.Contains("3"))
                    {
                        b_half1 = true;
                    }
                    if (str_number.Contains("7"))
                    {
                        b_half2 = true;
                    }
                    break;
                case 2:
                    if (str_number.Contains("0"))
                    {
                        str_result = "YES";
                    }
                    break;
                case 3:
                    if (str_number.Contains("0") || str_number.Contains("7"))
                    {
                        str_result = "YES";
                    }
                    if (str_number.Contains("9"))
                    {
                        b_half2 = true;
                    }
                    break;
                case 4:
                    if (str_number.Contains("6"))
                    {
                        b_half1 = true;
                    }
                    break;
                case 7:
                    if (str_number.Contains("9"))
                    {
                        b_half1 = true;
                    }
                    break;
            }
        }
        if (b_half1==true & b_half2 == true)
        {
            str_result = "YES";
        }
        Console.WriteLine(str_result);
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class cf1
{
    static void Main()
    {
        int int_digits = int.Parse(Console.ReadLine());
        string str_number = Console.ReadLine();
        string str_result = "NO";

        int digit2;
        bool b_half1 = false;
        bool b_half2 = false;

        foreach (char digit in str_number)
        {
            digit2 = int.Parse(digit.ToString());
            switch (digit2)
            {
                case 1:
                    if (str_number.Contains("9") || str_number.Contains("0"))
                    {
                        str_result = "YES";
                    }
                    if (str_number.Contains("3")||str_number.Contains("6")||str_number.Contains("9"))
                    {
                        b_half1 = true;
                    }
                    if (str_number.Contains("7")||str_number.Contains("8")||str_number.Contains("9"))
                    {
                        b_half2 = true;
                    }
                    break;
                case 2:
                    if (str_number.Contains("0"))
                    {
                        str_result = "YES";
                    }
                    if (str_number.Contains("7") || str_number.Contains("8") || str_number.Contains("9"))
                    {
                        b_half2 = true;
                    }
                    break;
                case 3:
                    if (str_number.Contains("0") || str_number.Contains("7"))
                    {
                        str_result = "YES";
                    }
                    if (str_number.Contains("7") || str_number.Contains("8") || str_number.Contains("9"))
                    {
                        b_half2 = true;
                    }
                    break;
                case 4:
                    if (str_number.Contains("6")||str_number.Contains("3")||str_number.Contains("9"))
                    {
                        b_half1 = true;
                    }
                    break;
                case 7:
                    if (str_number.Contains("9")||str_number.Contains("3")||str_number.Contains("6"))
                    {
                        b_half1 = true;
                    }
                    break;
            }
        }
        if (b_half1==true & b_half2 == true)
        {
            str_result = "YES";
        }
        Console.WriteLine(str_result);
    }
}

using System;
using System.Collections;
using System.Collections.Generic;

namespace A
{
    class Program
    {
        public class TupleList<T1, T2, T3> : List<Tuple<int, int, string>>
        {
            public void Add(int item1, int item2, string s)
            {
                Add(new Tuple<int, int, string>(item1, item2, s));
            }
        }
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            string input = Console.ReadLine();
            int most_left = 2;
            int most_right = 0;
            int most_up = 4;
            int most_down = 1;

            for(int i = 0; i< n; i++)
            {
                int input_number = 0;
                if (input[i] - '0' == 0) input_number = 10;
                else input_number = input[i] - '0';
                if (most_right != 2 && (input_number-1) % 3 > most_right) most_right = (input_number-1)%3;
                if (most_left != 0 && (input_number-1) % 3 < most_left) most_left= (input_number-1) % 3;
                if (most_up != 1 && (input_number+2) / 3 < most_up) most_up = (input_number+2)/3;
                if (most_down != 4 && (input_number+2) / 3 > most_down) most_down = (input_number+2)/3;
            }

            if (most_right - most_left == 2 && most_down - most_up == 2) Console.WriteLine("YES");
            else if (most_down - most_up == 3) Console.WriteLine("YES");
            else Console.WriteLine("NO");

        }
    }
}

using System;
using System.Collections;
using System.Collections.Generic;

namespace A
{
    class Program
    {
        public class TupleList<T1, T2, T3> : List<Tuple<int, int, string>>
        {
            public void Add(int item1, int item2, string s)
            {
                Add(new Tuple<int, int, string>(item1, item2, s));
            }
        }
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            string input = Console.ReadLine();
            int most_left = 2;
            int most_right = 0;
            int most_up = 4;
            int most_down = 1;
            bool is_8_only_most_down = false;

            for(int i = 0; i< n; i++)
            {
                int input_number = 0;
                if (input[i] - '0' == 0) input_number = 11;
                else input_number = input[i] - '0';
                if (most_right != 2 && (input_number-1) % 3 > most_right) most_right = (input_number-1)%3;
                if (most_left != 0 && (input_number-1) % 3 < most_left) most_left= (input_number-1) % 3;
                if (most_up != 1 && (input_number+2) / 3 < most_up) most_up = (input_number+2)/3;
                if (most_down != 4 && (input_number+2) / 3 > most_down) most_down = (input_number+2)/3;
                if (!is_8_only_most_down && input_number == 8) is_8_only_most_down = true;
                if (is_8_only_most_down && (input_number == 7 || input_number == 9)) is_8_only_most_down = false;
            }

            if (most_right - most_left == 2 && most_down - most_up == 2)
            {
                if (!is_8_only_most_down) Console.WriteLine("YES");
                else Console.WriteLine("NO");
            }
            else if (most_down - most_up == 3) Console.WriteLine("YES");
            else Console.WriteLine("NO");

        }
    }
}

using System;
using System.Collections;
using System.Collections.Generic;

namespace A
{
    class Program
    {
        public class TupleList<T1, T2, T3> : List<Tuple<int, int, string>>
        {
            public void Add(int item1, int item2, string s)
            {
                Add(new Tuple<int, int, string>(item1, item2, s));
            }
        }
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            string input = Console.ReadLine();
            int most_left = 2;
            int most_right = 0;
            int most_up = 4;
            int most_down = 1;

            for(int i = 0; i< n; i++)
            {
                int input_number = 0;
                if (input[i] - '0' == 0) input_number = 11;
                else input_number = input[i] - '0';
                if (most_right != 2 && (input_number-1) % 3 > most_right) most_right = (input_number-1)%3;
                if (most_left != 0 && (input_number-1) % 3 < most_left) most_left= (input_number-1) % 3;
                if (most_up != 1 && (input_number+2) / 3 < most_up) most_up = (input_number+2)/3;
                if (most_down != 4 && (input_number+2) / 3 > most_down) most_down = (input_number+2)/3;
            }

            if (most_right - most_left == 2 && most_down - most_up == 2) Console.WriteLine("YES");
            else if (most_down - most_up == 3) Console.WriteLine("YES");
            else Console.WriteLine("NO");

        }
    }
}

using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;

// (づ°ω°)づﾐe★゜・。。・゜゜・。。・゜☆゜・。。・゜゜・。。・゜
public class Solver
{
    int[] xr = { 3, 0, 0, 0, 1, 1, 1, 2, 2, 2 };
    int[] xc = { 1, 0, 1, 2, 0, 1, 2, 0, 1, 2 };

    public void Solve()
    {
        int n = ReadInt();
        if (n == 1)
        {
            Write("NO");
            return;
        }
        string s = ReadToken();

        bool ans = true;
        for (int i = 0; i < 10; i++)
            if (s[0] - '0' != i)
            {
                int r = xr[i];
                int c = xc[i];
                bool ok = true;
                for (int j = 1; j < n; j++)
                {
                    int dr = xr[s[j] - '0'] - xr[s[j - 1] - '0'];
                    int dc = xc[s[j] - '0'] - xc[s[j - 1] - '0'];
                    r += dr;
                    c += dc;
                    if (r < 0 || r > 3 || (r == 2 && c != 1) || c < 0 || c > 2)
                        ok = false;
                }
                if (ok)
                    ans = false;
            }

        Write(ans ? "YES" : "NO");
    }

    #region Main

    protected static TextReader reader;
    protected static TextWriter writer;
    static void Main()
    {
#if DEBUG
        reader = new StreamReader("..\\..\\input.txt");
        //reader = new StreamReader(Console.OpenStandardInput());
        writer = Console.Out;
        //writer = new StreamWriter("..\\..\\output.txt");
#else
        reader = new StreamReader(Console.OpenStandardInput());
        writer = new StreamWriter(Console.OpenStandardOutput(),Encoding.ASCII);
        //reader = new StreamReader("input.txt");
        //writer = new StreamWriter("output.txt");
#endif
        try
        {
            new Solver().Solve();
            //var thread = new Thread(new Solver().Solve, 1024 * 1024 * 128);
            //thread.Start();
            //thread.Join();
        }
        catch (Exception ex)
        {
#if DEBUG
            Console.WriteLine(ex);
#else
            throw;
#endif
        }
        reader.Close();
        writer.Close();
    }

    #endregion

    #region Read / Write
    private static Queue<string> currentLineTokens = new Queue<string>();
    private static string[] ReadAndSplitLine() { return reader.ReadLine().Split(new[] { ' ', '\t', }, StringSplitOptions.RemoveEmptyEntries); }
    public static string ReadToken() { while (currentLineTokens.Count == 0)currentLineTokens = new Queue<string>(ReadAndSplitLine()); return currentLineTokens.Dequeue(); }
    public static int ReadInt() { return int.Parse(ReadToken()); }
    public static long ReadLong() { return long.Parse(ReadToken()); }
    public static double ReadDouble() { return double.Parse(ReadToken(), CultureInfo.InvariantCulture); }
    public static int[] ReadIntArray() { return ReadAndSplitLine().Select(int.Parse).ToArray(); }
    public static long[] ReadLongArray() { return ReadAndSplitLine().Select(long.Parse).ToArray(); }
    public static double[] ReadDoubleArray() { return ReadAndSplitLine().Select(s => double.Parse(s, CultureInfo.InvariantCulture)).ToArray(); }
    public static int[][] ReadIntMatrix(int numberOfRows) { int[][] matrix = new int[numberOfRows][]; for (int i = 0; i < numberOfRows; i++)matrix[i] = ReadIntArray(); return matrix; }
    public static int[][] ReadAndTransposeIntMatrix(int numberOfRows)
    {
        int[][] matrix = ReadIntMatrix(numberOfRows); int[][] ret = new int[matrix[0].Length][];
        for (int i = 0; i < ret.Length; i++) { ret[i] = new int[numberOfRows]; for (int j = 0; j < numberOfRows; j++)ret[i][j] = matrix[j][i]; } return ret;
    }
    public static string[] ReadLines(int quantity) { string[] lines = new string[quantity]; for (int i = 0; i < quantity; i++)lines[i] = reader.ReadLine().Trim(); return lines; }
    public static void WriteArray<T>(IEnumerable<T> array) { writer.WriteLine(string.Join(" ", array)); }
    public static void Write(params object[] array) { WriteArray(array); }
    public static void WriteLines<T>(IEnumerable<T> array) { foreach (var a in array)writer.WriteLine(a); }
    private class SDictionary<TKey, TValue> : Dictionary<TKey, TValue>
    {
        public new TValue this[TKey key]
        {
            get { return ContainsKey(key) ? base[key] : default(TValue); }
            set { base[key] = value; }
        }
    }
    private static T[] Init<T>(int size) where T : new() { var ret = new T[size]; for (int i = 0; i < size; i++)ret[i] = new T(); return ret; }
    #endregion
}

using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;

// (づ°ω°)づﾐe★゜・。。・゜゜・。。・゜☆゜・。。・゜゜・。。・゜
public class Solver
{
    int[] xr = { 3, 0, 0, 0, 1, 1, 1, 2, 2, 2 };
    int[] xc = { 1, 0, 1, 2, 0, 1, 2, 0, 1, 2 };

    public void Solve()
    {
        int n = ReadInt();
        string s = ReadToken();

        bool ans = true;
        for (int i = 0; i < 10; i++)
            if (s[0] - '0' != i)
            {
                int r = xr[i];
                int c = xc[i];
                bool ok = true;
                for (int j = 1; j < n; j++)
                {
                    int dr = xr[s[j] - '0'] - xr[s[j - 1] - '0'];
                    int dc = xc[s[j] - '0'] - xc[s[j - 1] - '0'];
                    r += dr;
                    c += dc;
                    if (r < 0 || r > 3 || (r == 2 && c != 1) || c < 0 || c > 2)
                        ok = false;
                }
                if (ok)
                    ans = false;
            }

        Write(ans ? "YES" : "NO");
    }

    #region Main

    protected static TextReader reader;
    protected static TextWriter writer;
    static void Main()
    {
#if DEBUG
        reader = new StreamReader("..\\..\\input.txt");
        //reader = new StreamReader(Console.OpenStandardInput());
        writer = Console.Out;
        //writer = new StreamWriter("..\\..\\output.txt");
#else
        reader = new StreamReader(Console.OpenStandardInput());
        writer = new StreamWriter(Console.OpenStandardOutput(),Encoding.ASCII);
        //reader = new StreamReader("input.txt");
        //writer = new StreamWriter("output.txt");
#endif
        try
        {
            new Solver().Solve();
            //var thread = new Thread(new Solver().Solve, 1024 * 1024 * 128);
            //thread.Start();
            //thread.Join();
        }
        catch (Exception ex)
        {
#if DEBUG
            Console.WriteLine(ex);
#else
            throw;
#endif
        }
        reader.Close();
        writer.Close();
    }

    #endregion

    #region Read / Write
    private static Queue<string> currentLineTokens = new Queue<string>();
    private static string[] ReadAndSplitLine() { return reader.ReadLine().Split(new[] { ' ', '\t', }, StringSplitOptions.RemoveEmptyEntries); }
    public static string ReadToken() { while (currentLineTokens.Count == 0)currentLineTokens = new Queue<string>(ReadAndSplitLine()); return currentLineTokens.Dequeue(); }
    public static int ReadInt() { return int.Parse(ReadToken()); }
    public static long ReadLong() { return long.Parse(ReadToken()); }
    public static double ReadDouble() { return double.Parse(ReadToken(), CultureInfo.InvariantCulture); }
    public static int[] ReadIntArray() { return ReadAndSplitLine().Select(int.Parse).ToArray(); }
    public static long[] ReadLongArray() { return ReadAndSplitLine().Select(long.Parse).ToArray(); }
    public static double[] ReadDoubleArray() { return ReadAndSplitLine().Select(s => double.Parse(s, CultureInfo.InvariantCulture)).ToArray(); }
    public static int[][] ReadIntMatrix(int numberOfRows) { int[][] matrix = new int[numberOfRows][]; for (int i = 0; i < numberOfRows; i++)matrix[i] = ReadIntArray(); return matrix; }
    public static int[][] ReadAndTransposeIntMatrix(int numberOfRows)
    {
        int[][] matrix = ReadIntMatrix(numberOfRows); int[][] ret = new int[matrix[0].Length][];
        for (int i = 0; i < ret.Length; i++) { ret[i] = new int[numberOfRows]; for (int j = 0; j < numberOfRows; j++)ret[i][j] = matrix[j][i]; } return ret;
    }
    public static string[] ReadLines(int quantity) { string[] lines = new string[quantity]; for (int i = 0; i < quantity; i++)lines[i] = reader.ReadLine().Trim(); return lines; }
    public static void WriteArray<T>(IEnumerable<T> array) { writer.WriteLine(string.Join(" ", array)); }
    public static void Write(params object[] array) { WriteArray(array); }
    public static void WriteLines<T>(IEnumerable<T> array) { foreach (var a in array)writer.WriteLine(a); }
    private class SDictionary<TKey, TValue> : Dictionary<TKey, TValue>
    {
        public new TValue this[TKey key]
        {
            get { return ContainsKey(key) ? base[key] : default(TValue); }
            set { base[key] = value; }
        }
    }
    private static T[] Init<T>(int size) where T : new() { var ret = new T[size]; for (int i = 0; i < size; i++)ret[i] = new T(); return ret; }
    #endregion
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
    class _689A
    {
        static void Main(string[] args)
        {
            int n = Int32.Parse(Console.ReadLine());
            var seq = Console.ReadLine().Select(x => (x-'0')).ToList();
            int[] left = new int[] {-1, -1, 1, 2, -1, 4, 5, -1, 7, 8 };
            int[] right = new int[] {-1, 2, 3, -1, 5, 6, -1, 8, 9, -1};
            int[] up = new int[] {8, -1, -1, -1, 1, 2, 3, 4, 5, 6 };
            int[] down = new int[] {-1, 4, 5, 6, 7, 8, 9, -1, -1, -1 };
            if (isCorrect(seq, left) || isCorrect(seq, right) || isCorrect(seq, up) || isCorrect(seq, down))
            {
                Console.WriteLine("NO");
            }
            else
            {
                Console.WriteLine("YES");
            }
        }
        static bool isCorrect(List<int> source, int[] mode)
        {
            foreach(var x in source)
            {
                int to = mode[x];
                if (to == -1)
                    return false;
            }
            return true;
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _689A
{
    class Program
    {
        static void Main(string[] args)
        {
            Solution sol = new Solution();
            int n = int.Parse(Console.ReadLine());
            string str = Console.ReadLine();
            Console.WriteLine(sol.GetOtherNumber(str) ? "YES" : "NO");
        }
    }

    public class Solution
    {
        IDictionary<int, int[]> mp = new Dictionary<int, int[]>()
        {
            { '0', new [] { 0, 1 } },
            { '1', new [] { 3, 0 } },
            { '2', new [] { 3, 1 } },
            { '3', new [] { 3, 2 } },
            { '4', new [] { 2, 0 } },
            { '5', new [] { 2, 1 } },
            { '6', new [] { 2, 2 } },
            { '7', new [] { 1, 0 } },
            { '8', new [] { 1, 1 } },
            { '9', new [] { 1, 2 } }
        };

        public bool GetOtherNumber(string n)
        {
            List<int[]> steps = new List<int[]>();

            for (int i = 1; i < n.Length; ++i)
                steps.Add(new[] { mp[n[i]][0] - mp[n[i - 1]][0], mp[n[i]][1] - mp[n[i - 1]][1] });

            for(int i = 0; i < 10; ++i)
            {
                if (i == n[0] - '0')
                    continue;

                int x = mp[i + '0'][0];
                int y = mp[i + '0'][1];
                int j = 0;
                for (; j < steps.Count; j++)
                {
                    x += steps[j][0];
                    y += steps[j][1];
                    if (OutOfTheBox(x, y))
                        break;
                }
                if (j == steps.Count)
                    return false;
            }
            return true;
        }

        public bool OutOfTheBox(int x, int y)
        {
            return x == 0 && y != 1 || x > 3 || y < 0 || y > 2;
        }
    }
}