{"trustable":false,"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":"\u003cscript type\u003d\u0027text/x-mathjax-config\u0027\u003eMathJax.Hub.Config({tex2jax: { inlineMath: [[\u0027$\u0027,\u0027$\u0027]] } }); \u003c/script\u003e\n\u003cscript type\u003d\u0027text/javascript\u0027 src\u003d\u0027https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config\u003dTeX-AMS-MML_HTMLorMML\u0027\u003e\u003c/script\u003e\n\u003cscript type\u003d\u0027text/javascript\u0027\u003esetTimeout(function(){MathJax.Hub.Queue([\u0027Typeset\u0027, MathJax.Hub, \u0027left_view\u0027]);}, 2000);\u003c/script\u003e\n\u003cdiv class\u003d\"panel_content\"\u003e\n Alice has opened up a 24-hour mooncake shop. She always gets a lot of orders. Only when the time is K o’clock sharp( K \u003d 0,1,2 …. 23) she can make mooncakes, and We assume that making cakes takes no time. Due to the fluctuation of the price of the ingredients, the cost of a mooncake varies from hour to hour. She can make mooncakes when the order comes,or she can make mooncakes earlier than needed and store them in a fridge. The cost to store a mooncake for an hour is S and the storage life of a mooncake is T hours. She now asks you for help to work out a plan to minimize the cost to fulfill the orders.\n\u003c/div\u003e"}},{"title":"Input","value":{"format":"HTML","content":"The input contains no more than 10 test cases. \n\u003cbr\u003eFor each test case:\n\u003cbr\u003eThe first line includes two integers N and M. N is the total number of orders. M is the number of hours the shop opens. \n\u003cbr\u003eThe next N lines describe all the orders. Each line is in the following format:\n\u003cbr\u003e\n\u003cbr\u003emonth date year H R\n\u003cbr\u003e\n\u003cbr\u003eIt means that on a certain date, a customer orders R mooncakes at H o’clock. “month” is in the format of abbreviation, so it could be \"Jan\", \"Feb\", \"Mar\", \"Apr\", \"May\", \"Jun\", \"Jul\", \"Aug\", \"Sep\", \"Oct\", \"Nov\" or \"Dec\". H and R are all integers. \n\u003cbr\u003eAll the orders are sorted by the time in increasing order. \n\u003cbr\u003eThe next line contains T and S meaning that the storage life of a mooncake is T hours and the cost to store a mooncake for an hour is S.\n\u003cbr\u003eFinally, M lines follow. Among those M lines, the i\u003csup\u003eth\u003c/sup\u003e line( i starts from 1) contains a integer indicating the cost to make a mooncake during the i\u003csup\u003eth\u003c/sup\u003e hour . The cost is no more than 10000. Jan 1st 2000 0 o\u0027clock belongs to the 1\u003csup\u003est\u003c/sup\u003e hour, Jan 1st 2000 1 o\u0027clock belongs to the 2\u003csup\u003end\u003c/sup\u003e hour, …… and so on.\n\u003cbr\u003e\n\u003cbr\u003e(0\u0026lt;N \u0026lt;\u003d 2500; 0 \u0026lt; M,T \u0026lt;\u003d100000; 0\u0026lt;\u003dS \u0026lt;\u003d 200; R\u0026lt;\u003d10000 ; 0\u0026lt;\u003dH\u0026lt;24)\n\u003cbr\u003e\n\u003cbr\u003eThe input ends with N \u003d 0 and M \u003d 0."}},{"title":"Output","value":{"format":"HTML","content":"You should output one line for each test case: the minimum cost. \n\u003cbr\u003e"}},{"title":"Sample Input","value":{"format":"HTML","content":"\u003cpre\u003e1 10\nJan 1 2000 9 10\n5 2\n20 \n20 \n20 \n10 \n10\n8\n7 \n9 \n5 \n10\n0 0\u003c/pre\u003e"}},{"title":"Sample Output","value":{"format":"HTML","content":"\u003cpre\u003e70\n\n \u003ci style\u003d\"font-size:1px\"\u003e \u003c/i\u003e\u003c/pre\u003e"}},{"title":"Hint","value":{"format":"HTML","content":"\u003cpre\u003e\n“Jan 1 2000 9 10” means in Jan 1st 2000 at 9 o\u0027clock , there\u0027s a consumer ordering 10 mooncakes. \nMaybe you should use 64-bit signed integers. The answer will fit into a 64-bit signed integer.\n\n \u003c/pre\u003e"}}]}