Help Prapor
Time limit1sMemory limit1024 MB
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 of numbers, where is odd. Build a complete weighted graph with vertices. The weight of the edge between vertices and () is the maximum of . The cost of array 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 of distinct integers. Compute the sum of the costs over all permutations of , modulo .
Input
The first line contains one odd integer , the length of array (). The second line contains distinct integers ().
Output
Print one number: the sum of the costs of all permutations of , modulo .