[ l , r ] will be the range from total [ c , d ] x + y belongs For any r such that r = x + y We can choose z , in the range [ c , d ] only less than r , Thus total permutation be
x1 = int ( ( r * ( r + 1 ) ) / 2 ) NEW_LINE x2 = int ( ( l * ( l + 1 ) ) / 2 ) NEW_LINE ans = ans + ( x1 - x2 ) NEW_LINE return ans NEW_LINE