for s in open(0):print(+(sum(max(0,s.count(p)-ord(p)%4)for p in'QRBNp')<9))