#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
int wa(ll num) {
  if (num < 10) return num;
  return wa(num / 10) + num % 10;
}
int main() {
  ll n;
  cin >> n;
  while (n >= 10) {
    n = wa(n);
  }
  if (n % 9 == 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}
