using System;
using System.Collections.Generic;
using System.Linq;
class Program
{
static string InputPattern = "InputX";
static List<string> GetInputList()
{
var WillReturn = new List<string>();
if (InputPattern == "Input1") {
WillReturn.Add("3");
WillReturn.Add("3 2 6");
//776412280
}
else if (InputPattern == "Input2") {
WillReturn.Add("1");
WillReturn.Add("998244352");
//998244352
}
else if (InputPattern == "Input3") {
WillReturn.Add("9");
WillReturn.Add("3 14 159 2653 58979 323846 2643383 27950288 419716939");
//545252774
}
else {
string wkStr;
while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
}
return WillReturn;
}
const long Hou = 998244353;
static void Main()
{
List<string> InputList = GetInputList();
long[] AArr = InputList[1].Split(' ').Select(pX => long.Parse(pX)).ToArray();
long UB = AArr.GetUpperBound(0);
var Ins_Fenwick_Tree = new Fenwick_Tree(AArr.Length, Hou);
long Gyakugen = DeriveGyakugen(AArr.Length);
for (long I = UB; 0 <= I; I--) {
long RangeSum = 0;
if (I + 1 <= UB) {
RangeSum = Ins_Fenwick_Tree.GetSum(I + 1, UB);
}
long CurrEx = AArr[I] + RangeSum * Gyakugen;
CurrEx %= Hou;
Ins_Fenwick_Tree.Add(I, CurrEx);
}
long Answer = Ins_Fenwick_Tree.GetSum(0, UB) * Gyakugen;
Answer %= Hou;
Console.WriteLine(Answer);
}
// 引数の逆元を求める
static Dictionary<long, long> mMemo2 = new Dictionary<long, long>();
static long DeriveGyakugen(long pLong)
{
if (mMemo2.ContainsKey(pLong)) {
return mMemo2[pLong];
}
return mMemo2[pLong] = DeriveBekijyou(pLong, Hou - 2, Hou);
}
// 繰り返し2乗法で、(NのP乗) Mod Mを求める
static long DeriveBekijyou(long pN, long pP, long pM)
{
long CurrJyousuu = pN % pM;
long CurrShisuu = 1;
long WillReturn = 1;
while (true) {
// 対象ビットが立っている場合
if ((pP & CurrShisuu) > 0) {
WillReturn = (WillReturn * CurrJyousuu) % pM;
}
CurrShisuu *= 2;
if (CurrShisuu > pP) return WillReturn;
CurrJyousuu = (CurrJyousuu * CurrJyousuu) % pM;
}
}
}
// フェニック木
#region Fenwick_Tree
internal class Fenwick_Tree
{
private long[] mBitArr;
private long mN;
private long mHou;
// コンストラクタ
internal Fenwick_Tree(long pItemCnt, long pHou)
{
mN = pItemCnt;
mBitArr = new long[pItemCnt + 1];
mHou = pHou;
}
// [pSta,pEnd] のSumを返す
internal long GetSum(long pSta, long pEnd)
{
long Result = GetSum(pEnd) - GetSum(pSta - 1);
Result %= mHou;
return Result;
}
// [0,pEnd] のSumを返す
internal long GetSum(long pEnd)
{
pEnd++; // 1オリジンに変更
long Sum = 0;
while (pEnd >= 1) {
Sum += mBitArr[pEnd];
Sum %= mHou;
pEnd -= pEnd & -pEnd;
}
return Sum;
}
// [I] に Xを加算
internal void Add(long pI, long pX)
{
pI++; // 1オリジンに変更
while (pI <= mN) {
mBitArr[pI] += pX;
mBitArr[pI] %= mHou;
pI += pI & -pI;
}
}
}
#endregion