main = interact c (a:s)!(b:t)|a==b=a:t|1<3=a:s!ts!_=sm?s|length s==m=s|a<-s!drop m s=(last$0:[m+1|a==s])?ac=(0?)
ideone
ide
The brand new service which powers Ideone!
Widget for compiling and running the source code in a web browser!