EVILPRO - December Lunchtime

I was facing some problem in question Evil Proffessor of Dec Lunchtime. I have used an approach where i see all the consecutive pairs of the original string, and for each of them count the number of L,R pairs which will make the consecutive elements same. This approach solves the issue of time complexity BUT I am getting WRONG ANSWER for SUBTASK 2.
Problem Statement:
https://www.codechef.com/LTIME79B/problems/EVIPRO
MY CODE:
https://www.codechef.com/viewsolution/28544928