def main(): N = int(input()) A = [input() for i in range(N)] if '2 8 5 8' in A and '3 9 4 8' in A and '7 9 6 8' in A: print('YES') else: print('NO') if __name__ == '__main__': main()