{"code":"icpc21subsetcount","name":"Subset Counting","description":"Given a sequence of integers $a_1,a_2,...,a_n$; find the number of sets $S$ satisfying the following conditions:\r\n\r\n- $S \\sub \\{1, 2, ..., n\\}$\r\n- $\\exist x \\in S : a_x \\in S$\r\n- $\\exist y \\in S : (\\forall x \\in S : a_x \\ne y)$\r\n\r\nSince the result can be rather large, you should output it modulo $998244353$.\r\n\r\n<h4>Input</h4>\r\n\r\nThe input contains multiple test cases. Each test case is presented in two lines as below:\r\n\r\n- The first line contains an integer $n (1 \\le  n \\le  10^5\r\n)$.\r\n- The second line contains $n$ integers $a_1,a_2,...,a_n (1 \\le  |a_i\r\n| \\le  n)$.\r\n\r\nThe input is terminated by a line with a single integer $0$ which is not a test case. The sum of n over all test cases does\r\nnot exceed $10^6$\r\n.\r\n\r\n<h4>Output</h4>\r\n\r\nFor each test case, write the result on the single line.\r\n\r\n<h4>Example</h4>\r\n\r\n!!! question \"Test 1\"\r\n\r\n    ???+ \"Input\"\r\n        ```sample\r\n        3\r\n        1 2 3\r\n        3\r\n        2 3 1\r\n        0\r\n        ```\r\n    \r\n    ???+ success \"Output\"\r\n        ```sample\r\n        0\r\n        6\r\n        ```\r\n    \r\n    ??? warning \"Note\"\r\n\r\n        In the second test cases, 6 valid sets are {1};{2};{3};{1, 2};{2, 3};{3, 1}.","points":400.0,"partial":false,"time_limit":1.0,"memory_limit":262144,"short_circuit":false,"allowed_languages":[3,4,34,36,37,5,6,11,12,14,28,2,38,39,9,18,17,29,23,27,35,25,26,10,7,19,32,1,8,15,16,24,20,33,13,41,21,40],"is_public":true,"is_manually_managed":false,"permissions":{"can_edit":false}}