Advertisement
Guest User

Untitled

a guest
Oct 16th, 2019
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.47 KB | None | 0 0
  1. input()
  2. s = input()
  3. def www(qqq):
  4. b = {0:0}
  5. for i in range(1, len(qqq)):
  6. j = b[i - 1]
  7. while j > 0 and qqq[j] != qqq[i]:
  8. j = b[j - 1]
  9. if qqq[j] == qqq[i]:
  10. j = j+1
  11. b[i] = j
  12. return b
  13.  
  14. def sss(k, qqq):
  15. b = www(qqq)
  16. i = 0
  17. j = 0
  18. while i< len(k) and j < len(qqq):
  19. if qqq[j] == k[i]:
  20. i = i+1
  21. j = j+1
  22. elif j == 0:
  23. i = i+1
  24. else:
  25. j = b[j - 1]
  26. else:
  27. if j == len(qqq):
  28. return i - j
  29. return -1
  30.  
  31. print(sss(s*2, s[::-1]))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement