Pyramid Puzzle

View as PDF

Submit solution

Points: 10 (partial)
Time limit: 0.5s
Memory limit: 256M

Author:
Problem type

A large triangle is divided evenly into exactly eight rows of smaller unit triangles, like so:

          ^
         /0\            <-- Row 1
        /___\
       /1\2/3\          <-- Row 2
      /___V___\
     /4\5/6\7/8\        <-- Row 3
    /___V___V___\             .
   / .    .    . \            .                   ___
  / .     .     . \           .                  ('v')         (\_/)
 / .      .      . \    <-- Row 8               ((___))        (^x^)
/___________________\                             ^ ^          c(_)o

The unit triangles are position-numbered (in reading order) starting from zero.
N of them are shaded; the rest are all unshaded.

You can flip any set of unit triangles that make up (in shape, not necessarily in shade) one larger, upright, and three-row-high triangle.
Flipping reverses the shade of each of its nine unit triangles individually (shaded triangles become unshaded, vice versa).

Given an unlimited number of flips, is it possible to unify (in shade) the entire triangle?

Input Specification

The first line of input contains integer N (0 \le N \le 64), the total number of unit triangles that are shaded to begin with.
The next line contains N space-separated integers, each representing the position number of a shaded unit triangle.

Output Specification

Output YES or NO, whether or not it is possible to make the entire triangle the same shade (i.e. all shaded or all unshaded).

Sample Input 1

16
29 44 32 11 28 45 30 33 19 42 22 46 20 18 27 43

Sample Output 1

YES

Sample Input 2

1
2

Sample Output 2

NO

Comments

There are no comments at the moment.