{"trustable":true,"prependHtml":"\u003cstyle type\u003d\u0027text/css\u0027\u003e\n .input, .output {\n border: 1px solid #888888;\n }\n .output {\n margin-bottom: 1em;\n position: relative;\n top: -1px;\n }\n .output pre, .input pre {\n background-color: #EFEFEF;\n line-height: 1.25em;\n margin: 0;\n padding: 0.25em;\n }\n \u003c/style\u003e\n \u003clink rel\u003d\"stylesheet\" href\u003d\"//codeforces.org/s/96598/css/problem-statement.css\" type\u003d\"text/css\" /\u003e\u003cscript\u003e window.katexOptions \u003d { disable: true }; \u003c/script\u003e\n\u003cscript type\u003d\"text/x-mathjax-config\"\u003e\n MathJax.Hub.Config({\n tex2jax: {\n inlineMath: [[\u0027$$$\u0027,\u0027$$$\u0027], [\u0027$\u0027,\u0027$\u0027]],\n displayMath: [[\u0027$$$$$$\u0027,\u0027$$$$$$\u0027], [\u0027$$\u0027,\u0027$$\u0027]]\n }\n });\n\u003c/script\u003e\n\u003cscript type\u003d\"text/javascript\" async src\u003d\"https://mathjax.codeforces.org/MathJax.js?config\u003dTeX-AMS_HTML-full\"\u003e\u003c/script\u003e","sections":[{"title":"","value":{"format":"HTML","content":"\u003cp\u003e如果从 $$$1$$$ 到 $$$n-1$$$ 的所有 $$$i$$$ 都满足条件 $$$$$$a_1 \\: \\\u0026amp; \\: a_2 \\: \\\u0026amp; \\: \\dots \\: \\\u0026amp; \\: a_i \u003d a_{i+1} \\: \\\u0026amp; \\: a_{i+2} \\: \\\u0026amp; \\: \\dots \\: \\\u0026amp; \\: a_n,$$$$$$,则称一系列非负整数 $$$n$$$ ($$$n \\ge 2$$$) $$$a_1, a_2, \\dots, a_n$$$ 为好序列,其中 $$$\\\u0026amp;$$$ 表示\u003ca href\u003d\"https://zh.wikipedia.org/wiki/%E4%BD%8D%E6%93%8D%E4%BD%9C\"\u003e按位与操作\u003c/a\u003e。\u003c/p\u003e\u003cp\u003e给定大小为 $$$n$$$ ($$$n \\geq 2$$$) 的数组 $$$a$$$。找到从 $$$1$$$ 到 $$$n$$$ 范围内数字的排列 $$$p$$$ 数量,使得序列 $$$a_{p_1}$$$、$$$a_{p_2}$$$、...、$$$a_{p_n}$$$ 为好序列。由于结果可能很大,输出结果对 $$$10^9+7$$$ 取模。\u003c/p\u003e"}},{"title":"输入","value":{"format":"HTML","content":"\u003cp\u003e第一行包含一个整数 $$$t$$$ ($$$1 \\leq t \\leq 10^4$$$),表示测试用例数量。\u003c/p\u003e\u003cp\u003e每个测试用例的第一行包含一个整数 $$$n$$$ ($$$2 \\le n \\le 2 \\cdot 10^5$$$) — 数组的大小。\u003c/p\u003e\u003cp\u003e每个测试用例的第二行包含 $$$n$$$ 个整数 $$$a_1, a_2, \\ldots, a_n$$$ ($$$0 \\le a_i \\le 10^9$$$) — 数组的元素。\u003c/p\u003e\u003cp\u003e保证所有测试用例中 $$$n$$$ 的总和不超过 $$$2 \\cdot 10^5$$$。\u003c/p\u003e"}},{"title":"输出","value":{"format":"HTML","content":"\u003cp\u003e输出 $$$t$$$ 行,第 $$$i$$$ 行包含第 $$$i$$$ 个测试用例中好排列的数量对 $$$10^9 + 7$$$ 取模的结果。\u003c/p\u003e"}},{"title":"示例 1","value":{"format":"HTML","content":"\u003ctable class\u003d\u0027vjudge_sample\u0027\u003e\n\u003cthead\u003e\n \u003ctr\u003e\n \u003cth\u003eInput\u003c/th\u003e\n \u003cth\u003eOutput\u003c/th\u003e\n \u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n \u003ctr\u003e\n \u003ctd\u003e\u003cpre\u003e4\n3\n1 1 1\n5\n1 2 3 4 5\n5\n0 2 0 3 0\n4\n1 3 5 1\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e6\n0\n36\n4\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e"}},{"title":"注意","value":{"format":"HTML","content":"\u003cp\u003e在第一个测试用例中,由于所有数字相等,无论取哪种排列,序列都是好序列。从 $$$1$$$ 到 $$$3$$$ 的数字共有 $$$6$$$ 种排列可能性: $$$[1,2,3]$$$、$$$[1,3,2]$$$、$$$[2,1,3]$$$、$$$[2,3,1]$$$、$$$[3,1,2]$$$、$$$[3,2,1]$$$。\u003c/p\u003e\u003cp\u003e在第二个测试用例中,可以证明不存在任何排列使得序列为好序列。\u003c/p\u003e\u003cp\u003e在第三个测试用例中,共有 $$$36$$$ 种排列使得序列为好序列。其中一种是排列 $$$[1,5,4,2,3]$$$,得到序列 $$$s\u003d[0,0,3,2,0]$$$。这是一个好序列,因为\u003c/p\u003e\u003cul\u003e \u003cli\u003e $$$ s_1 \u003d s_2 \\: \\\u0026amp; \\: s_3 \\: \\\u0026amp; \\: s_4 \\: \\\u0026amp; \\: s_5 \u003d 0$$$, \u003c/li\u003e\u003cli\u003e $$$ s_1 \\: \\\u0026amp; \\: s_2 \u003d s_3 \\: \\\u0026amp; \\: s_4 \\: \\\u0026amp; \\: s_5 \u003d 0$$$, \u003c/li\u003e\u003cli\u003e $$$ s_1 \\: \\\u0026amp; \\: s_2 \\: \\\u0026amp; \\: s_3 \u003d s_4 \\: \\\u0026amp; \\: s_5 \u003d 0$$$, \u003c/li\u003e\u003cli\u003e $$$ s_1 \\: \\\u0026amp; \\: s_2 \\: \\\u0026amp; \\: s_3 \\: \\\u0026amp; \\: s_4 \u003d s_5 \u003d 0$$$。 \u003c/li\u003e\u003c/ul\u003e\u003cp\u003e \u003c/p\u003e"}}]}