n = int(input()) for i in range(30): if 3 ** i + 1 == n: print("YES") exit() print("NO")