{"trustable":true,"prependHtml":"\u003cstyle type\u003d\"text/css\"\u003e\n div.illustration {\n float: right;\n padding-left: 20px;\n }\n div.illustration .illustration {\n width: 100%;\n border-radius: 4px;\n }\n pre {\n display: block;\n margin: 0 0 10px;\n font-size: 13px;\n line-height: 1.42857143;\n color: #333;\n word-break: break-all;\n word-wrap: break-word;\n }\n\u003c/style\u003e\n\u003cscript\u003e\n window.katexOptions \u003d {\n delimiters: [\n {left: \u0027\\\\[\u0027, right: \u0027\\\\]\u0027, display: true}\n ]\n };\n\u003c/script\u003e\n","sections":[{"title":"","value":{"format":"HTML","content":"\n \u003cp\u003eBiologists have discovered a strange DNA molecule, best\n described as a sequence of \u003cspan class\u003d\"tex2jax_process\"\u003e$N$\u003c/span\u003e characters from the set\n \u003cspan class\u003d\"tex2jax_process\"\u003e$\\{ A, B\\} $\u003c/span\u003e. An unlikely\n sequence of mutations has resulted in a DNA strand consisting\n only of \u003cspan class\u003d\"tex2jax_process\"\u003e$A$\u003c/span\u003e’s. Biologists\n found that very odd, so they began studying the mutations in\n greater detail.\u003c/p\u003e\n \u003cp\u003eThey discovered two types of mutations. One type results in\n changing any single character of the sequence (\u003cspan class\u003d\"tex2jax_process\"\u003e$A \\rightarrow B$\u003c/span\u003e or \u003cspan class\u003d\"tex2jax_process\"\u003e$B \\rightarrow A$\u003c/span\u003e). The second type\n changes a whole \u003cem\u003eprefix\u003c/em\u003e of the sequence, specifically\n replacing all characters in positions from \u003cspan class\u003d\"tex2jax_process\"\u003e$1$\u003c/span\u003e to \u003cspan class\u003d\"tex2jax_process\"\u003e$K$\u003c/span\u003e (for some \u003cspan class\u003d\"tex2jax_process\"\u003e$K$\u003c/span\u003e between \u003cspan class\u003d\"tex2jax_process\"\u003e$1$\u003c/span\u003e and \u003cspan class\u003d\"tex2jax_process\"\u003e$N$\u003c/span\u003e, inclusive) with the other\n character (\u003cspan class\u003d\"tex2jax_process\"\u003e$A$\u003c/span\u003e with\n \u003cspan class\u003d\"tex2jax_process\"\u003e$B$\u003c/span\u003e, \u003cspan class\u003d\"tex2jax_process\"\u003e$B$\u003c/span\u003e with \u003cspan class\u003d\"tex2jax_process\"\u003e$A$\u003c/span\u003e).\u003c/p\u003e\n \u003cp\u003eCompute the least possible number of mutations that could\n convert the starting molecule to its end state (containing only\n \u003cspan class\u003d\"tex2jax_process\"\u003e$A$\u003c/span\u003e characters). Mutations\n can occur in any order.\u003c/p\u003e\n \u003ch2\u003eInput\u003c/h2\u003e\n \u003cp\u003eThe first line of input contains the positive integer\n \u003cspan class\u003d\"tex2jax_process\"\u003e$N$\u003c/span\u003e (\u003cspan class\u003d\"tex2jax_process\"\u003e$1 \\le N \\le 1\\, 000\\, 000$\u003c/span\u003e), the\n length of the molecule. The second line of input contains a\n string with \u003cspan class\u003d\"tex2jax_process\"\u003e$N$\u003c/span\u003e\n characters, with each character being either \u003cspan class\u003d\"tex2jax_process\"\u003e$A$\u003c/span\u003e or \u003cspan class\u003d\"tex2jax_process\"\u003e$B$\u003c/span\u003e. This string represents the\n starting state of the molecule.\u003c/p\u003e\n \u003ch2\u003eOutput\u003c/h2\u003e\n \u003cp\u003eThe first and only line of output must contain the required\n minimum number of mutations.\u003c/p\u003e\n \u003ch2\u003eSample 1\u003c/h2\u003e\u003cbody\u003e\u003ctable class\u003d\"vjudge_sample\"\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\nABBA\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e2\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n\u003c/body\u003e\n \u003ch2\u003eSample 2\u003c/h2\u003e\u003cbody\u003e\u003ctable class\u003d\"vjudge_sample\"\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\nBBABB\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e2\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n\u003c/body\u003e\n \u003ch2\u003eSample 3\u003c/h2\u003e\u003cbody\u003e\u003ctable class\u003d\"vjudge_sample\"\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\u003e12\nAAABBBAAABBB\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e4\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n\u003c/body\u003e\n "}}]}