{"task": {"agent_timeout": 600, "task": "1087", "verifier_timeout": 7200, "instruction": "Please implement a Python 3 solution to the below problem.\nReason through the problem and:\n1. Restate the problem in plain English\n2. Conceptualize a solution first in plain English\n3. Write a pseudocode solution\n4. Save your solution as solution.py\nNo outside libraries are allowed.\n\n[BEGIN PROBLEM]\nBessie has recently received a painting set, and she wants to paint the long\nfence at one end of her pasture.  The fence consists of $N$ consecutive 1-meter \nsegments ($1\\le N\\le 10^5$).  Bessie has 26 different colors available, which\nshe labels with the letters 'A' through 'Z' in increasing order of darkness ('A'\nis a very light color, and 'Z' is very dark).  She can therefore describe the\ndesired color she wants to paint each fence segment as a length-$N$ string where\neach character is a letter.\n\nInitially, all fence segments are uncolored.  Bessie can color any  contiguous\nrange of segments with a single color in a single brush stroke as long as she\nnever paints a lighter color over a darker color (she can only paint darker\ncolors over lighter colors).  \n\nFor example, an initially uncolored segment of length four can be colored as\nfollows:\n\n\n.... -> BBB. -> BBLL -> BQQL\n\nRunning short on time, Bessie thinks she may need to leave some consecutive\nrange of fence segments unpainted! Currently, she is considering $Q$  candidate\nranges ($1\\le Q\\le 10^5$), each described by  by two integers $(a,b)$ with\n$1 \\leq a \\leq b \\leq N$ giving the indices of  endpoints of the range\n$a \\ldots b$ of segments to be left unpainted.\n\nFor each candidate range, what is the minimum number of strokes needed to paint\nevery fence segment outside those in the range with its desired color while \nleaving all fence segments inside the range uncolored?  Note that Bessie does\nnot actually do any painting during this process, so the answers for each\ncandidate range are independent. \n\nINPUT FORMAT (input arrives from the terminal / stdin):\nThe first line contains $N$ and $Q$.\n\nThe next line contains a string of length $N$ characters representing the\ndesired color  for each fence segment.\n\nThe next $Q$ lines each contain two space-separated integers $a$ and $b$\nrepresenting a candidate range to possibly leave unpainted.\n\nOUTPUT FORMAT (print output to the terminal / stdout):\nFor each of the $Q$ candidates, output the answer on a new line.\n\nSAMPLE INPUT:\n8 2\nABBAABCB\n3 6\n1 4\nSAMPLE OUTPUT: \n4\n3\n\nIn this example, excluding the sub-range corresponding to the desired pattern\n$\\texttt{BAAB}$ requires four strokes to paint while excluding $\\texttt{ABBA}$ \nrequires only three.\n\n\n.... -> AA.. -> ABBB -> ABCB\n\nSCORING:\nTest cases 1-4 satisfy $N,Q\\le 100$.Test cases 5-7 satisfy\n$N,Q\\le 5000$.Test cases 8-13 satisfy no additional constraints.\n\n\nProblem credits: Andi Qu and Brian Dean\n\n[END PROBLEM]\n", "memory": "2048m", "runnable": false, "difficulty": "medium", "language": "", "cpus": 1, "instruction_truncated": false, "category": "python_programming", "compose": false, "has_solution": true, "oracle": null, "docker_image": "", "taskset": "usaco", "tags": ["python", "programming", "usaco"]}, "runs": []}