{"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\"\u003eYou are the director of Arbitrarily Complex Machines (ACM for short), a company producing advanced machinery using even more advanced machinery. The old production machinery has broken down, so you need to buy new production machines for the company. Your goal is to make as much money as possible during the restructuring period. During this period you will be able to buy and sell machines and operate them for profit while ACM owns them. Due to space restrictions, ACM can own at most one machine at a time.\u003cbr\u003e\u003cbr\u003eDuring the restructuring period, there will be several machines for sale. Being an expert in the advanced machines market, you already know the price P\u003csub\u003ei\u003c/sub\u003e and the availability day Di for each machines M\u003csub\u003ei\u003c/sub\u003e. Note that if you do not buy machine M\u003csub\u003ei\u003c/sub\u003e on day Di, then somebody else will buy it and it will not be available later. Needless to say, you cannot buy a machine if ACM has less money than the price of the machine.\u003cbr\u003e\u003cbr\u003eIf you buy a machine M\u003csub\u003ei\u003c/sub\u003e on day D\u003csub\u003ei\u003c/sub\u003e, then ACM can operate it starting on day D\u003csub\u003ei\u003c/sub\u003e + 1. Each day that the machine operates, it produces a profit of Gi dollars for the company.\u003cbr\u003e\u003cbr\u003eYou may decide to sell a machine to reclaim a part of its purchase price any day after you’ve bought it. Each machine has a resale price R\u003csub\u003ei\u003c/sub\u003e for which it may be resold to the market. You cannot operate a machine on the day that you sell it, but you may sell a machine and use the proceeds to buy a new machine on the same day.\u003cbr\u003e\u003cbr\u003eOnce the restructuring period ends, ACM will sell any machine that it still owns. Your task is to maximize the amount of money that ACM makes during the restructuring.\u003c/div\u003e"}},{"title":"Input","value":{"format":"HTML","content":"The input consists of several test cases. Each test case starts with a line containing three positive integers N, C, and D. N is the number of machines for sale (N \u0026lt;\u003d 10^5), C is the number of dollars with which the company begins the restructuring (C \u0026lt;\u003d 10^9), and D is the number of days that the restructuring lasts (D \u0026lt;\u003d 10^9).\u003cbr\u003e\u003cbr\u003eEach of the next N lines describes a single machine for sale. Each line contains four integers D\u003csub\u003ei\u003c/sub\u003e, P\u003csub\u003ei\u003c/sub\u003e, R\u003csub\u003ei\u003c/sub\u003e and G\u003csub\u003ei\u003c/sub\u003e,\u003cbr\u003edenoting (respectively) the day on which the machine is for sale, the dollar price for which it may be bought, the\u003cbr\u003edollar price for which it may be resold and the daily profit generated by operating the machine. These numbers satisfy\u003cbr\u003e1 \u0026lt;\u003d D\u003csub\u003ei\u003c/sub\u003e \u0026lt;\u003d D, 1 \u0026lt;\u003d R\u003csub\u003ei\u003c/sub\u003e \u0026lt; P\u003csub\u003ei\u003c/sub\u003e \u0026#x14;\u0026lt;\u003d10^9 and 1 \u0026lt;\u003d G\u003csub\u003ei\u003c/sub\u003e \u0026lt;\u003d 10^9.\u003cbr\u003e\u003cbr\u003eThe last test case is followed by a line containing three zeros."}},{"title":"Output","value":{"format":"HTML","content":"For each test case, display its case number followed by the largest number of dollars that ACM can have at the end of day D + 1.\u003cbr\u003eFollow the format of the sample output."}},{"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\u003e6 10 20\r\n6 12 1 3\r\n1 9 1 2\r\n3 2 1 2\r\n8 20 5 4\r\n4 11 7 4\r\n2 10 9 1\r\n0 0 0\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003eCase 1: 44\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}}]}