Under construction

Still being built. Things may change

Help Prapor

Time limit1sMemory limit1024 MB

Summary
Given an odd-length array of distinct integers, sum the maximum-weight perfect matching cost over all permutations, modulo 998244353.
Level

Hard9 of 10

Topics
Combinatorics, Math, Dynamic programming
Solved
No attempts yet

Problem

Prapor is in no mood for jokes, but he has decided to take part in a contest. Just help him solve the problem.

Consider an array aa of nn numbers, where nn is odd. Build a complete weighted graph with n+1n + 1 vertices. The weight of the edge between vertices uu and vv (1≤u<v≤n1 \le u < v \le n) is the maximum of au,au+1,…,av−1a_u, a_{u+1}, \dots, a_{v-1}. The cost of array aa is the maximum total weight of a perfect matching in this graph. A perfect matching is a matching that covers all vertices.

You are given an array aa of nn distinct integers. Compute the sum of the costs over all permutations of aa, modulo 998 244 353998\,244\,353.

Input

The first line contains one odd integer nn, the length of array aa (1≤n≤100 0001 \le n \le 100\,000). The second line contains nn distinct integers a1,a2,…,ana_1, a_2, \dots, a_n (1≤ai≤1081 \le a_i \le 10^8).

Output

Print one number: the sum of the costs of all permutations of aa, modulo 998 244 353998\,244\,353.

Examples1

  1. Example 1

    Input
    3
    1 30 15
    
    Expected output
    300