Here you have to count the maximum number of consecutive zero and one. Suppose a is the maximum consecutive number of one & b is the maximum consecutive number of zero.
If a is greater then or equal P or b is greater than or equal Q then print he is in danger else he is safe.