#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;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8Y3N0cmluZz4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKIAppbnQgbWFpbigpIHsKCWNvbnN0IGludCBNQVhfU0laRSA9IDI1NjsKCWNoYXIgKmMgPSBuZXcgY2hhciBbTUFYX1NJWkVdOyAgICAgCgljaW4uZ2V0bGluZSAoYyxNQVhfU0laRSk7CiAgICBpbnQgYT0wOyAgICAgICAgCiAgICBmb3IoaW50IGk9MDtpPHN0cmxlbihjKTtpKyspewogICAgICAgIGErPWNbaV0tJzAnOwogICAgfQogICAgaWYoYSUzPT0wKWNvdXQ8PCJZRVMiOwogICAgZWxzZSBjb3V0PDwiTk8iOwogICAgcmV0dXJuIDA7Cn0=