while 1:s=raw_input()+"="*9;i=d=0;exec"i+=ord(s[i])%3*d-d;d+=1;"*9;print+(i>0)