atcoder#ARC128F. [ARC128F] Game against Robot

[ARC128F] Game against Robot

Score : 10001000 points

Problem Statement

There are NN cards numbered 11 to NN. Card ii has an integer AiA_i written on it. Here, NN is even.

Snuke and Robot will play a game, which will go as follows.

  • The game master announces a permutation (p1,p2,,pN)(p_1,p_2,\cdots,p_N) of (1,2,,N)(1,2,\cdots,N), to both Snuke and Robot.
  • Then, Snuke and Robot alternately take turns, with Snuke going first. Each turn goes as follows.- Snuke's turn: choose a remaining card of his choice and eat it.
    • Robot's turn: choose Card ii with the largest pip_i and burn it.
  • Snuke's turn: choose a remaining card of his choice and eat it.
  • Robot's turn: choose Card ii with the largest pip_i and burn it.
  • The game ends when there is no more card.

The final score of the game is the sum of integers written on the cards eaten by Snuke. Snuke will play optimally to maximize the score.

There are N!N! permutations pp of (1,2,,N)(1,2,\cdots,N). Find the sum, modulo 998244353998244353, of the final scores for all of these permutations.

Constraints

  • 1N1061 \leq N \leq 10^6
  • NN is even.
  • 1Ai1091 \leq A_i \leq 10^9
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN

A1A_1 A2A_2 \cdots ANA_N

Output

Print the answer.

2
1 2
4

Regardless of the permutation pp, Snuke will eat Card 22.

4
1 100 10000 1000000
24200400

For example, when p=(3,1,4,2)p=(3,1,4,2), the game will go as follows.

  • Snuke eats Card 33.
  • Robot burns Card 11.
  • Snuke eats Card 44.
  • Robot burns Card 22.

The score of the game here is 10100001010000.

10
866111664 178537096 844917655 218662351 383133839 231371336 353498483 865935868 472381277 579910117
710984634