Advertisement
Guest User

Untitled

a guest
Nov 20th, 2019
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. a,b = map(int,input().split())
  2. qw = set()
  3. def hash(st):
  4. h = 0
  5. for l,i in enumerate(st):
  6. h += ord(i) * pow(997*5,l,28429892811)
  7. h %= 28429892
  8. return h
  9.  
  10. for i in range(a):
  11. qw.add(hash(input()))
  12.  
  13. for i in range(b):
  14. er = input()
  15. t = hash(er)
  16. for i in range(len(er)):
  17. if er[i] != 'a' and t - ord(er[i])* pow(997*5,l,28429892811) + 97 * pow(997*5,l,28429892811) in qw:
  18. boo = 1
  19. print('YES')
  20. break
  21. if er[i] != 'b' and (t - ord(er[i])* pow(997*5,l,28429892811) + 98 * pow(997*5,l,28429892811))% 28429892811 in qw:
  22. boo = 1
  23. print('YES')
  24. break
  25. if er[i] != 'c' and t - ord(er[i])* pow(997*5,l,28429892811) % 28429892811 + 99 * pow(997*5,l,28429892811) in qw:
  26. boo = 1
  27. print('YES')
  28. break
  29. if boo == 0:
  30. print('NO')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement