What is wrong in my solution?

Question link- https://codeforces.com/contest/165/problem/C
My submission- https://codeforces.com/contest/165/submission/63779434

Can anyone tell where I am doing wrong.

K is like length of the substring least length for the substring , right?