#include<stdio.h>
//#include<bits/stdc++.h>
#include<string.h>
#include<iostream>
#include<math.h>
#include<sstream>
#include<set>
#include<queue>
#include<vector>
#include<algorithm>
#include<limits.h>
#define inf 0x3fffffff
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
using namespace std;
int main()
{
char s[100000];
int i;
__int64 sum;
int ans;
int len;
while(cin>>s)
{
sum=0;
len=strlen(s);
for(i=0;i<len;i++)
{
sum+=(s[i]-'0');
}
ans=s[len-1]-'0';
if(ans%2==0||s[len-1]=='5'||sum%3==0)
{
cout<<"YES"<<endl;
}
else
{
cout<<"NO"<<endl;
}
}
return 0;
}