I’ve employed the same method described in the editorial just the implementation is a bit different.

For each index calculate the no. of A’s, B’s, and C’s till that index. Then calculate A[i]-B[i], B[i]-C[i] for each index. Store them in a structure. Sort them out. If there are X continuous pairs for which these are equal, add C(x,2) to the final count.

I am getting SIGSEGV and am not able to spot out the error. Any help would be appreciated.

Link for the code : link text