import java.util.*; import java.io.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); PrintWriter ou = new PrintWriter(System.out); long a = Integer.parseInt(sc.next()); if(a % 3 == 0) ou.println("YES"); else ou.println("NO"); ou.flush(); sc.close(); } }