{"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\u003eA string \u003cspan class\u003d\"tex-span\"\u003e\u003ci\u003et\u003c/i\u003e\u003c/span\u003e is called \u003cspan class\u003d\"tex-font-style-it\"\u003enice\u003c/span\u003e if a string \"\u003cspan class\u003d\"tex-font-style-tt\"\u003e2017\u003c/span\u003e\" occurs in \u003cspan class\u003d\"tex-span\"\u003e\u003ci\u003et\u003c/i\u003e\u003c/span\u003e as a \u003cspan class\u003d\"tex-font-style-bf\"\u003esubsequence\u003c/span\u003e but a string \"\u003cspan class\u003d\"tex-font-style-tt\"\u003e2016\u003c/span\u003e\" doesn\u0027t occur in \u003cspan class\u003d\"tex-span\"\u003e\u003ci\u003et\u003c/i\u003e\u003c/span\u003e as a \u003cspan class\u003d\"tex-font-style-bf\"\u003esubsequence\u003c/span\u003e. For example, strings \"\u003cspan class\u003d\"tex-font-style-tt\"\u003e203434107\u003c/span\u003e\" and \"\u003cspan class\u003d\"tex-font-style-tt\"\u003e9220617\u003c/span\u003e\" are nice, while strings \"\u003cspan class\u003d\"tex-font-style-tt\"\u003e20016\u003c/span\u003e\", \"\u003cspan class\u003d\"tex-font-style-tt\"\u003e1234\u003c/span\u003e\" and \"\u003cspan class\u003d\"tex-font-style-tt\"\u003e20167\u003c/span\u003e\" aren\u0027t nice.\u003c/p\u003e\u003cp\u003eThe \u003cspan class\u003d\"tex-font-style-it\"\u003eugliness\u003c/span\u003e of a string is the minimum possible number of characters to remove, in order to obtain a nice string. If it\u0027s impossible to make a string nice by removing characters, its ugliness is \u003cspan class\u003d\"tex-span\"\u003e - 1\u003c/span\u003e.\u003c/p\u003e\u003cp\u003eLimak has a string \u003cspan class\u003d\"tex-span\"\u003e\u003ci\u003es\u003c/i\u003e\u003c/span\u003e of length \u003cspan class\u003d\"tex-span\"\u003e\u003ci\u003en\u003c/i\u003e\u003c/span\u003e, with characters indexed \u003cspan class\u003d\"tex-span\"\u003e1\u003c/span\u003e through \u003cspan class\u003d\"tex-span\"\u003e\u003ci\u003en\u003c/i\u003e\u003c/span\u003e. He asks you \u003cspan class\u003d\"tex-span\"\u003e\u003ci\u003eq\u003c/i\u003e\u003c/span\u003e queries. In the \u003cspan class\u003d\"tex-span\"\u003e\u003ci\u003ei\u003c/i\u003e\u003c/span\u003e-th query you should compute and print the ugliness of a \u003cspan class\u003d\"tex-font-style-bf\"\u003esubstring\u003c/span\u003e (continuous subsequence) of \u003cspan class\u003d\"tex-span\"\u003e\u003ci\u003es\u003c/i\u003e\u003c/span\u003e starting at the index \u003cspan class\u003d\"tex-span\"\u003e\u003ci\u003ea\u003c/i\u003e\u003csub class\u003d\"lower-index\"\u003e\u003ci\u003ei\u003c/i\u003e\u003c/sub\u003e\u003c/span\u003e and ending at the index \u003cspan class\u003d\"tex-span\"\u003e\u003ci\u003eb\u003c/i\u003e\u003csub class\u003d\"lower-index\"\u003e\u003ci\u003ei\u003c/i\u003e\u003c/sub\u003e\u003c/span\u003e (inclusive).\u003c/p\u003e"}},{"title":"Input","value":{"format":"HTML","content":"\u003cp\u003eThe first line of the input contains two integers \u003cspan class\u003d\"tex-span\"\u003e\u003ci\u003en\u003c/i\u003e\u003c/span\u003e and \u003cspan class\u003d\"tex-span\"\u003e\u003ci\u003eq\u003c/i\u003e\u003c/span\u003e (\u003cspan class\u003d\"tex-span\"\u003e4 ≤ \u003ci\u003en\u003c/i\u003e ≤ 200 000\u003c/span\u003e, \u003cspan class\u003d\"tex-span\"\u003e1 ≤ \u003ci\u003eq\u003c/i\u003e ≤ 200 000\u003c/span\u003e)\u0026nbsp;— the length of the string \u003cspan class\u003d\"tex-span\"\u003e\u003ci\u003es\u003c/i\u003e\u003c/span\u003e and the number of queries respectively.\u003c/p\u003e\u003cp\u003eThe second line contains a string \u003cspan class\u003d\"tex-span\"\u003e\u003ci\u003es\u003c/i\u003e\u003c/span\u003e of length \u003cspan class\u003d\"tex-span\"\u003e\u003ci\u003en\u003c/i\u003e\u003c/span\u003e. Every character is one of digits \u0027\u003cspan class\u003d\"tex-font-style-tt\"\u003e0\u003c/span\u003e\u0027–\u0027\u003cspan class\u003d\"tex-font-style-tt\"\u003e9\u003c/span\u003e\u0027.\u003c/p\u003e\u003cp\u003eThe \u003cspan class\u003d\"tex-span\"\u003e\u003ci\u003ei\u003c/i\u003e\u003c/span\u003e-th of next \u003cspan class\u003d\"tex-span\"\u003e\u003ci\u003eq\u003c/i\u003e\u003c/span\u003e lines contains two integers \u003cspan class\u003d\"tex-span\"\u003e\u003ci\u003ea\u003c/i\u003e\u003csub class\u003d\"lower-index\"\u003e\u003ci\u003ei\u003c/i\u003e\u003c/sub\u003e\u003c/span\u003e and \u003cspan class\u003d\"tex-span\"\u003e\u003ci\u003eb\u003c/i\u003e\u003csub class\u003d\"lower-index\"\u003e\u003ci\u003ei\u003c/i\u003e\u003c/sub\u003e\u003c/span\u003e (\u003cspan class\u003d\"tex-span\"\u003e1 ≤ \u003ci\u003ea\u003c/i\u003e\u003csub class\u003d\"lower-index\"\u003e\u003ci\u003ei\u003c/i\u003e\u003c/sub\u003e ≤ \u003ci\u003eb\u003c/i\u003e\u003csub class\u003d\"lower-index\"\u003e\u003ci\u003ei\u003c/i\u003e\u003c/sub\u003e ≤ \u003ci\u003en\u003c/i\u003e\u003c/span\u003e), describing a substring in the \u003cspan class\u003d\"tex-span\"\u003e\u003ci\u003ei\u003c/i\u003e\u003c/span\u003e-th query.\u003c/p\u003e"}},{"title":"Output","value":{"format":"HTML","content":"\u003cp\u003eFor each query print the ugliness of the given substring.\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\u003e8 3\n20166766\n1 8\n1 7\n2 8\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e4\n3\n-1\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}},{"title":"","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\u003e15 5\n012016662091670\n3 4\n1 14\n4 15\n1 13\n10 15\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e-1\n2\n1\n-1\n-1\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}},{"title":"","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\u003e4 2\n1234\n2 4\n1 2\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e-1\n-1\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\u003eIn the first sample:\u003c/p\u003e\u003cul\u003e \u003cli\u003e In the first query, \u003cspan class\u003d\"tex-span\"\u003e\u003ci\u003eugliness\u003c/i\u003e(\u003c/span\u003e\"\u003cspan class\u003d\"tex-font-style-tt\"\u003e20166766\u003c/span\u003e\"\u003cspan class\u003d\"tex-span\"\u003e) \u003d 4\u003c/span\u003e because all four sixes must be removed. \u003c/li\u003e\u003cli\u003e In the second query, \u003cspan class\u003d\"tex-span\"\u003e\u003ci\u003eugliness\u003c/i\u003e(\u003c/span\u003e\"\u003cspan class\u003d\"tex-font-style-tt\"\u003e2016676\u003c/span\u003e\"\u003cspan class\u003d\"tex-span\"\u003e) \u003d 3\u003c/span\u003e because all three sixes must be removed. \u003c/li\u003e\u003cli\u003e In the third query, \u003cspan class\u003d\"tex-span\"\u003e\u003ci\u003eugliness\u003c/i\u003e(\u003c/span\u003e\"\u003cspan class\u003d\"tex-font-style-tt\"\u003e0166766\u003c/span\u003e\"\u003cspan class\u003d\"tex-span\"\u003e) \u003d - 1\u003c/span\u003e because it\u0027s impossible to remove some digits to get a nice string. \u003c/li\u003e\u003c/ul\u003e\u003cp\u003eIn the second sample:\u003c/p\u003e\u003cul\u003e \u003cli\u003e In the second query, \u003cspan class\u003d\"tex-span\"\u003e\u003ci\u003eugliness\u003c/i\u003e(\u003c/span\u003e\"\u003cspan class\u003d\"tex-font-style-tt\"\u003e01201666209167\u003c/span\u003e\"\u003cspan class\u003d\"tex-span\"\u003e) \u003d 2\u003c/span\u003e. It\u0027s optimal to remove the first digit \u0027\u003cspan class\u003d\"tex-font-style-tt\"\u003e2\u003c/span\u003e\u0027 and the last digit \u0027\u003cspan class\u003d\"tex-font-style-tt\"\u003e6\u003c/span\u003e\u0027, what gives a string \"\u003cspan class\u003d\"tex-font-style-tt\"\u003e010166620917\u003c/span\u003e\", which is nice. \u003c/li\u003e\u003cli\u003e In the third query, \u003cspan class\u003d\"tex-span\"\u003e\u003ci\u003eugliness\u003c/i\u003e(\u003c/span\u003e\"\u003cspan class\u003d\"tex-font-style-tt\"\u003e016662091670\u003c/span\u003e\"\u003cspan class\u003d\"tex-span\"\u003e) \u003d 1\u003c/span\u003e. It\u0027s optimal to remove the last digit \u0027\u003cspan class\u003d\"tex-font-style-tt\"\u003e6\u003c/span\u003e\u0027, what gives a nice string \"\u003cspan class\u003d\"tex-font-style-tt\"\u003e01666209170\u003c/span\u003e\". \u003c/li\u003e\u003c/ul\u003e"}}]}