CF1009E.Intercity Travelling
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Leha is planning his journey from Moscow to Saratov. He hates trains, so he has decided to get from one city to another by car.
The path from Moscow to Saratov can be represented as a straight line (well, it's not that straight in reality, but in this problem we will consider it to be straight), and the distance between Moscow and Saratov is n km. Let's say that Moscow is situated at the point with coordinate 0 km, and Saratov — at coordinate n km.
Driving for a long time may be really difficult. Formally, if Leha has already covered i kilometers since he stopped to have a rest, he considers the difficulty of covering (i+1) -th kilometer as ai+1 . It is guaranteed that for every i∈[1,n−1] ai≤ai+1 . The difficulty of the journey is denoted as the sum of difficulties of each kilometer in the journey.
Fortunately, there may be some rest sites between Moscow and Saratov. Every integer point from 1 to n−1 may contain a rest site. When Leha enters a rest site, he may have a rest, and the next kilometer will have difficulty a1 , the kilometer after it — difficulty a2 , and so on.
For example, if n=5 and there is a rest site in coordinate 2 , the difficulty of journey will be 2a1+2a2+a3 : the first kilometer will have difficulty a1 , the second one — a2 , then Leha will have a rest, and the third kilometer will have difficulty a1 , the fourth — a2 , and the last one — a3 . Another example: if n=7 and there are rest sites in coordinates 1 and 5 , the difficulty of Leha's journey is 3a1+2a2+a3+a4 .
Leha doesn't know which integer points contain rest sites. So he has to consider every possible situation. Obviously, there are 2n−1 different distributions of rest sites (two distributions are different if there exists some point x such that it contains a rest site in exactly one of these distributions). Leha considers all these distributions to be equiprobable. He wants to calculate p — the expected value of difficulty of his journey.
Obviously, p⋅2n−1 is an integer number. You have to calculate it modulo 998244353 .
输入格式
The first line contains one number n ( 1≤n≤106 ) — the distance from Moscow to Saratov.
The second line contains n integer numbers a1 , a2 , ..., an ( 1≤a1≤a2≤⋯≤an≤106 ), where ai is the difficulty of i -th kilometer after Leha has rested.
输出格式
Print one number — p⋅2n−1 , taken modulo 998244353 .
输入输出样例
输入#1
2 1 2
输出#1
5
输入#2
4 1 3 3 7
输出#2
60