Diversity Number
https://www.facebook.com/codingcompetitions/hacker-cup/2011/round-1a/problems/A
Question
Let's call a sequence of integers almost monotonic if first K elements are non-decreasing sequence and last elements are non-increasing sequence: and .
The diversity number of a sequence is the number of possible sequences for which and all of the numbers are different. The diversity number of an empty sequence is 1.
You need to find the sum of the diversity numbers of all almost monotonic subsequences of a sequence. Since this number can be very large, find it modulo . A subsequence is a sequence that can be obtained from another sequence by deleting some elements without changing the order of the remaining elements. Two sequences are considered different if their lengths differ or there is at least one position at which they differ.
Input Format
The first line of the input file consists of a single number T, the number of test cases. Each test case consists of a number M, the number of elements in a sequence, followed by M numbers n, elements of some sequence (note that this sequence is not necessarily almost monotonic). All tokens are whitespace-separated.
Constraints
Output Format
Output T lines, with the answer to each test case on a single line.
Sample Inputs:
Last updated