#include <iostream>
#include <cmath>
#include <climits>
#include <numeric>
#include <algorithm>
#include <map>
#include <sstream>
#include <string>
#include <variant>
#include <vector>
#include <iomanip>

using namespace std;


vector<string> split(const string& haystack, const string& needle) {
    vector<string> result;
    size_t start_pos = 0;
    size_t found_pos = haystack.find(needle, start_pos);
    while (found_pos != string::npos) {
        size_t count = found_pos - start_pos;
        string token = haystack.substr(start_pos, count);
        if (!token.empty()) {
            result.push_back(token);
        }
        start_pos = found_pos + needle.length();
        found_pos = haystack.find(needle, start_pos);
    }
    string last_token = haystack.substr(start_pos);
    if (!last_token.empty()) {
        result.push_back(last_token);
    }
    return result;
}

int main() {
    
    string s; cin >> s;
    int sum = 0;
    for (int i = 0; i < s.length(); i++) {
        sum = sum + (s[i] - '0');
    }
    int digit_root = -1;
    if (sum % 9 == 0 && sum != 0) {
        digit_root = 9;
    }
    else {
        digit_root = sum%9;
    }
    if (digit_root == 9) {
        cout << "YES";
    }
    else {
        cout << "NO";
    }
    return 0;
}
