Count the Orders

시간 제한1초메모리 제한2048 MB

요약
서로 다른 n개의 정수를 원 위에 배치해 인접한 수 차이의 절댓값 합을 최대로 만들고, 그 최댓값을 달성하는 배치의 수를 10^9+7로 나눈 나머지를 구한다.
난이도

어려움10점 중 8점

유형
그리디, 조합론, 정렬, 수학
정답자
아직 제출이 없습니다

문제

There are nn positions on a circle, numbered successively by integers from 11 to nn. The positions ii and i+1i + 1 are adjacent; the positions nn and 11 are also adjacent.

Consider nn distinct integers a_1,a_2,…,a_na\_1, a\_2, \ldots, a\_n. We arrange them somehow on the circle, so that there is a single integer in each of the nn positions. The cost of an arrangement is defined as the sum of the absolute values of the difference between every two adjacent integers.

Two arrangements are different if and only if at least one integer has different positions in them.

You need to find the maximum cost of an arrangement. Additionally, calculate the number of different arrangements that have this cost. As their number can be very large, find it modulo 109+710^9 + 7.

입력

The first line contains a single integer nn (3≤n≤1063 \le n \le 10^6).

The next line contains nn integers a_1,a_2,…,a_na\_1, a\_2, \ldots, a\_n (0≤a_i≤1090 \le a\_i \le 10^9).

It is guaranteed that a_1,a_2,…,a_na\_1, a\_2, \ldots, a\_n are pairwise distinct.

출력

Output a single line with two integers. The first one should be the maximum cost. The second one should be the number of different arrangements that have this cost, modulo 109+710^9 + 7.

예제2

  1. 예제 1

    입력
    3
    1 2 3
    
    예상 출력
    4 6
    
  2. 예제 2

    입력
    4
    2 4 8 16
    
    예상 출력
    36 8