Lots of geeky customers visit our chef's restaurant everyday. So, when asked to fill the feedback form, these customers represent the feedback using a binary string (i.e a string that contains only characters '0' and '1'.
Now since chef is not that great in deciphering binary strings, he has decided the following criteria to classify the feedback as Good or Bad :
If the string contains the substring "010" or "101", then the feedback is Good, else it is Bad. Note that, to be Good it is not necessary to have both of them as substring.
So given some binary strings, you need to output whether according to the chef, the strings are Good or Bad.
Input
The first line contains an integer T denoting the number of feedbacks. Each of the next T lines contains a string composed of only '0' and '1'.
Output
For every test case, print in a single line Good or Bad as per the Chef's method of classification.
Constraints
1 ≤ T ≤ 100
1 ≤ |S| ≤ 10^5
Sum of length of all strings in one test file will not exceed 6*10^6.
Example
Input:
2
11111110
10101010101010
Output:
Bad
Good
Explanation
Example case 1.
The string doesn't contain 010 or 101 as substrings.
Example case 2.
The string contains both 010 and 101 as substrings.
Assistant
We need to solve the problem: For each binary string S, check if it contains substring "010" or "101". If yes, output "Good", else "Bad". Constraints: T up to 100, each string length up to 100,000, total length across test cases up to 6 million. So we can just scan each string and look for these patterns. Complexity O(total length) which is fine.
Implementation: Read T, then loop T times: read string s, check if "010" in s or "101" in s, print accordingly. However, note that s may contain newline etc. Use input().strip().
But need to consider Python input speed: total length up to 6 million, reading lines and checking with substring search is fine.
Alternatively, could scan each string manually: for i in range(len(s)-2): if s[i:i+3] in ["010","101"]: good = True; break. But using in operator is efficient (Python's string search is implemented in C, uses fast algorithm). So simply:
if "010" in s or "101" in s: print("Good") else: print("Bad").
Edge cases: string length less than 3 -> cannot contain either substring -> Bad.
Thus solution straightforward.
Now produce answer with explanation and code.
The problem seems from CodeChef, maybe named "Good and Bad". But we need to output final answer with code.
We'll write Python solution.
Potential pitfalls: Input reading might include large lines, but reading line by line is fine. Use sys.stdin.read or sys.stdin.buffer for speed? Could just use sys.stdin.readline.
But let's provide efficient code:
import sys
def main():
data = sys.stdin.read().split()
# first token is T, then T strings
if not data: return
t = int(data[0])
out = []
for i in range(1, t+1):
s = data[i]
if "010" in s or "101" in s:
out.append("Good")
else:
out.append("Bad")
sys.stdout.write("\n".join(out))
if name == "main":
main()
This reads all tokens, works.
Alternatively, use sys.stdin.readline in loop.
Ok.
Now in final answer: Provide explanation, algorithm, complexity, and code.
We'll also note that we could use regex or find, but straightforward.
Write final answer. ```python
import sys
def main() -> None:
data = sys.stdin.read().split()
if not data:
return
t = int(data[0])
out_lines = []
# Iterate over the next t tokens (the binary strings)
for i in range(1, t + 1):
s = data[i]
if "010" in s or "101" in s:
out_lines.append("Good")
else:
out_lines.append("Bad")
sys.stdout.write("\n".join(out_lines))