while~0:s="Qpp"+input();print(+(sum(max(s.count(c)-2,0)for c in"pQRBN")<9))