{"trustable":false,"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\u003eBowen will study $$$n$$$ kinds of magic. Each magic costs $$$c_i$$$ and it will damage some types of monsters. There are three types of monsters : monster \"\u003cspan class\u003d\"tex-font-style-tt\"\u003eA\u003c/span\u003e\", monster \"\u003cspan class\u003d\"tex-font-style-tt\"\u003eB\u003c/span\u003e\" and monster \"\u003cspan class\u003d\"tex-font-style-tt\"\u003eC\u003c/span\u003e\". Each magic can damage one, two or all three types of monsters in it.\u003c/p\u003e\n\u003cp\u003eBowen knows that he needs to damage all three types of monsters to save the world, so he want to know the minimum price. \u003c/p\u003e"}},{"title":"Input","value":{"format":"HTML","content":"\u003cp\u003eThe first line contains a single integer $$$n$$$ $$$(1 \\le n \\le 1\\,000)$$$ — the types of magic.\u003c/p\u003e\n\u003cp\u003eEach of the next $$$n$$$ lines contains an integer $$$c_i$$$ $$$(1 \\le c_i \\le 100\\,000)$$$ and a string $$$s_i$$$ — the price of the $$$i$$$-th magic. String $$$s_i$$$ contains from $$$1$$$ to $$$3$$$ characters, and the only possible characters are \"\u003cspan class\u003d\"tex-font-style-tt\"\u003eA\u003c/span\u003e\", \"\u003cspan class\u003d\"tex-font-style-tt\"\u003eB\u003c/span\u003e\" and \"\u003cspan class\u003d\"tex-font-style-tt\"\u003eC\u003c/span\u003e\" which means the type of monsters it can kill. It is guaranteed that each letter appears no more than once in each string $$$s_i$$$. The order of letters in strings $$$s_i$$$ is arbitrary.\u003c/p\u003e"}},{"title":"Output","value":{"format":"HTML","content":"\u003cp\u003ePrint \u003cspan class\u003d\"tex-font-style-tt\"\u003e-1\u003c/span\u003e if there is no way to destroy all three types of monsters. Otherwise print the minimum total price of magic that Bowen needs to pay to study.\u003c/p\u003e"}},{"title":"Sample 1","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\n5 A\n6 B\n4 C\n100 ABC\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e15\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}}]}