This page is still under construction.

Parts of this page are still being built. What you see may change.

Game

Time limit1sMemory limit256 MB

Summary
A robot starts uniformly at random in an array and may stop for A_i or gamble a fair step left or right; maximize the expected score, output modulo 998244353.
Level

Hard8 of 10

Topics
Dynamic programming, Probability, Math, Prefix sum
Solved
No attempts yet

Problem

You are playing a simple game. Given an array AA of length nn, you must control a robot that moves or stops within this array.

Initially, the robot's position is chosen at random: the probability that position i∈[1,n]i \in [1, n] is selected is 1n\frac{1}{n}. On each turn you know the current position, and you must decide between two actions.

  • Stop. If you choose this action, the game ends immediately. When the robot stops at position ii, your score is AiA_i.
  • Move. If you choose this action and the robot is at position ii, then with probability 50%50\% it moves to i−1i - 1 and with probability 50%50\% it moves to i+1i + 1. When the robot is at position 11 or nn, you cannot choose this action.

The second action can be chosen only when the robot is not at either end of the array, so for any strategy we can prove that lim⁡m→+∞f(m)=0\lim\limits_{m \rightarrow +\infty} f(m) = 0, where f(m)f(m) is the probability that the game is still going after mm turns.

Your task is to maximize the expected score of the game.

Input

The first line contains a single integer nn (1≤n≤5⋅1051 \le n \le 5 \cdot 10^5).

The second line contains nn integers A1,A2,…,AnA_1, A_2, \ldots, A_n (1≤Ai≤10121 \le A_i \le 10^{12}).

Output

Output a single line with the maximum possible expected score as a fraction modulo 998 244 353998\,244\,353. In other words, the answer can be expressed as a rational number P/QP / Q where QQ is coprime with 998 244 353998\,244\,353, and you must output (P⋅Q−1) mod 998 244 353(P \cdot Q^{-1}) \bmod 998\,244\,353.

Examples2

  1. Example 1

    Input
    3
    3 1 2
    
    Expected output
    499122179
    
  2. Example 2

    Input
    6
    6 1 2 5 3 4
    
    Expected output
    582309211