{"problem":{"name":"All Pair Shortest Paths","description":{"content":"We have a grid with $2$ rows and $N$ columns. Let $(i,j)$ denote the square at the $i$\\-th row from the top and $j$\\-th column from the left. $(i,j)$ has a postive integer $x_{i,j}$ written on it. Two","description_type":"Markdown"},"platform":"AtCoder","limit":{"time_limit":4000,"memory_limit":262144},"difficulty":"None","is_remote":true,"is_sync":true,"sync_url":null,"sign":"arc158_e"},"statements":[{"statement_type":"Markdown","content":"We have a grid with $2$ rows and $N$ columns. Let $(i,j)$ denote the square at the $i$\\-th row from the top and $j$\\-th column from the left. $(i,j)$ has a postive integer $x_{i,j}$ written on it.\nTwo squares are said to be **adjacent** when they share a side.\nA **path** from square $X$ to $Y$ is a sequence $(P_1, \\ldots, P_n)$ of distinct squares such that $P_1 = X$, $P_n = Y$, and $P_i$ and $P_{i+1}$ are adjacent for every $1\\leq i \\leq n-1$. Additionally, the **weight** of that path is the sum of integers written on $P_1, \\ldots, P_n$.\nFor two squares $X$ and $Y$, let $f(X, Y)$ denote the minimum weight of a path from $X$ to $Y$. Find the sum of $f(X, Y)$ over all pairs of squares $(X,Y)$, modulo $998244353$.\n\n## Constraints\n\n*   $1\\leq N\\leq 2\\times 10^5$\n*   $1\\leq x_{i,j} \\leq 10^9$\n\n## Input\n\nThe input is given from Standard Input in the following format:\n\n$N$\n$x_{1,1}$ $\\ldots$ $x_{1,N}$\n$x_{2,1}$ $\\ldots$ $x_{2,N}$\n\n[samples]","is_translate":false,"language":"English"}],"meta":{"iden":"arc158_e","tags":[],"sample_group":[["1\n3\n5","24\n\nYou should find the sum of the following four values.\n\n*   For $X = (1,1), Y = (1,1)$: $f(X, Y) = 3$.\n*   For $X = (1,1), Y = (2,1)$: $f(X, Y) = 8$.\n*   For $X = (2,1), Y = (1,1)$: $f(X, Y) = 8$.\n*   For $X = (2,1), Y = (2,1)$: $f(X, Y) = 5$."],["2\n1 2\n3 4","76"],["5\n1 1000000000 1 1 1\n1 1 1 1000000000 1","66714886"]],"created_at":"2026-03-03 11:01:14"}}