Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- input()
- s = input()
- def www(qqq):
- b = {0:0}
- for i in range(1, len(qqq)):
- j = b[i - 1]
- while j > 0 and qqq[j] != qqq[i]:
- j = b[j - 1]
- if qqq[j] == qqq[i]:
- j = j+1
- b[i] = j
- return b
- def sss(k, qqq):
- b = www(qqq)
- i = 0
- j = 0
- while i< len(k) and j < len(qqq):
- if qqq[j] == k[i]:
- i = i+1
- j = j+1
- elif j == 0:
- i = i+1
- else:
- j = b[j - 1]
- else:
- if j == len(qqq):
- return i - j
- return -1
- print(sss(s*2, s[::-1]))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement