n = gets.to_i puts 20.times.any?{|c| 3**c == n-1} ? "YES" : "NO"