def check(k):
sum = 0
has0 = False
while k > 0:
x = k % 10
sum += x
if x == 0:
has0 = True
k //= 10
return (sum % 3 == 0) and has0
def solve():
n = int(input())
if check(n):
print("YES")
else:
print("NO")
solve()