#include <iostream>
#include <string>
using namespace std;
int main() {
string s;
cin>>s;
int a=0;
for(int i=0;i<s.size();i++){
a+=s[i]-'0';
}
if(a%3==0)cout<<"YES";
else cout<<"NO";
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8c3RyaW5nPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKaW50IG1haW4oKSB7CglzdHJpbmcgczsJCQoJY2luPj5zOwkJCQoJaW50IGE9MDsJCQoJZm9yKGludCBpPTA7aTxzLnNpemUoKTtpKyspewoJCWErPXNbaV0tJzAnOwoJfQoJaWYoYSUzPT0wKWNvdXQ8PCJZRVMiOwoJZWxzZSBjb3V0PDwiTk8iOwoJcmV0dXJuIDA7Cn0=