{"problem":{"name":"Ex - Yet Another Path Counting","description":{"content":"We have a grid of squares with $N$ rows arranged vertically and $N$ columns arranged horizontally. The square at the $i$\\-th row from the top and $j$\\-th column from the left has an integer label $a_{","description_type":"Markdown"},"platform":"AtCoder","limit":{"time_limit":2000,"memory_limit":262144},"difficulty":"None","is_remote":true,"is_sync":true,"sync_url":null,"sign":"abc259_h"},"statements":[{"statement_type":"Markdown","content":"We have a grid of squares with $N$ rows arranged vertically and $N$ columns arranged horizontally. The square at the $i$\\-th row from the top and $j$\\-th column from the left has an integer label $a_{i,j}$.  \nConsider paths obtained by starting on one of the squares and going **right or down** to an adjacent square zero or more times. Find the number, modulo $998244353$, of such paths that start and end on squares with the same label.  \nTwo paths are distinguished when they visit different sets of squares (including the starting and ending squares).\n\n## Constraints\n\n*   $1 \\leq N \\leq 400$\n*   $1 \\leq a_{i,j} \\leq N^2$\n*   All values in input are integers.\n\n## Input\n\nInput is given from Standard Input in the following format:\n\n$N$\n$a_{1,1}$ $\\ldots$ $a_{1,N}$\n$\\vdots$\n$a_{N,1}$ $\\ldots$ $a_{N,N}$\n\n[samples]","is_translate":false,"language":"English"}],"meta":{"iden":"abc259_h","tags":[],"sample_group":[["2\n1 3\n3 1","6\n\nThe following six paths satisfy the requirements. ($(i, j)$ denotes the square at the $i$\\-th row from the top and $j$\\-th column from the left. Each path is represented as a sequence of squares it visits.)\n\n*   $(1,1)$\n*   $(1,1)$ → $(1,2)$ → $(2,2)$\n*   $(1,1)$ → $(2,1)$ → $(2,2)$\n*   $(1,2)$\n*   $(2,1)$\n*   $(2,2)$"]],"created_at":"2026-03-03 11:01:14"}}