#include #include #include #include #include #include using namespace std; typedef long long LL; const int N = 1e6 + 10; int work(int T) { return 0; } char a[1100]; int check() { int len = strlen(a); if(a[len-1] == '0' || a[len-1] == '5') return 1; if( (a[len-1] - '0') % 2 == 0) return 1; int ans = 0; for(int i = 0; a[i]; i ++) ans += a[i] - '0', ans %= 3; return ans == 0; } int main() { while(gets(a)) { puts(check() ? "YES" : "NO"); } return 0; }