{"trustable":true,"prependHtml":"\u003cstyle type\u003d\"text/css\"\u003e\n section pre {\n display: block;\n padding: 9.5px;\n margin: 0 0 10px;\n font-size: 13px;\n line-height: 1.42857143;\n word-break: break-all;\n word-wrap: break-word;\n color: #333;\n background: rgba(255, 255, 255, 0.5);\n border: 1px solid #ccc;\n border-radius: 6px;\n }\n\u003c/style\u003e\n\u003cscript\u003e\n window.katexOptions \u003d {\n delimiters: [\n {left: \u0027\\\\(\u0027, right: \u0027\\\\)\u0027, display: false},\n {left: \u0027\\\\[\u0027, right: \u0027\\\\]\u0027, display: true}\n ]\n };\n\u003c/script\u003e\n","sections":[{"title":"Problem Statement","value":{"format":"HTML","content":"\r\n\u003csection\u003e\r\n\u003cp\u003eYou are given an integer sequence of length \u003cvar\u003e\\(N\\)\u003c/var\u003e: \u003cvar\u003e\\(A_1,A_2,...,A_N\\)\u003c/var\u003e. Let us perform \u003cvar\u003e\\(Q\\)\u003c/var\u003e operations in order.\r\nThe \u003cvar\u003e\\(i\\)\u003c/var\u003e-th operation is described by two integers \u003cvar\u003e\\(X_i\\)\u003c/var\u003e and \u003cvar\u003e\\(Y_i\\)\u003c/var\u003e. In this operation, we will choose one of the following two actions and perform it:\u003c/p\u003e\r\n\u003cul\u003e\r\n\u003cli\u003eSwap the values of \u003cvar\u003e\\(A_{X_i}\\)\u003c/var\u003e and \u003cvar\u003e\\(A_{Y_i}\\)\u003c/var\u003e\u003c/li\u003e\r\n\u003cli\u003eDo nothing\u003c/li\u003e\r\n\u003c/ul\u003e\r\n\u003cp\u003eThere are \u003cvar\u003e\\(2^Q\\)\u003c/var\u003e ways to perform these operations. Find the sum of the inversion numbers of the final sequences for all of these ways to perform operations, modulo \u003cvar\u003e\\(10^9+7\\)\u003c/var\u003e.\u003c/p\u003e\r\n\u003cp\u003eHere, the inversion number of a sequence \u003cvar\u003e\\(P_1,P_2,...,P_M\\)\u003c/var\u003e is the number of pairs of integers \u003cvar\u003e\\((i,j)\\)\u003c/var\u003e such that \u003cvar\u003e\\(1\\leq i \u0026lt; j\\leq M\\)\u003c/var\u003e and \u003cvar\u003e\\(P_i \u0026gt; P_j\\)\u003c/var\u003e.\u003c/p\u003e\r\n\u003c/section\u003e\r\n"}},{"title":"Constraints","value":{"format":"HTML","content":"\r\n\u003csection\u003e\r\n\u003cul\u003e\r\n\u003cli\u003e\u003cvar\u003e\\(1 \\leq N \\leq 3000\\)\u003c/var\u003e\u003c/li\u003e\r\n\u003cli\u003e\u003cvar\u003e\\(0 \\leq Q \\leq 3000\\)\u003c/var\u003e\u003c/li\u003e\r\n\u003cli\u003e\u003cvar\u003e\\(0 \\leq A_i \\leq 10^9(1\\leq i\\leq N)\\)\u003c/var\u003e\u003c/li\u003e\r\n\u003cli\u003e\u003cvar\u003e\\(1 \\leq X_i,Y_i \\leq N(1\\leq i\\leq Q)\\)\u003c/var\u003e\u003c/li\u003e\r\n\u003cli\u003e\u003cvar\u003e\\(X_i\\neq Y_i(1\\leq i\\leq Q)\\)\u003c/var\u003e\u003c/li\u003e\r\n\u003cli\u003eAll values in input are integers.\u003c/li\u003e\r\n\u003c/ul\u003e\r\n\u003c/section\u003e\r\n"}},{"title":"Input","value":{"format":"HTML","content":"\r\n\u003csection\u003e\r\n\u003cp\u003eInput is given from Standard Input in the following format:\u003c/p\u003e\r\n\u003cpre\u003e\u003cvar\u003e\\(N\\)\u003c/var\u003e \u003cvar\u003e\\(Q\\)\u003c/var\u003e\r\n\u003cvar\u003e\\(A_1\\)\u003c/var\u003e\r\n\u003cvar\u003e\\(:\\)\u003c/var\u003e\r\n\u003cvar\u003e\\(A_N\\)\u003c/var\u003e\r\n\u003cvar\u003e\\(X_1\\)\u003c/var\u003e \u003cvar\u003e\\(Y_1\\)\u003c/var\u003e\r\n\u003cvar\u003e\\(:\\)\u003c/var\u003e\r\n\u003cvar\u003e\\(X_Q\\)\u003c/var\u003e \u003cvar\u003e\\(Y_Q\\)\u003c/var\u003e\r\n\u003c/pre\u003e\r\n\r\n\u003c/section\u003e\r\n"}},{"title":"Output","value":{"format":"HTML","content":"\r\n\u003csection\u003e\r\n\u003cp\u003ePrint the sum of the inversion numbers of the final sequences, modulo \u003cvar\u003e\\(10^9+7\\)\u003c/var\u003e.\u003c/p\u003e\r\n\u003c/section\u003e\r\n"}},{"title":"Sample 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\u003e3 2\r\n1\r\n2\r\n3\r\n1 2\r\n1 3\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e6\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n\r\n\u003csection\u003e\r\n\r\n\r\n\u003c/section\u003e\r\n\r\n\u003csection\u003e\r\n\r\n\r\n\u003cp\u003eThere are four ways to perform operations, as follows:\u003c/p\u003e\r\n\u003cul\u003e\r\n\u003cli\u003eDo nothing, both in the first and second operations. The final sequence would be \u003cvar\u003e\\(1,2,3\\)\u003c/var\u003e, with the inversion number of \u003cvar\u003e\\(0\\)\u003c/var\u003e.\u003c/li\u003e\r\n\u003cli\u003eDo nothing in the first operation, then perform the swap in the second. The final sequence would be \u003cvar\u003e\\(3,2,1\\)\u003c/var\u003e, with the inversion number of \u003cvar\u003e\\(3\\)\u003c/var\u003e.\u003c/li\u003e\r\n\u003cli\u003ePerform the swap in the first operation, then do nothing in the second. The final sequence would be \u003cvar\u003e\\(2,1,3\\)\u003c/var\u003e, with the inversion number of \u003cvar\u003e\\(1\\)\u003c/var\u003e.\u003c/li\u003e\r\n\u003cli\u003ePerform the swap, both in the first and second operations. The final sequence would be \u003cvar\u003e\\(3,1,2\\)\u003c/var\u003e, with the inversion number of \u003cvar\u003e\\(2\\)\u003c/var\u003e.\u003c/li\u003e\r\n\u003c/ul\u003e\r\n\u003cp\u003eThe sum of these inversion numbers, \u003cvar\u003e\\(0+3+1+2\u003d6\\)\u003c/var\u003e, should be printed.\u003c/p\u003e\r\n\u003c/section\u003e\r\n"}},{"title":"Sample 2","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\u003e5 3\r\n3\r\n2\r\n3\r\n1\r\n4\r\n1 5\r\n2 3\r\n4 2\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e36\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n\r\n\u003csection\u003e\r\n\r\n\r\n\u003c/section\u003e\r\n\r\n\u003csection\u003e\r\n\r\n\r\n\u003c/section\u003e\r\n"}},{"title":"Sample 3","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\u003e9 5\r\n3\r\n1\r\n4\r\n1\r\n5\r\n9\r\n2\r\n6\r\n5\r\n3 5\r\n8 9\r\n7 9\r\n3 2\r\n3 8\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e425\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n\r\n\u003csection\u003e\r\n\r\n\r\n\u003c/section\u003e\r\n\r\n\u003csection\u003e\r\n\u003c/section\u003e\r\n"}}]}