#include
#include
using namespace std;
int char_to_int(char symb) {
return symb - '0';
}
int main() {
string bufer;
cin >> bufer;
long long sum = 0, len = bufer.length();
for(int i = 0; i < len; ++i) {
sum += char_to_int(bufer[i]);
}
if(sum % 3 == 0)
cout << "YES";</p>
else
cout << "NO";</p>
system("pause");
}