Tweak the Peak


Michael has a favourite kind of skyline: one clean peak, and absolutely no valleys.

You are given an array of nn distinct integers. You may rearrange its elements in any order.

In a rearranged array, an index ii is a peak if 2in12 \le i \le n - 1 and both neighbours are strictly smaller: ai1<aia_{i-1} < a_i and ai+1<aia_{i+1} < a_i.

Similarly, an index ii is a valley if 2in12 \le i \le n - 1 and both neighbours are strictly larger: ai1>aia_{i-1} > a_i and ai+1>aia_{i+1} > a_i.

Count the number of distinct rearrangements of the array that have exactly one peak and zero valleys.

Since the answer can be large, output it modulo 998244353998244353.

Input

The first line contains the integer nn, the length of the array.

The second line contains nn integers: a1,a2,,ana_1, a_2, \ldots, a_n.

Output

Print the number of distinct rearrangements with exactly one peak and zero valleys, modulo 998244353998244353.

Constraints

  • 1n21051 \le n \le 2 \cdot 10^5
  • 1ai1091 \le a_i \le 10^9
  • All aia_i are distinct.

Example 1

Input 1
3
1 2 3
Output 1
2
Explanation

The valid rearrangements are [1,3,2][1, 3, 2] and [2,3,1][2, 3, 1].

Example 2

Input 2
4
1 2 3 4
Output 2
6

Example 3

Input 3
5
10 20 30 40 50
Output 3
14

Comments0


No comments yet

Be the first to comment.

New comment


Log in to join the discussion.