from sys import setrecursionlimit from functools import lru_cache from math import log setrecursionlimit(10 ** 6) N = int(input()) @lru_cache(maxsize=10000) def f(n): if n == 0: return True a = int(log(n, 3)) for i in range(a + 1): if f(n - 3 ** i): continue return True return False if f(N): print('YES') else: print('NO')