{"trustable":false,"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":"\u003cscript type\u003d\"text/x-mathjax-config\"\u003eMathJax.Hub.Config({messageStyle:\"none\",tex2jax:{skipTags:[\"script\",\"noscript\",\"style\",\"textarea\",\"code\"],inlineMath:[[\u0027\\\u0027,\u0027\\\u0027]]},delayStartupUntil:\"onload\"});\u003c/script\u003e\n\u003cscript src\u003d\"https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config\u003dTeX-MML-AM_CHTML\"\u003e\u003c/script\u003e\n\u003ch3\u003e\u003c/h3\u003e\n\u003cp\u003eThere are \u003cvar\u003eN\u003c/var\u003e beads arranged in a straight row. The beads are numbered \u003cvar\u003e1\u003c/var\u003e, \u003cvar\u003e2\u003c/var\u003e, \u003cvar\u003e...\u003c/var\u003e, \u003cvar\u003eN\u003c/var\u003e, from left to right.\u003c/p\u003e\n\u003cp\u003eTarun is painting each square in red, green or blue. According to his artistic morales, the following \u003cvar\u003eM\u003c/var\u003e conditions must all be satisfied. The \u003cvar\u003ei\u003c/var\u003e-th condition is:\u003c/p\u003e\n\u003cul\u003e\n \u003cli\u003eThere are exactly \u003cvar\u003ex_i\u003c/var\u003e different colors among beads \u003cvar\u003el_i\u003c/var\u003e, \u003cvar\u003el_i + 1\u003c/var\u003e, \u003cvar\u003e...\u003c/var\u003e, \u003cvar\u003er_i\u003c/var\u003e.\u003c/li\u003e\n\u003c/ul\u003e\n\u003cp\u003eIn how many ways can the beads be painted to satisfy all the conditions? Find the count modulo \u003cvar\u003e10^9+7\u003c/var\u003e.\u003c/p\u003e\n"}},{"title":"Constraints","value":{"format":"HTML","content":"\u003ch3\u003e\u003c/h3\u003e\n\u003cul\u003e\n \u003cli\u003e\u003cvar\u003e1 ≤ N ≤ 300\u003c/var\u003e\u003c/li\u003e\n \u003cli\u003e\u003cvar\u003e1 ≤ M ≤ 300\u003c/var\u003e\u003c/li\u003e\n \u003cli\u003e\u003cvar\u003e1 ≤ l_i ≤ r_i ≤ N\u003c/var\u003e\u003c/li\u003e\n \u003cli\u003e\u003cvar\u003e1 ≤ x_i ≤ 3\u003c/var\u003e\u003c/li\u003e\n\u003c/ul\u003e\n"}},{"title":"Input","value":{"format":"HTML","content":"\u003ch3\u003e\u003c/h3\u003e\n\u003cp\u003eInput is given from Standard Input in the following format:\u003c/p\u003e\n\u003cpre\u003e\u003cvar\u003eN\u003c/var\u003e \u003cvar\u003eM\u003c/var\u003e\n\u003cvar\u003el_1\u003c/var\u003e \u003cvar\u003er_1\u003c/var\u003e \u003cvar\u003ex_1\u003c/var\u003e\n\u003cvar\u003el_2\u003c/var\u003e \u003cvar\u003er_2\u003c/var\u003e \u003cvar\u003ex_2\u003c/var\u003e\n\u003cvar\u003e:\u003c/var\u003e\n\u003cvar\u003el_M\u003c/var\u003e \u003cvar\u003er_M\u003c/var\u003e \u003cvar\u003ex_M\u003c/var\u003e\n\u003c/pre\u003e\n\n\n"}},{"title":"Output","value":{"format":"HTML","content":"\u003ch3\u003e\u003c/h3\u003e\n\u003cp\u003ePrint the number of ways to paint the squares to satisfy all the conditions, modulo \u003cvar\u003e10^9+7\u003c/var\u003e.\u003c/p\u003e"}},{"title":"Sample Input 1","value":{"format":"HTML","content":"\u003ch3\u003e\u003c/h3\u003e\n\u003cpre\u003e3 1\n1 3 3\n\u003c/pre\u003e"}},{"title":"Sample Output 1","value":{"format":"HTML","content":"\u003ch3\u003e\u003c/h3\u003e\n\u003cpre\u003e6\n\u003c/pre\u003e \n\u003cp\u003eThe six ways are:\u003c/p\u003e \n\u003cul\u003e \n \u003cli\u003eRGB\u003c/li\u003e \n \u003cli\u003eRBG\u003c/li\u003e \n \u003cli\u003eGRB\u003c/li\u003e \n \u003cli\u003eGBR\u003c/li\u003e \n \u003cli\u003eBRG\u003c/li\u003e \n \u003cli\u003eBGR\u003c/li\u003e \n\u003c/ul\u003e \n\u003cp\u003ewhere R, G and B correspond to red, green and blue beads, respectively.\u003c/p\u003e"}},{"title":"Sample Input 2","value":{"format":"HTML","content":"\u003ch3\u003e\u003c/h3\u003e\n\u003cpre\u003e4 2\n1 3 1\n2 4 2\n\u003c/pre\u003e"}},{"title":"Sample Output 2","value":{"format":"HTML","content":"\u003ch3\u003e\u003c/h3\u003e\n\u003cpre\u003e6\n\u003c/pre\u003e \n\u003cp\u003eThe six ways are:\u003c/p\u003e \n\u003cul\u003e \n \u003cli\u003eRRRG\u003c/li\u003e \n \u003cli\u003eRRRB\u003c/li\u003e \n \u003cli\u003eGGGR\u003c/li\u003e \n \u003cli\u003eGGGB\u003c/li\u003e \n \u003cli\u003eBBBR\u003c/li\u003e \n \u003cli\u003eBBBG\u003c/li\u003e \n\u003c/ul\u003e"}},{"title":"Sample Input 3","value":{"format":"HTML","content":"\u003ch3\u003e\u003c/h3\u003e\n\u003cpre\u003e1 3\n1 1 1\n1 1 2\n1 1 3\n\u003c/pre\u003e"}},{"title":"Sample Output 3","value":{"format":"HTML","content":"\u003ch3\u003e\u003c/h3\u003e\n\u003cpre\u003e0\n\u003c/pre\u003e \n\u003cp\u003eThere are zero ways.\u003c/p\u003e"}},{"title":"Sample Input 4","value":{"format":"HTML","content":"\u003ch3\u003e\u003c/h3\u003e\n\u003cpre\u003e8 10\n2 6 2\n5 5 1\n3 5 2\n4 7 3\n4 4 1\n2 3 1\n7 7 1\n1 5 2\n1 7 3\n3 4 2\n\u003c/pre\u003e"}},{"title":"Sample Output 4","value":{"format":"HTML","content":"\u003ch3\u003e\u003c/h3\u003e\n\u003cpre\u003e108\n\u003c/pre\u003e"}}]}