def can_win(X): if X == 0: return True current = 1 while current * 3 <= X: current *= 3 return not can_win(X - current) N = int(input()) print("YES" if can_win(N) else "NO")