{"problem":{"name":"Circular","description":{"content":"You are given a sequence of $N$ integers: $A_1,A_2,...,A_N$. Find the number of permutations $p_1,p_2,...,p_N$ of $1,2,...,N$ that can be changed to $A_1,A_2,...,A_N$ by performing the following opera","description_type":"Markdown"},"platform":"AtCoder","limit":{"time_limit":2000,"memory_limit":262144},"difficulty":"None","is_remote":true,"is_sync":true,"sync_url":null,"sign":"tenka1_2018_f"},"statements":[{"statement_type":"Markdown","content":"You are given a sequence of $N$ integers: $A_1,A_2,...,A_N$.\nFind the number of permutations $p_1,p_2,...,p_N$ of $1,2,...,N$ that can be changed to $A_1,A_2,...,A_N$ by performing the following operation some number of times (possibly zero), modulo $998244353$:\n\n*   For each $1\\leq i\\leq N$, let $q_i=min(p_{i-1},p_{i})$, where $p_0=p_N$. Replace the sequence $p$ with the sequence $q$.\n\n## Constraints\n\n*   $1 \\leq N \\leq 3 × 10^5$\n*   $1 \\leq A_i \\leq N$\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$\n$:$\n$A_N$\n\n[samples]","is_translate":false,"language":"English"}],"meta":{"iden":"tenka1_2018_f","tags":[],"sample_group":[["3\n1\n2\n1","2\n\n$(2,3,1)$ and $(3,2,1)$ satisfy the condition."],["5\n3\n1\n4\n1\n5","0"],["8\n4\n4\n4\n1\n1\n1\n2\n2","24"],["6\n1\n1\n6\n2\n2\n2","0"]],"created_at":"2026-03-03 11:01:14"}}