maxi = 3;
for i in range(10):
a = int(input())
if ( (a % 7 == 0) and ( a > maxi or a == 3) ):
maxi = a;
if(maxi == 3):
print("NO")
else:
print(maxi)
maxi = 3;
for i in range(10):
a = int(input())
if ( (a % 7 == 0) and ( a > maxi or a == 3) ):
maxi = a;
if(maxi == 3):
print("NO")
else:
print(maxi)