n=int(eval(input()))

print(('No' if n % 3 else 'Yes'))

n = list(map(int, list(eval(input()))))



ans = 0

for i in n:

    ans = (ans + i) % 9

print(('Yes' if ans % 9 == 0 else 'No'))

n = int(eval(input()))
print(("No" if n % 3 else "Yes"))

n = list(map(int, list(eval(input()))))
ans = 0
for i in n:
    ans = (ans + i) % 9
print(("Yes" if ans % 9 == 0 else "No"))

-n = int(eval(input())) -print(("No" if n % 3 else "Yes")) +n = list(map(int, list(eval(input())))) +ans = 0 +for i in n: +    ans = (ans + i) % 9 +print(("Yes" if ans % 9 == 0 else "No"))