{"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\n\u003cscript\u003e\n window.katexOptions \u003d {\n delimiters: [\n {left: \u0027$$$$$$\u0027, right: \u0027$$$$$$\u0027, display: true},\n {left: \u0027$$$\u0027, right: \u0027$$$\u0027, display: false},\n {left: \u0027$$\u0027, right: \u0027$$\u0027, display: true},\n {left: \u0027$\u0027, right: \u0027$\u0027, display: false}\n ]\n };\n\u003c/script\u003e\n","sections":[{"title":"","value":{"format":"HTML","content":"\u003cp\u003eLet $$$\\text{LCP}(s, t)$$$ be the length of the longest common prefix of strings $$$s$$$ and $$$t$$$. Also let $$$s[x \\dots y]$$$ be the substring of $$$s$$$ from index $$$x$$$ to index $$$y$$$ (inclusive). For example, if $$$s \u003d $$$ \"\u003cspan class\u003d\"tex-font-style-tt\"\u003eabcde\u003c/span\u003e\", then $$$s[1 \\dots 3] \u003d$$$ \"\u003cspan class\u003d\"tex-font-style-tt\"\u003eabc\u003c/span\u003e\", $$$s[2 \\dots 5] \u003d$$$ \"\u003cspan class\u003d\"tex-font-style-tt\"\u003ebcde\u003c/span\u003e\".\u003c/p\u003e\u003cp\u003eYou are given a string $$$s$$$ of length $$$n$$$ and $$$q$$$ queries. Each query is a pair of integer sets $$$a_1, a_2, \\dots, a_k$$$ and $$$b_1, b_2, \\dots, b_l$$$. Calculate $$$\\sum\\limits_{i \u003d 1}^{i \u003d k} \\sum\\limits_{j \u003d 1}^{j \u003d l}{\\text{LCP}(s[a_i \\dots n], s[b_j \\dots n])}$$$ for each query.\u003c/p\u003e"}},{"title":"Input","value":{"format":"HTML","content":"\u003cp\u003eThe first line contains two integers $$$n$$$ and $$$q$$$ ($$$1 \\le n, q \\le 2 \\cdot 10^5$$$) — the length of string $$$s$$$ and the number of queries, respectively.\u003c/p\u003e\u003cp\u003eThe second line contains a string $$$s$$$ consisting of lowercase Latin letters ($$$|s| \u003d n$$$).\u003c/p\u003e\u003cp\u003eNext $$$3q$$$ lines contains descriptions of queries — three lines per query. The first line of each query contains two integers $$$k_i$$$ and $$$l_i$$$ ($$$1 \\le k_i, l_i \\le n$$$) — sizes of sets $$$a$$$ and $$$b$$$ respectively.\u003c/p\u003e\u003cp\u003eThe second line of each query contains $$$k_i$$$ integers $$$a_1, a_2, \\dots a_{k_i}$$$ ($$$1 \\le a_1 \u0026lt; a_2 \u0026lt; \\dots \u0026lt; a_{k_i} \\le n$$$) — set $$$a$$$.\u003c/p\u003e\u003cp\u003eThe third line of each query contains $$$l_i$$$ integers $$$b_1, b_2, \\dots b_{l_i}$$$ ($$$1 \\le b_1 \u0026lt; b_2 \u0026lt; \\dots \u0026lt; b_{l_i} \\le n$$$) — set $$$b$$$.\u003c/p\u003e\u003cp\u003eIt is guaranteed that $$$\\sum\\limits_{i \u003d 1}^{i \u003d q}{k_i} \\le 2 \\cdot 10^5$$$ and $$$\\sum\\limits_{i \u003d 1}^{i \u003d q}{l_i} \\le 2 \\cdot 10^5$$$.\u003c/p\u003e"}},{"title":"Output","value":{"format":"HTML","content":"\u003cp\u003ePrint $$$q$$$ integers — answers for the queries in the same order queries are given in the input.\u003c/p\u003e"}},{"title":"Examples","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\u003e7 4\nabacaba\n2 2\n1 2\n1 2\n3 1\n1 2 3\n7\n1 7\n1\n1 2 3 4 5 6 7\n2 2\n1 5\n1 5\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e13\n2\n12\n16\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}},{"title":"Note","value":{"format":"HTML","content":"\u003cp\u003eDescription of queries: \u003c/p\u003e\u003col\u003e \u003cli\u003e In the first query $$$s[1 \\dots 7] \u003d \\text{abacaba}$$$ and $$$s[2 \\dots 7] \u003d \\text{bacaba}$$$ are considered. The answer for the query is $$$\\text{LCP}(\\text{abacaba}, \\text{abacaba}) + \\text{LCP}(\\text{abacaba}, \\text{bacaba}) + \\text{LCP}(\\text{bacaba}, \\text{abacaba}) + \\text{LCP}(\\text{bacaba}, \\text{bacaba}) \u003d 7 + 0 + 0 + 6 \u003d 13$$$.\u003c/li\u003e\u003cli\u003e In the second query $$$s[1 \\dots 7] \u003d \\text{abacaba}$$$, $$$s[2 \\dots 7] \u003d \\text{bacaba}$$$, $$$s[3 \\dots 7] \u003d \\text{acaba}$$$ and $$$s[7 \\dots 7] \u003d \\text{a}$$$ are considered. The answer for the query is $$$\\text{LCP}(\\text{abacaba}, \\text{a}) + \\text{LCP}(\\text{bacaba}, \\text{a}) + \\text{LCP}(\\text{acaba}, \\text{a}) \u003d 1 + 0 + 1 \u003d 2$$$.\u003c/li\u003e\u003cli\u003e In the third query $$$s[1 \\dots 7] \u003d \\text{abacaba}$$$ are compared with all suffixes. The answer is the sum of non-zero values: $$$\\text{LCP}(\\text{abacaba}, \\text{abacaba}) + \\text{LCP}(\\text{abacaba}, \\text{acaba}) + \\text{LCP}(\\text{abacaba}, \\text{aba}) + \\text{LCP}(\\text{abacaba}, \\text{a}) \u003d 7 + 1 + 3 + 1 \u003d 12$$$.\u003c/li\u003e\u003cli\u003e In the fourth query $$$s[1 \\dots 7] \u003d \\text{abacaba}$$$ and $$$s[5 \\dots 7] \u003d \\text{aba}$$$ are considered. The answer for the query is $$$\\text{LCP}(\\text{abacaba}, \\text{abacaba}) + \\text{LCP}(\\text{abacaba}, \\text{aba}) + \\text{LCP}(\\text{aba}, \\text{abacaba}) + \\text{LCP}(\\text{aba}, \\text{aba}) \u003d 7 + 3 + 3 + 3 \u003d 16$$$. \u003c/li\u003e\u003c/ol\u003e"}}]}