AMR11H - Array Diversity

no tags 

Enough with this Harry Potter, please! What are we, twelve-year olds? Let's get our teeth into some real pumpkin pasties — oops, programming problems!

Here we go!

Let's define the diversity of a list of numbers to be the difference between the largest and smallest number in the list.

For example, the diversity of the list (1, -1, 2, 7) = 7 - (-1) = 8.

A substring of a list is considered a non-empty sequence of contiguous numbers from the list. For example, for the list (1, 3, 7), the substrings are (1), (3), (7), (1, 3), (3, 7), (1, 3, 7). A subsequence of a list is defined to be a non-empty sequence of numbers obtained by deleting some elements from the list. For example, for the list (1, 3, 7), the subsequences are (1), (3), (7), (1, 3), (3, 7), (1, 7), (1, 3, 7).

Given a list of length N find the number of substrings and subsequences in this list with the maximum diversity. If a substring/subsequence having maximum diversity occurs multiple times in the list, each of its occurrences adds towards the answer. And tell Harry Potter your answer.

Input

The first line contains T, the number of test cases. Then follow T test case blocks.

Each blocks starts with the first line containing the number N.

The second line contains a list of numbers in this list.

Output

For each test case, output the number of substrings and the number of subsequences in this list with the maximum diversity.

Since the answers may be very large, output them modulo 1000000007.

Constraints

T ≤ 10

N ≤ 100,000

Each number in the list is between 1 and 100,000 inclusive.

Example

Input:
3
3
1 2 3
4
1 4 3 4
3
3 2 1

Output:
1 2
3 6
1 2

hide comments
nadstratosfer: 2020-01-31 18:18:25

Cool problem. Seemed too hard when looked at it in the past, but gave in bit by bit once I sat down to it properly. Enjoyed the time spent here, including looking for evil cornercases.

YangYue: 2013-01-08 13:05:54

the output if all N elements are equal should be (n * (n + 1) / 2, 2 ^ n -1)
but I think it's incorrect..
I think the output should be (n, n)

Abhishek Kandoi: 2012-12-26 12:58:07

I am getting TLE around 9th Test Case, any help?
Also what should be the output if all N elements are equal?


Added by:Varun Jalan
Date:2011-12-15
Time limit:0.404s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64
Resource:Pratik Tandel - ICPC Asia regionals, Amritapuri 2011