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