##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
2
5 2 1 3 5 4
10 4 1 7 2 10 5 3 9 6 8
27
100
The beauty of an array of natural numbers is defined as follows.
Choose a non-negative integer and subtract from every element of the array. If all elements remain non-negative, then this is valid. For every valid , compute the MEX of the resulting array. The beauty of the array is the maximum of these MEX values over all valid .
You are given a permutation of length . For every pair of indices , consider the subarray and its beauty. Output the sum of these beauties over all such pairs .
consider the subarray which is . Its minimum is . If we choose and subtract it from all elements, we get (all non-negative). The MEX of is , so the beauty of this subarray is at least (and it is exactly ).
There are subarrays and the answer is .