{"trustable":true,"prependHtml":"\u003cscript\u003e window.katexOptions \u003d { disable: true }; \u003c/script\u003e\n\u003cscript type\u003d\"text/x-mathjax-config\"\u003e\n MathJax.Hub.Config({\n tex2jax: {\n inlineMath: [[\u0027$$$\u0027,\u0027$$$\u0027], [\u0027$\u0027,\u0027$\u0027]],\n displayMath: [[\u0027$$$$$$\u0027,\u0027$$$$$$\u0027], [\u0027$$\u0027,\u0027$$\u0027]]\n }\n });\n\u003c/script\u003e\n\u003cscript async src\u003d\"https://mathjax.codeforces.org/MathJax.js?config\u003dTeX-AMS-MML_HTMLorMML\" type\u003d\"text/javascript\"\u003e\u003c/script\u003e","sections":[{"title":"","value":{"format":"HTML","content":"\u003cdiv class\u003d\"panel_content\"\u003eDo you know the popular game World Of Warcraft (WOW) made by Blizzard? Tom plays a Blood Elf Paladin in WOW. The Paladins have 3 kinds of talent trees: Holy, Protection and Retribution.\u003cbr\u003eThe Holy Paladins in a team are healers, who provide healing service, heal the wounded; the Protection Paladins in a team are tanks, who attract the enemy\u0027s fire and protect the teammates; the Retribution Paladins in a team are melee damage dealers.\u003cbr\u003eAfter the version Cataclysm is published, the Retribution Paladins are found weakened by Blizzard. But fortunately, the Holy Paladins become more and more powerful amount the healers.\u003cbr\u003eIn order to join the dungeons and raids easier, Tom choose the talent of Holy to be his role\u0027s main talent (because the dungeons and raids are lack of healers). What a nice job the Holy Paladin is! Instead of standing in front of the monsters and enduring the hit, the only thing the Holy Paladins should do is to heal teammates and hardly worry about the monsters would attack them.\u003cbr\u003eUnlike the Retribution Paladins\u0027 operation of \"Keyboard Rolling\", the Holy Paladins have many spells to use of healing, so that some part of the pressing of some spells would be overlapping with each other. Furthermore, once a spell was cast successfully, it would possibly lead to casting one spell easily, that means you can get a buff which would allow you cast one spell in another way (The spell the buff effects can be anyone he can cast).\u003cbr\u003eIt is high-operation-frequency when in the dungeons, so Tom can hardly notice whether he cast a spell successfully or how much he had healed. And Tom really wants to know that, so he turns to you for a favor, asks you to write an Add-On which can help him record the total healing points and which spell brings higher total healing points.\u003cbr\u003eAbout the spells:\u003cbr\u003eEach spell has a distinct name.\u003cbr\u003eSpell needs Mana Points(MP). You cannot cast the spell when there is not enough mana.\u003cbr\u003eSpell has Cool Down Time. Once you cast a spell successfully, you cannot cast the same spell during the next Cool Down Time.\u003cbr\u003eIf you fail to cast a spell, the keys you have pressed can be the prefix of the next spell.\u003cbr\u003eIf spell-2 is the suffix of spell-1, then spell-1 is priority.\u003cbr\u003eNo two spells can be cast in same moment.\u003cbr\u003eSome spells will lead to some buffs(described above) so that when you press some other keys sequences, you will cast some spells, too. Notice that the buff will exist until you cast the exact spell successfully, no matter you use the buff or not. (In other word, if you get the buff of spell A, then you don\u0027t use the buff but cast the spell A, the buff of spell A will disappear.)\u003cbr\u003eOne spell will immediately be cast once it fits the spell condition.\u003cbr\u003eBesides, the Holy Paladins have a talent called Meditation, which will regenerates one mana every second. Meditation will regenerate MP immediately when one second starts. And Tom can press 5 keys every second.\u003c/div\u003e"}},{"title":"Input","value":{"format":"HTML","content":"There are no more than 20 test cases, end by EOF.\u003cbr\u003eIn each test case:\u003cbr\u003eFirst line contains 2 integers N (0\u0026lt;N\u0026lt;\u003d10000) and MP (0\u0026lt;\u003dMP\u0026lt;\u003d100000), indicating there will be N spells and you have MP Mana Points at the beginning and you can have MP Mana Points at most.\u003cbr\u003eThen follows N lines:\u003cbr\u003eEach line contains Spell Name, Spell Press Key Sequence, Spell Mana Cost(MC), Spell Healing Points(HP), and Spell Cool Down Time(CD). The Spell Name is no more than 50 characters; Spell Press Key Sequence is no more than 20 characters and all the characters are capital letters; -MP\u0026lt;\u003dMC\u0026lt;\u003dMP, the spell will regenerate manas if the MC is negative;\u003cbr\u003e0\u0026lt;\u003dHP\u0026lt;\u003d100000; 0\u0026lt;\u003dCD\u0026lt;\u003d1000, notice that here the CD is base on 0.2 second, (For example: If CD\u003d5, then the Spell Cool Down Time is 1 second).\u003cbr\u003eThen follow integer M (M+N\u0026lt;\u003d10000), indicates the buffs may appear.\u003cbr\u003eThen M lines follow:\u003cbr\u003eEach line contains Spell-1 Name, Spell-2 Name, Spell-2\u0027s Another Press Key Sequence, which means when you cast Spell-1, you can get the buff of Spell-2, the effect of the buff is Spell-2\u0027s Another Press Key Sequence. The Spell-1 Name and Spell-2 Name is the Spell Name appear in the N lines, Spell-2\u0027s Another Press Key Sequence is no more than 20 characters and all the characters are capital letters.\u003cbr\u003eThe last line is Tom\u0027s press sequence, the length is no longer than 500000 and all the characters are capital letters."}},{"title":"Output","value":{"format":"HTML","content":"For each case, please output :\u003cbr\u003eCase X:\u003cbr\u003eThe Total Healing Point is Y.\u003cbr\u003eThen several lines follow(3 lines at most):\u003cbr\u003eThe first line contains the information of the spell with highest total healing points; the second line contains information of the spell with second highest; and the third line contains the third highest. The informations contains Spell Name, Total Spell Healing Points, Spell times. Indicate the spell\u0027s name, spell\u0027s total healing points and how many times the spell had been cast. If the total Healing Points is equal then compare with the times who was cast most, if it still the same, then ordered by the Lexicographic order. If there is less than 3 spells, output the rest.\u003cbr\u003e(Here X is the case number, Y is the total Healing Points)\u003cbr\u003eIf Y is not positive, just print the following text instead:\u003cbr\u003eCase X:\u003cbr\u003eNo Healing Spell!\u003cbr\u003ePrint a blank line between test cases."}},{"title":"Sample","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\u003e3 10\r\nHolyShock ASDF 5 10 3\r\nJudgements SDFG -10 0 10\r\nLightsOfDawn DFGH 10 25 10\r\n2\r\nHolyShock Judgements G\r\nJudgements LightsOfDawn H\r\nASDFSDFGH\r\n\r\n1 10\r\nWordOfGlory A 1 10 1\r\n0\r\nAAAAAAAA\r\n\r\n1 1\r\nHolyLight A 1 10 1\r\n0\r\nAAAAAAAAAA\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003eCase 1:\r\nThe Total Healing Point is 35.\r\nLightsOfDawn 25 1\r\nHolyShock 10 1\r\n\r\nCase 2:\r\nThe Total Healing Point is 40.\r\nWordOfGlory 40 4\r\n\r\nCase 3:\r\nThe Total Healing Point is 20.\r\nHolyLight 20 2\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}}]}