B. Ma5termind and Interesting Function

3.7

9 votes
Easy
Problem

We define a function F, on a array , P ,as follows:

F(P) = ( length(P) distinct(P))%(109+7)

where:

  • length(P) denotes the number of elements in array P.
  • distinct(P) denotes number of distinct elements in array P.

Ma5termind loves creating new challenges and he need your help testing his newest one. Given a array A consisting of N elements, compute the maximum value of F over all possible subarrays of A.

As result can be quite large, print it modulo 109+7.

Input:

Each input file will contain a T test cases.

First line will contain a single integer N denoting number of elements in array A.

Next line will contain a list of N integers Ai.

Ouput:

For each test case, output the answer in new line.

Constraints:

  • 1 ≤ T ≤ 5
  • 1 ≤ N ≤ 100000
  • 1 ≤ A[i] ≤ 100000000
See sample I/O for more clarification.

Scoring:

  • subtask 1: 1 ≤ N ≤ 1000 ( 30 pts )
  • subtask 2: 1 ≤ N ≤ 105 ( 70 pts )
Sample Input
1
2
1 2
Sample Output
4
Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

The maximum value of is for sub-array {1,2}.

Editor Image

?