#print("YES" if int(input())%3==0 else "NO")
a = "YES"
b = "NO"
print(a if int(input())%3==0 else b)
#print("YES" if int(input())%3==0 else "NO")
a = "YES"
b = "NO"
print(a if int(input())%3==0 else b)
#print("YES" if int(input())%3==0 else "NO")