{"trustable":true,"prependHtml":"\u003cstyle type\u003d\"text/css\"\u003e\n section pre {\n display: block;\n padding: 9.5px;\n margin: 0 0 10px;\n font-size: 13px;\n line-height: 1.42857143;\n word-break: break-all;\n word-wrap: break-word;\n color: #333;\n background: rgba(255, 255, 255, 0.5);\n border: 1px solid #ccc;\n border-radius: 6px;\n }\n\u003c/style\u003e\n\u003cscript\u003e\n window.katexOptions \u003d {\n delimiters: [\n {left: \u0027\\\\(\u0027, right: \u0027\\\\)\u0027, display: false},\n {left: \u0027\\\\[\u0027, right: \u0027\\\\]\u0027, display: true}\n ]\n };\n\u003c/script\u003e\n","sections":[{"title":"Problem Statement","value":{"format":"HTML","content":"\n\u003csection\u003e\n\u003cp\u003eThere is a grid with \u003cvar\u003e\\(N\\)\u003c/var\u003e rows and \u003cvar\u003e\\(N\\)\u003c/var\u003e columns. Let \u003cvar\u003e\\((i,j)\\)\u003c/var\u003e denote the square at the \u003cvar\u003e\\(i\\)\u003c/var\u003e-th row from the top and \u003cvar\u003e\\(j\\)\u003c/var\u003e-th column from the left.\u003c/p\u003e\n\u003cp\u003eTakahashi is initially at square \u003cvar\u003e\\((1,1)\\)\u003c/var\u003e with zero money.\u003c/p\u003e\n\u003cp\u003eWhen Takahashi is at square \u003cvar\u003e\\((i,j)\\)\u003c/var\u003e, he can perform one of the following in one \u003cstrong\u003eaction\u003c/strong\u003e:\u003c/p\u003e\n\u003cul\u003e\n\u003cli\u003eStay at the same square and increase his money by \u003cvar\u003e\\(P_{i,j}\\)\u003c/var\u003e.\u003c/li\u003e\n\u003cli\u003ePay \u003cvar\u003e\\(R_{i,j}\\)\u003c/var\u003e from his money and move to square \u003cvar\u003e\\((i,j+1)\\)\u003c/var\u003e.\u003c/li\u003e\n\u003cli\u003ePay \u003cvar\u003e\\(D_{i,j}\\)\u003c/var\u003e from his money and move to square \u003cvar\u003e\\((i+1,j)\\)\u003c/var\u003e.\u003c/li\u003e\n\u003c/ul\u003e\n\u003cp\u003eHe cannot make a move that would make his money negative or take him outside the grid.\u003c/p\u003e\n\u003cp\u003eIf Takahashi acts optimally, how many actions does he need to reach square \u003cvar\u003e\\((N,N)\\)\u003c/var\u003e?\u003c/p\u003e\n\u003c/section\u003e\n"}},{"title":"Constraints","value":{"format":"HTML","content":"\n\u003csection\u003e\n\u003cul\u003e\n\u003cli\u003e\u003cvar\u003e\\(2 \\leq N \\leq 80\\)\u003c/var\u003e\u003c/li\u003e\n\u003cli\u003e\u003cvar\u003e\\(1 \\leq P_{i,j} \\leq 10^9\\)\u003c/var\u003e \u003c/li\u003e\n\u003cli\u003e\u003cvar\u003e\\(1 \\leq R_{i,j},D_{i,j} \\leq 10^9\\)\u003c/var\u003e\u003c/li\u003e\n\u003cli\u003eAll input values are integers.\u003c/li\u003e\n\u003c/ul\u003e\n\u003c/section\u003e\n"}},{"title":"Input","value":{"format":"HTML","content":"\n\u003csection\u003e\n\u003cp\u003eThe input is given from Standard Input in the following format:\u003c/p\u003e\n\u003cpre\u003e\u003cvar\u003e\\(N\\)\u003c/var\u003e\n\u003cvar\u003e\\(P_{1,1}\\)\u003c/var\u003e \u003cvar\u003e\\(\\ldots\\)\u003c/var\u003e \u003cvar\u003e\\(P_{1,N}\\)\u003c/var\u003e\n\u003cvar\u003e\\(\\vdots\\)\u003c/var\u003e \n\u003cvar\u003e\\(P_{N,1}\\)\u003c/var\u003e \u003cvar\u003e\\(\\ldots\\)\u003c/var\u003e \u003cvar\u003e\\(P_{N,N}\\)\u003c/var\u003e\n\u003cvar\u003e\\(R_{1,1}\\)\u003c/var\u003e \u003cvar\u003e\\(\\ldots\\)\u003c/var\u003e \u003cvar\u003e\\(R_{1,N-1}\\)\u003c/var\u003e\n\u003cvar\u003e\\(\\vdots\\)\u003c/var\u003e\n\u003cvar\u003e\\(R_{N,1}\\)\u003c/var\u003e \u003cvar\u003e\\(\\ldots\\)\u003c/var\u003e \u003cvar\u003e\\(R_{N,N-1}\\)\u003c/var\u003e\n\u003cvar\u003e\\(D_{1,1}\\)\u003c/var\u003e \u003cvar\u003e\\(\\ldots\\)\u003c/var\u003e \u003cvar\u003e\\(D_{1,N}\\)\u003c/var\u003e\n\u003cvar\u003e\\(\\vdots\\)\u003c/var\u003e\n\u003cvar\u003e\\(D_{N-1,1}\\)\u003c/var\u003e \u003cvar\u003e\\(\\ldots\\)\u003c/var\u003e \u003cvar\u003e\\(D_{N-1,N}\\)\u003c/var\u003e\n\u003c/pre\u003e\n\u003c/section\u003e\n"}},{"title":"Output","value":{"format":"HTML","content":"\n\u003csection\u003e\n\u003cp\u003ePrint the answer.\u003c/p\u003e\n\u003c/section\u003e\n"}},{"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\u003e3\n1 2 3\n3 1 2\n2 1 1\n1 2\n4 3\n4 2\n1 5 7\n5 3 3\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e8\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n\n\u003csection\u003e\n\n\u003c/section\u003e\n\n\u003csection\u003e\n\n\u003cp\u003e\u003cimg alt\u003d\"Figure\" src\u003d\"CDN_BASE_URL/ee5c4cb3658d1f7d31147bfce34b11b2?v\u003d1726014412\"\u003e\u003c/p\u003e\n\u003cp\u003eIt is possible to reach square \u003cvar\u003e\\((3,3)\\)\u003c/var\u003e in eight actions as follows:\u003c/p\u003e\n\u003cul\u003e\n\u003cli\u003eStay at square \u003cvar\u003e\\((1,1)\\)\u003c/var\u003e and increase money by \u003cvar\u003e\\(1\\)\u003c/var\u003e. His money is now \u003cvar\u003e\\(1\\)\u003c/var\u003e.\u003c/li\u003e\n\u003cli\u003ePay \u003cvar\u003e\\(1\\)\u003c/var\u003e money and move to square \u003cvar\u003e\\((2,1)\\)\u003c/var\u003e. His money is now \u003cvar\u003e\\(0\\)\u003c/var\u003e.\u003c/li\u003e\n\u003cli\u003eStay at square \u003cvar\u003e\\((2,1)\\)\u003c/var\u003e and increase money by \u003cvar\u003e\\(3\\)\u003c/var\u003e. His money is now \u003cvar\u003e\\(3\\)\u003c/var\u003e.\u003c/li\u003e\n\u003cli\u003eStay at square \u003cvar\u003e\\((2,1)\\)\u003c/var\u003e and increase money by \u003cvar\u003e\\(3\\)\u003c/var\u003e. His money is now \u003cvar\u003e\\(6\\)\u003c/var\u003e. \u003c/li\u003e\n\u003cli\u003eStay at square \u003cvar\u003e\\((2,1)\\)\u003c/var\u003e and increase money by \u003cvar\u003e\\(3\\)\u003c/var\u003e. His money is now \u003cvar\u003e\\(9\\)\u003c/var\u003e.\u003c/li\u003e\n\u003cli\u003ePay \u003cvar\u003e\\(4\\)\u003c/var\u003e money and move to square \u003cvar\u003e\\((2,2)\\)\u003c/var\u003e. His money is now \u003cvar\u003e\\(5\\)\u003c/var\u003e.\u003c/li\u003e\n\u003cli\u003ePay \u003cvar\u003e\\(3\\)\u003c/var\u003e money and move to square \u003cvar\u003e\\((3,2)\\)\u003c/var\u003e. His money is now \u003cvar\u003e\\(2\\)\u003c/var\u003e.\u003c/li\u003e\n\u003cli\u003ePay \u003cvar\u003e\\(2\\)\u003c/var\u003e money and move to square \u003cvar\u003e\\((3,3)\\)\u003c/var\u003e. His money is now \u003cvar\u003e\\(0\\)\u003c/var\u003e.\u003c/li\u003e\n\u003c/ul\u003e\n\u003c/section\u003e\n"}},{"title":"Sample 2","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\n1 1 1\n1 1 1\n1 1 1\n1000000000 1000000000\n1000000000 1000000000\n1000000000 1000000000\n1000000000 1000000000 1000000000\n1000000000 1000000000 1000000000\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e4000000004\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n\n\u003csection\u003e\n\n\u003c/section\u003e\n\n\u003csection\u003e\n\u003c/section\u003e\n"}}]}