#include <bits/stdc++.h>
using namespace std;
int main() {
  unsigned long long int n, r, sum = 0;
  cin >> n;
  while (n) {
    r = n % 10;
    sum = sum * 10 + r;
    n = n / 10;
  }
  if (sum % 9 == 0)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return 0;
}
