while 1:s=input();print(+(sum(max(s.count(c),ord(c)%4)for c in'QRBNp')<16))