Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- a,b = map(int,input().split())
- qw = set()
- def hash(st):
- h = 0
- for l,i in enumerate(st):
- h += ord(i) * pow(997*5,l,28429892811)
- h %= 28429892
- return h
- for i in range(a):
- qw.add(hash(input()))
- for i in range(b):
- er = input()
- t = hash(er)
- for i in range(len(er)):
- if er[i] != 'a' and t - ord(er[i])* pow(997*5,l,28429892811) + 97 * pow(997*5,l,28429892811) in qw:
- boo = 1
- print('YES')
- break
- if er[i] != 'b' and (t - ord(er[i])* pow(997*5,l,28429892811) + 98 * pow(997*5,l,28429892811))% 28429892811 in qw:
- boo = 1
- print('YES')
- break
- if er[i] != 'c' and t - ord(er[i])* pow(997*5,l,28429892811) % 28429892811 + 99 * pow(997*5,l,28429892811) in qw:
- boo = 1
- print('YES')
- break
- if boo == 0:
- print('NO')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement