atcoder#ARC116B. [ARC116B] Products of Min-Max

[ARC116B] Products of Min-Max

Score : 400400 points

Problem Statement

Given is a sequence AA of NN integers. There are 2N12^N - 1 non-empty subsequences BB of AA. Find the sum of max(B)×min(B)\max\left(B\right) \times \min\left(B\right) over all of them.

Since the answer can be enormous, report it modulo 998244353998244353.

Constraints

  • All values in input are integers.
  • 1N2×1051 \leq N \leq 2 \times 10^5
  • 0Ai9982443520 \leq A_i \leq 998244352

Input

Input is given from Standard Input in the following format:

NN

A1A_1 A2A_2 \cdots ANA_N

Output

Print the answer.

3
2 4 3
63

There are 77 subsequences BB, as follows:

  • B=(2)B = \left(2\right) : max(B)×min(B)=4\max\left(B\right) \times \min\left(B\right) = 4
  • B=(4)B = \left(4\right) : max(B)×min(B)=16\max\left(B\right) \times \min\left(B\right) = 16
  • B=(3)B = \left(3\right) : max(B)×min(B)=9\max\left(B\right) \times \min\left(B\right) = 9
  • B=(2,4)B = \left(2, 4\right) : max(B)×min(B)=8\max\left(B\right) \times \min\left(B\right) = 8
  • B=(2,3)B = \left(2, 3\right) : max(B)×min(B)=6\max\left(B\right) \times \min\left(B\right) = 6
  • B=(4,3)B = \left(4, 3\right) : max(B)×min(B)=12\max\left(B\right) \times \min\left(B\right) = 12
  • B=(2,4,3)B = \left(2, 4, 3\right) : max(B)×min(B)=8\max\left(B\right) \times \min\left(B\right) = 8

The answer is the sum of them: 6363.

1
10
100
7
853983 14095 543053 143209 4324 524361 45154
206521341