{"trustable":true,"prependHtml":"\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 async src\u003d\"https://mathjax.codeforces.org/MathJax.js?config\u003dTeX-AMS-MML_HTMLorMML\" type\u003d\"text/javascript\"\u003e\u003c/script\u003e","sections":[{"title":"","value":{"format":"HTML","content":"\u003cdiv class\u003d\"panel_content\"\u003eYuanfang is puzzled with the question below: \u003cbr\u003eThere are n integers, a\u003csub\u003e1\u003c/sub\u003e, a\u003csub\u003e2\u003c/sub\u003e, …, a\u003csub\u003en\u003c/sub\u003e. The initial values of them are 0. There are four kinds of operations.\u003cbr\u003eOperation 1: Add c to each number between a\u003csub\u003ex\u003c/sub\u003e and a\u003csub\u003ey\u003c/sub\u003e inclusive. In other words, do transformation a\u003csub\u003ek\u003c/sub\u003e\u0026lt;---a\u003csub\u003ek\u003c/sub\u003e+c, k \u003d x,x+1,…,y.\u003cbr\u003eOperation 2: Multiply c to each number between a\u003csub\u003ex\u003c/sub\u003e and a\u003csub\u003ey\u003c/sub\u003e inclusive. In other words, do transformation a\u003csub\u003ek\u003c/sub\u003e\u0026lt;---a\u003csub\u003ek\u003c/sub\u003e×c, k \u003d x,x+1,…,y.\u003cbr\u003eOperation 3: Change the numbers between a\u003csub\u003ex\u003c/sub\u003e and a\u003csub\u003ey\u003c/sub\u003e to c, inclusive. In other words, do transformation a\u003csub\u003ek\u003c/sub\u003e\u0026lt;---c, k \u003d x,x+1,…,y.\u003cbr\u003eOperation 4: Get the sum of p power among the numbers between a\u003csub\u003ex\u003c/sub\u003e and a\u003csub\u003ey\u003c/sub\u003e inclusive. In other words, get the result of a\u003csub\u003ex\u003c/sub\u003e\u003csup\u003ep\u003c/sup\u003e+a\u003csub\u003ex+1\u003c/sub\u003e\u003csup\u003ep\u003c/sup\u003e+…+a\u003csub\u003ey\u003c/sub\u003e \u003csup\u003ep\u003c/sup\u003e.\u003cbr\u003eYuanfang has no idea of how to do it. So he wants to ask you to help him. \u003cbr\u003e\u003c/div\u003e"}},{"title":"Input","value":{"format":"HTML","content":"There are no more than 10 test cases.\u003cbr\u003eFor each case, the first line contains two numbers n and m, meaning that there are n integers and m operations. 1 \u0026lt;\u003d n, m \u0026lt;\u003d 100,000.\u003cbr\u003eEach the following m lines contains an operation. Operation 1 to 3 is in this format: \"1 x y c\" or \"2 x y c\" or \"3 x y c\". Operation 4 is in this format: \"4 x y p\". (1 \u0026lt;\u003d x \u0026lt;\u003d y \u0026lt;\u003d n, 1 \u0026lt;\u003d c \u0026lt;\u003d 10,000, 1 \u0026lt;\u003d p \u0026lt;\u003d 3)\u003cbr\u003eThe input ends with 0 0.\u003cbr\u003e"}},{"title":"Output","value":{"format":"HTML","content":"For each operation 4, output a single integer in one line representing the result. The answer may be quite large. You just need to calculate the remainder of the answer when divided by 10007."}},{"title":"Sample","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 5\r\n3 3 5 7\r\n1 2 4 4\r\n4 1 5 2\r\n2 2 5 8\r\n4 3 5 3\r\n0 0\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e307\r\n7489\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}}]}