#include <iostream>
#include <cstring>
using namespace std;
 
int main() {
	const int MAX_SIZE = 256;
	char *c = new char [MAX_SIZE];     
	cin.getline (c,MAX_SIZE);
    int a=0;        
    for(int i=0;i<strlen(c);i++){
        a+=c[i]-'0';
    }
    if(a%3==0)cout<<"YES";
    else cout<<"NO";
    return 0;
}