Game
Time limit1sMemory limit256 MB
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 of length , 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 is selected is . 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 , your score is .
- Move. If you choose this action and the robot is at position , then with probability it moves to and with probability it moves to . When the robot is at position or , 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 , where is the probability that the game is still going after turns.
Your task is to maximize the expected score of the game.
Input
The first line contains a single integer ().
The second line contains integers ().
Output
Output a single line with the maximum possible expected score as a fraction modulo . In other words, the answer can be expressed as a rational number where is coprime with , and you must output .