Help in mexum in April 20 lunch time

How to solve positive mex . I calculated number of segments for each possible mex , since each mex must be from 1 to n+1.For example suppose we want to calculate for 2 in 1,1,1,2,2,1,1,1,3 , then first i will count all segments made by {1,1,1,1,1,1} multiply it with count of all segments made by {3} . Following is my code , which is correct on samples , please tell me where i am wrong , or tell at least a test case where it fails since codechef does not show test cases. code
Please help.