{"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\"\u003eWLD is always very lucky.His secret is a lucky number $K$.$k$ is a fixed odd number. Now he meets a stranger with $N$ numbers:$a1,a2,...,aN$.The stranger asks him $M$ questions.Each question is like this:Given two ranges $[Li,Ri]$ and $[Ui,Vi]$,you can choose two numbers $X$ and $Y$ to make $aX+aY\u003dK$.The $X$ you can choose is between $Li$ and $Ri$ and the $Y$ you can choose is between $Ui$ and $Vi$.How many pairs of numbers$(X,Y)$ you can choose?\u003cbr\u003eIf WLD can answer all the questions correctly,he\u0027ll be the luckiest man in the world.Can you help him?\u003c/div\u003e"}},{"title":"Input","value":{"format":"HTML","content":"There are multiple cases.(At MOST $5$)\u003cbr\u003e\u003cbr\u003eFor each case:\u003cbr\u003e\u003cbr\u003eThe first line contains an integer $N(1 \\leq N \\leq 30000)$.\u003cbr\u003e\u003cbr\u003eThe following line contains an integer $K(2 \\leq K \\leq 2*N)$,WLD\u0027s lucky number.K is odd.\u003cbr\u003e\u003cbr\u003eThe following line contains $N$ integers $a1,a2,...,aN(1 \\leq ai \\leq N)$.\u003cbr\u003e\u003cbr\u003eThe following line contains an integer $M(1 \\leq M \\leq 30000)$,the sum of the questions WLD has to answer.\u003cbr\u003e\u003cbr\u003eThe following $M$ lines,the i-th line contains $4$ numbers $Li,Ri,Ui,Vi(1 \\leq Li \\leq Ri \u0026lt; Ui \\leq Vi \\leq N)$,describing the i-th question the stranger asks."}},{"title":"Output","value":{"format":"HTML","content":"For each case:\u003cbr\u003e\u003cbr\u003ePrint the total of pairs WLD can choose for each question."}},{"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\r\n3 \r\n1 2 1 2 3\r\n1 \r\n1 2 3 5\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e2\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}},{"title":"Hint","value":{"format":"HTML","content":"a1+a4\u003da2+a3\u003d3\u003dK.\u003cbr\u003eSo we have two pairs of numbers (1,4) and (2,3).\u003cbr\u003eGood luck!"}}]}