{"trustable":false,"prependHtml":"\u003cstyle type\u003d\"text/css\"\u003e\n div.illustration {\n float: right;\n padding-left: 20px;\n }\n div.illustration .illustration {\n width: 100%;\n border-radius: 4px;\n }\n pre {\n display: block;\n margin: 0 0 10px;\n font-size: 13px;\n line-height: 1.42857143;\n color: #333;\n word-break: break-all;\n word-wrap: break-word;\n }\n\u003c/style\u003e\n\u003cscript\u003e\n window.katexOptions \u003d {\n delimiters: [\n {left: \u0027\\\\[\u0027, right: \u0027\\\\]\u0027, display: true}\n ]\n };\n\u003c/script\u003e\n","sections":[{"title":"","value":{"format":"MD","content":"There are n cities in the country numbered from 1 to $n$ including the capital which is city 1. You want to travel only by train. There are m trains available where the $i_{th}$ train departs from city $a_ i$ and takes you to city $b_ i$. The departure time is $s_ i$ and arrival time is $e_ i$.\n\nThe time now is \u003cspan class\u003d\"tex2jax_process\"\u003e$0$\u003c/span\u003e and you are at the capital. You need to go to city \u003cspan class\u003d\"tex2jax_process\"\u003e$n$\u003c/span\u003e. Your only concern is the waiting time at any city. You would rather be on a long train ride than at a station waiting. If you wait \u003cspan class\u003d\"tex2jax_process\"\u003e$t$\u003c/span\u003e units, your sadness grows by \u003cspan class\u003d\"tex2jax_process\"\u003e$t^2$\u003c/span\u003e units. \n\nFind a route that minimizes your sadness. Note that the total time needed to reach your final destination is irrelevant."}},{"title":"Input","value":{"format":"MD","content":"The first line contains two integers $n$ and $m$ $(1 \\leq n,m \\leq 2 * 10^5)$.\n\nEach of the next $m$ lines contains four space-separated integers $a_ i$, $b_ i$, $s_ i$ and $e_ i$ \n$(1 \\leq a_ i, b_ i \\leq n)$ $(0 \\leq s_ i \\leq e_ i \\le 10^6)$.\n\nA train could depart and arrive at the same city. So weird, but okay.\n\nIt is always possible to reach the destination.\n\n**Important**: All the times mentioned in the input are distinct."}},{"title":"Output","value":{"format":"MD","content":"Output the minimized sum of sadness."}},{"title":"Sample 1","value":{"format":"MD","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\u003e5 8\n1 2 1 10\n2 4 11 16\n2 1 9 12\n3 5 28 100\n1 2 3 8\n4 3 20 21\n1 3 13 27\n3 5 23 24\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e12\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}},{"title":"Sample 2","value":{"format":"MD","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 5\n1 1 10 20\n1 2 30 40\n1 2 50 60\n1 2 70 80\n2 3 90 95\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e1900\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}}]}