#yukicoder No.1462 最弱WEAKER
def find_thr(N):
    i = 0
    while True:
        if 3 ** i > N:
            break
        else:
            thr = i
            i += 1
    return thr


N = int(input())
thr = find_thr(N)
ans = 1

while True:
    N -= 3 ** thr
    ans *= -1
    if N == 0:
        break
    elif N < 3 ** thr:
        thr = find_thr(N)

if ans == 1:
    print('YES')
else:
    print('NO')