{"problem":{"name":"Inversion Squared","description":{"content":"You are given a sequence $A = (A_1,\\ldots,A_N)$ of length $N$. Each element of $A$ is either $-1$ or an integer between $1$ and $N$, and each integer from $1$ to $N$ is contained at most once. A permu","description_type":"Markdown"},"platform":"AtCoder","limit":{"time_limit":2000,"memory_limit":262144},"difficulty":"None","is_remote":true,"is_sync":true,"sync_url":null,"sign":"abc330_g"},"statements":[{"statement_type":"Markdown","content":"You are given a sequence $A = (A_1,\\ldots,A_N)$ of length $N$. Each element of $A$ is either $-1$ or an integer between $1$ and $N$, and each integer from $1$ to $N$ is contained at most once.\nA permutation $P=(P_1,\\ldots,P_N)$ of $(1,\\ldots,N)$ is called a **good permutation** if and only if it satisfies $A_i \\neq -1 \\Rightarrow P_i = A_i$. Find the sum of the squares of the inversion numbers of all good permutations, modulo $998244353$.\nThe inversion number of a permutation $P$ is the number of pairs of integers $(i,j)$ such that $1\\leq i < j \\leq N$ and $P_i > P_j$.\n\n## Constraints\n\n*   $1\\leq N\\leq 3000$\n*   $A_i = -1$ or $1\\leq A_i \\leq N$.\n*   Each integer from $1$ to $N$ is contained at most once in $A$.\n*   All input values are integers.\n\n## Input\n\nInput is given from Standard Input in the following format:\n\n$N$ \n$A_1$ $\\ldots$ $A_N$\n\n[samples]","is_translate":false,"language":"English"}],"meta":{"iden":"abc330_g","tags":[],"sample_group":[["4\n3 -1 2 -1","29\n\nThere are two good permutations: $P=(3,1,2,4)$ and $P=(3,4,2,1)$, with inversion numbers $2$ and $5$, respectively.\nThus, the answer is $2^2 + 5^2 = 29$."],["10\n-1 -1 -1 -1 -1 -1 -1 -1 -1 -1","952235647"],["15\n-1 -1 10 -1 -1 -1 2 -1 -1 3 -1 -1 -1 -1 1","460544744\n\nFind the sum modulo $998244353$."]],"created_at":"2026-03-03 11:01:14"}}