Company: De shaw
Difficulty: medium
You are given an integer array A of length N. For any non-empty subsequence P selected from A, define its Stability Score as follows: Rearrange the elements of P in non-decreasing order. Let the sorted sequence be indexed from 1 to |P|. A position i is called stable if the value at that position is exactly equal to its index. The Stability Score of P is the number of stable positions in the sorted subsequence. Example Consider: A = [10, 3, 2, 5, 11, 3, 1, 12] Choose the subsequence: P = [3, 2, 5, 3, 1] After sorting: P = [1, 2, 3, 3, 5] Positions 1, 2, 3, and 5 satisfy P[i] = i. Therefore, the Stability Score of this subsequence is 4. Your task is to evaluate every non-empty subsequence of the array and compute the sum of their Stability Scores. Since the answer may be very large, return it modulo 10 9 + 7. Input Format The first line contains an integer T — the number of test cases. For each test case: The first line contains an integer N. The second line contains N integers represent