Alice wants to send a classified message to Bob. She tries to encrypt the message with her original encryption method. The message is a string $S$, which consists of $N$ lowercase letters.
$S[a…b]$ means a substring of S ranging from $S[a]$ to $S[b]$ ($0≤a≤b<N$). If the first $i$ letters have been encrypted, Alice will try to find a magic string $P$. Assuming $P$ has $K$ letters, $P$ is the longest string which satisfies $P=S[T...T+K-1]$ ($0≤T<i$,$T+K≤N$) and $P=S[i…i+K-1] (i+K≤N)$. In other words, $P$ is a substring of $S$, of which starting address is within $[0...i-1]$, and $P$ is also a prefix of $S[i...N-1]$. If $P$ exists, Alice will append integer $K$ and $T$ to ciphertext. If $T$ is not unique, Alice would select the minimal one. And then $i$ is incremented by $K$. If $P$ does not exist, Alice will append -1 and the ASCII code of letter $S[i]$ to ciphertext, and then increment $i$ by 1.
Obviously the first letter cannot be encrypted. That is to say, $P$ does not exist when $i=0$. So the first integer of ciphertext must be -1, and the second integer is the ASCII code of $S[0]$.
When $i=N$, all letters are encrypted, and Alice gets the final ciphertext, which consists of many pairs of integers. Please help Alice to implement this method.