A Little Elephant from the Zoo of Lviv likes lucky strings, i.e., the strings that consist only of the lucky digits 4 and 7.

The Little Elephant has K favorite lucky strings A_{1}, A_{2}, ..., A_{K}. He thinks that the lucky string S is good if either |S| ≥ 47 or for some j from 1 to K we have that  A_{j} is a substring of S.

The Little Elephant has found N lucky strings B_{1}, B_{2}, ..., B_{N} under the pillow. Now he wants to know which of them are good. Help him and find for each i from 1 to N whether the string B_{i} is good or not.

Notes.

Let S be some lucky string. Then

|S| denotes the length of the string S;

S[i] (1 ≤ i ≤ |S|) denotes the i^{th} character of S (the numeration of characters starts from 1);

The string T of the length M is called a substring of S if for some k from 0 to |S| - M we have 
T[1] = S[k + 1], T[2] = S[k + 2], ..., T[M] = S[k + M].

------ Input ------ 

The first line of the input file contains two integers K and N, the number of favorite lucky strings of the Little Elephant and the number of strings he has found under the pillow. Each of the following K lines contains one favorite lucky string. Namely, j^{th} line among these K lines contains the string A_{j}. Each of the following N lines contains one lucky string that was found under the pillow. Namely, i^{th} line among these N lines contains the string B_{i}. The input file does not contain any whitespaces.

------ Output ------ 

For each of the N strings that were found under the pillow print Good if it is good, and Bad otherwise.

------ Constraints ------ 

1 ≤ K, N ≤ 50
For each string S in the input file we have 1 ≤ |S| ≤ 50.
Each string in the input file consists only of the lucky digits 4 and 7.

----- Sample Input 1 ------ 
2 4
47
744
7444
447
7774
77777777777777777777777777777777777777777777774
----- Sample Output 1 ------ 
Good
Good
Bad
Good
----- explanation 1 ------ 
The string S = 7444 is good since the favorite string 744 is its substring.
The string S = 447 is good since the favorite string 47 is its substring.
The string S = 7774 is bad since none of the favorite strings 47 and 744 is a substring of S.
The string S = 77777777777777777777777777777777777777777777774 is good since its length is 47. Note, however, that S does not have favorite substrings at all.

Difficulty: EASY
Tags: String algorithms

Data structures

Complete search
Skill types: Data structures

Complete search

Starter code:

Solutions:
(k, n) = map(int, input().split())
(good, luckystring) = ([], [])
flag = 0
for i in range(k):
	good.append(input())
for i in range(n):
	luckystring.append(input())
for i in luckystring:
	if len(i) >= 47:
		flag = 1
	else:
		for f in good:
			if i.find(f) != -1:
				flag = 1
				break
			else:
				continue
	if flag:
		print('Good')
	else:
		print('Bad')
	flag = 0


(K, N) = map(int, input().split())
P = []
for m in range(K):
	A = input()
	P.append(A)
for i in range(N):
	S = input()
	if len(S) >= 47:
		print('Good')
	else:
		for j in P:
			if j in S:
				print('Good')
				break
		else:
			print('Bad')


(k, n) = map(int, input().split())
l = []
for i in range(k):
	l.append(input())
for i in range(n):
	j = input()
	if len(j) >= 47 or any((z in j for z in l)):
		print('Good')
	else:
		print('Bad')


(t, s) = map(int, input().split(' '))
li = []
for i in range(t):
	li.append(input())
for i in range(s):
	c = 0
	s1 = input()
	if len(s1) >= 47:
		print('Good')
		c = 1
	else:
		for i in li:
			if i in s1:
				print('Good')
				c = 1
				break
	if c == 0:
		print('Bad')


(n, k) = map(int, input().split())
li1 = []
for i in range(n):
	s = input()
	li1.append(s)
for j in range(k):
	s2 = input()
	if len(s2) >= 47:
		print('Good')
	else:
		for k in li1:
			if k in s2:
				print('Good')
				break
		else:
			print('Bad')


(k, n) = map(int, input().split())
flag = 0
fav = []
found = []
for i in range(k):
	fav.append(input())
for j in range(n):
	found.append(input())
for x in found:
	for y in fav:
		if y in x:
			print('Good')
			flag = 1
			break
	if flag == 0 and len(x) >= 47:
		print('Good')
	elif flag == 0:
		print('Bad')
	flag = 0


(a, b) = map(int, input().split())
l = []
for i in range(a):
	l.append(input())
for j in range(b):
	s = input()
	for i in l:
		if i in s:
			print('Good')
			break
	else:
		if len(s) >= 47:
			print('Good')
		else:
			print('Bad')


(n, k) = map(int, input().split())
list1 = []
for i in range(n):
	list1.append(input())
for i in range(k):
	string = input()
	if len(string) >= 47:
		print('Good')
		continue
	for lis in list1:
		if lis in string:
			print('Good')
			break
	else:
		print('Bad')


import re
(lucky, found) = map(int, input().split(' '))
arr_luck = []
for i in range(lucky):
	arr_luck.append(str(input()))
for j in range(found):
	flag = 0
	check = str(input())
	for x in arr_luck:
		if re.search(x, check) or len(check) >= 47:
			flag = 1
			print('Good')
			break
	if flag == 0:
		print('Bad')


(n, p) = map(int, input().split())
l = []
for i in range(n):
	l.append(input())
for j in range(p):
	test = input()
	if len(test) >= 47:
		print('Good')
		continue
	for i in l:
		if i in test:
			print('Good')
			break
	else:
		print('Bad')


(k, n) = map(int, input().split())
lst = []
for i in range(k):
	lst.append(input())
for j in range(n):
	s = input()
	if len(s) >= 47:
		print('Good')
		continue
	for j in lst:
		if j in s:
			print('Good')
			break
	else:
		print('Bad')


(n, m) = map(int, input().split())
fav = []
for i in range(n):
	fav.append(input())
for i in range(m):
	x = input()
	if len(x) >= 47 or any((i in x for i in fav)):
		print('Good')
	else:
		print('Bad')


(K, N) = map(int, input().split())
s1 = []
for i in range(K):
	s1.append(input())
for j in range(N):
	s2 = input()
	if len(s2) >= 47:
		print('Good')
		continue
	for c in s1:
		if c in s2:
			print('Good')
			break
	else:
		print('Bad')


(k, n) = map(int, input().split())
a = []
b = []
for i in range(k):
	a.append(input())
for i in range(n):
	flag = 0
	b.append(input())
	if len(b[i]) >= 47:
		flag = 1
	for j in a:
		if j in b[i]:
			flag = 1
			break
	print('Good' if flag == 1 else 'Bad')


def is_good_lucky_string(lucky_string, favorite_lucky_strings):
	if len(lucky_string) >= 47:
		return True
	for favorite_lucky_string in favorite_lucky_strings:
		if favorite_lucky_string in lucky_string:
			return True
	return False
(k, n) = map(int, input().split())
favorite_lucky_strings = set()
for i in range(k):
	favorite_lucky_strings.add(input().strip())
for i in range(n):
	lucky_string = input().strip()
	if is_good_lucky_string(lucky_string, favorite_lucky_strings):
		print('Good')
	else:
		print('Bad')


(k, n) = map(int, input().split())
ls = []
for l in range(k):
	ls.append(input())
for s in range(n):
	test = input()
	if len(test) >= 47:
		print('Good')
		continue
	for l in ls:
		if l in test:
			print('Good')
			break
	else:
		print('Bad')


(n, k) = map(int, input().split())
l = []
for _ in range(n):
	a = input()
	l.append(a)
for _ in range(k):
	c = 0
	ss = input()
	for i in l:
		if i in ss or len(ss) >= 47:
			c = 1
	if c == 1:
		print('Good')
	else:
		print('Bad')


(k, n) = map(int, input().split())
l = []
for i in range(k):
	l.append(input())
for i in range(n):
	t = input()
	if len(t) >= 47:
		print('Good')
		continue
	for j in l:
		if j in t:
			print('Good')
			break
	else:
		print('Bad')


(n, k) = map(int, input().split(' '))
l = []
for i in range(n):
	l.append(input())
for i in range(k):
	c = 0
	s = input()
	if len(s) >= 47:
		print('Good')
		c = 1
	else:
		for i in l:
			if i in s:
				print('Good')
				c = 1
				break
	if c == 0:
		print('Bad')


(a, b) = map(int, input().split())
list1 = []
for i in range(a):
	ask1 = input()
	list1.append(ask1)
for j in range(b):
	ask2 = input()
	if len(ask2) >= 47:
		print('Good')
	else:
		for k in list1:
			if k in ask2:
				print('Good')
				break
		else:
			print('Bad')


data = list(map(int, input().split()))
lst = []
lst1 = []
c = 0
for i in range(data[0]):
	lst.append(input())
for j in range(data[1]):
	s = input()
	if len(s) >= 47:
		print('Good')
		continue
	for l in lst:
		if l in s:
			print('Good')
			break
	else:
		print('Bad')


(k, n) = map(int, input().split())
k_l = []
n_l = []
good = 0
for i in range(k):
	k_l.append(input())
for i in range(n):
	nl = input()
	good = 0
	if len(nl) >= 47:
		print('Good')
		good = 1
		continue
	else:
		for j in k_l:
			if j in nl:
				print('Good')
				good = 1
				break
		else:
			print('Bad')


(k, n) = map(int, input().split())
l = []
for i in range(k):
	l.append(input())
for i in range(n):
	temp = input()
	if len(temp) >= 47:
		print('Good')
	else:
		for i in l:
			if i in temp:
				print('Good')
				break
		else:
			print('Bad')


(m, n) = map(int, input().split())
l = []
for i in range(m):
	l.append(input())
for j in range(n):
	s = input()
	if len(s) >= 47:
		print('Good')
		continue
	for e in l:
		if e in s:
			print('Good')
			break
	else:
		print('Bad')


(a, b) = map(int, input().strip().split())
l = []
for i in range(1, a + 1):
	s = input()
	l.append(s)
for j in range(1, b + 1):
	s1 = input()
	flag = 0
	for k in range(len(l)):
		if l[k] in s1:
			flag = 1
	if flag == 1 or len(s1) >= 47:
		print('Good')
	else:
		print('Bad')


(k, n) = map(int, input().split(' '))
a = []
for i in range(k):
	a.append(input())
for j in range(n):
	p = input()
	if len(p) >= 47:
		print('Good')
		continue
	else:
		c = 0
		for num in a:
			if num in p:
				c = 1
				break
		if c == 1:
			print('Good')
		else:
			print('Bad')


(k, n) = map(int, input().split())
lucky = []
for i in range(k):
	str1 = input()
	lucky.append(str1)
for i in range(n):
	str2 = input()
	size = len(str2)
	if size >= 47:
		print('Good')
	else:
		for str3 in lucky:
			if str3 in str2:
				print('Good')
				break
		else:
			print('Bad')


import sys
from sys import stdin
(k, n) = map(int, stdin.readline().split())
lcky = []
for i in range(k):
	lcky.append(input())
lst = []
for j in range(n):
	lst.append(input())
for each in lst:
	ans = 'Bad'
	if len(each) >= 47:
		print('Good')
	else:
		for lckstr in lcky:
			if lckstr in each:
				ans = 'Good'
		print(ans)


(k, n) = map(int, input().split())
s = []
for i in range(k):
	s.append(input())
for i in range(n):
	a = input()
	if len(a) >= 47 or any((i in a for i in s)):
		print('Good')
	else:
		print('Bad')


(j, k) = map(int, input().split())
a = []
b = []
for i in range(j):
	a.append(input())
for i in range(k):
	b.append(input())
for i in range(len(b)):
	r = 0
	for j in range(len(a)):
		x = b[i]
		f = x.count(a[j])
		r = r + f
	if len(b[i]) >= 47 or r > 0:
		print('Good')
	else:
		print('Bad')


(wife, goals) = map(int, input().split())
life = []
for aim in range(wife):
	life.append(input())
for girl in range(goals):
	stress = input()
	for death in life:
		if death in stress:
			print('Good')
			break
	else:
		if len(stress) >= 47:
			print('Good')
		else:
			print('Bad')


(K, N) = map(int, input().split())
a = []
for i in range(K):
	m = int(input())
	a.append(str(m))
for j in range(N):
	s = input()
	li = []
	flag = 0
	if len(s) >= 47:
		print('Good')
	else:
		for k in range(len(s)):
			for l in range(k + 1, len(s) + 1):
				li.append(s[k:l])
		for p in range(K):
			if a[p] in li:
				flag += 1
				break
		if flag == 1:
			print('Good')
		else:
			print('Bad')


(a, b) = map(int, input().split())
fav = []
for i in range(a):
	fav.append(input())
for i in range(b):
	n = input()
	if len(n) >= 47 or any((i in n for i in fav)):
		print('Good')
	else:
		print('Bad')


(K, N) = map(int, input().split())
S = []
for _ in range(K):
	S.append(input())
for _ in range(N):
	c = input()
	ok = 'Bad'
	if len(c) >= 47:
		del (c, ok)
		print('Good')
		continue
	for x in S:
		if x in c:
			ok = 'Good'
			del c
			break
	print(ok)


(f, n) = map(int, input().split())
ls = []
for i in range(f):
	ls.append(input())
for j in range(n):
	s = input()
	if len(s) >= 47:
		print('Good')
		continue
	else:
		for l in ls:
			if l in s:
				print('Good')
				break
		else:
			print('Bad')


(x, y) = map(int, input().split())
favourite = []
for i in range(x):
	favourite.append(input())
for i in range(y):
	n = input()
	if len(n) >= 47 or any((i in n for i in favourite)):
		print('Good')
	else:
		print('Bad')


(k, n) = map(int, input().split())
l = []
a = True
for i in range(k):
	l.append(input())
for j in range(n):
	p = input()
	a = len(p)
	if a >= 47:
		print('Good')
		continue
	for i in l:
		if i in p:
			print('Good')
			break
	else:
		print('Bad')