{"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\"\u003eThe design of the meal card in the canteen of the UESTC main campus is quite peculiar, as it checks the balance before purchase. If the remaining amount on the card is greater than or equal to 5 yuan before purchasing an item, the purchase will definitely be successful (even if the balance becomes negative after the purchase). Otherwise, the purchase will not be possible (even if the amount is sufficient). Therefore, everyone hopes to keep the balance on the card as low as possible.\u003cbr\u003eOne day, there are n types of dishes for sale in the canteen, each of which can be purchased once. It is known the price of each dish and the balance on the card. The question is, what is the minimum balance that can be left on the card.\u003cbr\u003e\u003c/div\u003e"}},{"title":"Input","value":{"format":"HTML","content":"Multiple test cases. For each test case:\u003cbr\u003eThe first line contains a positive integer n, indicating the number of dishes. n\u0026lt;\u003d1000.\u003cbr\u003eThe second line contains n positive integers, indicating the price of each dish. The price does not exceed 50.\u003cbr\u003eThe third line contains a positive integer m, indicating the balance on the card. m\u0026lt;\u003d1000.\u003cbr\u003e\u003cbr\u003en\u003d0 indicates the end of the input.\u003cbr\u003e"}},{"title":"Output","value":{"format":"HTML","content":"For each input, output one line containing an integer, indicating the possible minimum balance on the card."}},{"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\u003e1\r\n50\r\n5\r\n10\r\n1 2 3 2 1 1 2 3 2 1\r\n50\r\n0\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e-45\r\n32\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e"}}]}