{"raw_statement":[{"iden":"problem statement","content":"There are $N$ points numbered $1,2, \\dots, N$ on the $2$\\-dimensional plane. The coordinates of point $i$ are $(i,Y_i)$. In this problem, it is guaranteed that $Y=(Y_1,Y_2,\\dots ,Y_N)$ is a permutation of $(1,2, \\dots ,N)$.\nFind the sum of the areas of bounding boxes for all subsets $S$ of $\\lbrace \\texttt{point}\\,1,\\texttt{point}\\,2,\\dots ,\\texttt{point}\\,N \\rbrace$ with at least $2$ elements, modulo $998244353$.\nThe bounding box for $S$ refers to the minimum area rectangle with sides parallel to the $x$\\-axis that contains all points in $S$ inside or on the boundary."},{"iden":"constraints","content":"*   $2 \\le N \\le 2 \\times 10^5$\n*   $Y$ is a permutation of $(1,2, \\dots ,N)$.\n*   All input values are integers."},{"iden":"input","content":"The input is given from Standard Input in the following format:\n\n$N$\n$Y_1$ $Y_2$ $\\ldots$ $Y_N$"},{"iden":"sample input 1","content":"4\n2 3 1 4"},{"iden":"sample output 1","content":"50\n\nEach subset and the area of its bounding box are shown in the figure below. Output the sum of areas, which is $50$. ![image](https://img.atcoder.jp/arc201/d0a42940efeb582795eb4766786ddd68.png)"},{"iden":"sample input 2","content":"26\n6 14 8 19 13 25 26 22 7 3 16 15 11 24 1 12 20 23 5 17 9 2 21 10 4 18"},{"iden":"sample output 2","content":"575187918"}],"translated_statement":null,"sample_group":[],"show_order":["default"],"formal_statement":null,"simple_statement":null,"has_page_source":true}