{"trustable":false,"sections":[{"title":"","value":{"format":"HTML","content":"\u003chtml\u003e\n \u003chead\u003e\u003c/head\u003e\n \u003cbody\u003e\n \u003cspan class\u003d\"solution-visible-txt\"\u003e\u003c/span\u003e\n \u003ch3\u003e Read problems statements in \u003ca target\u003d\"_blank\" href\u003d\"CDN_BASE_URL/10912c860977620f4bb2f66170c199a2?v\u003d1525114200\"\u003eMandarin Chinese \u003c/a\u003e , \u003ca target\u003d\"_blank\" href\u003d\"CDN_BASE_URL/193199e5e86e41dfc2aa828144c3b0ee?v\u003d1525114200\"\u003eRussian\u003c/a\u003e and \u003ca target\u003d\"_blank\" href\u003d\"CDN_BASE_URL/b3fea85228a53a448457da8ac4df311f?v\u003d1525114200\"\u003eVietnamese\u003c/a\u003e\u003c/h3\u003e \n \u003cp\u003eChef loves to play with arrays by himself. Today, he has an array \u003cb\u003eA\u003c/b\u003e consisting of \u003cb\u003eN\u003c/b\u003e distinct integers. He wants to perform the following operation on his array \u003cb\u003eA\u003c/b\u003e.\u003c/p\u003e \n \u003cp\u003e\u003c/p\u003e\n \u003cul\u003e \n \u003cli\u003eSelect a pair of adjacent integers and remove the larger one of these two. This decreases the array size by 1. Cost of this operation will be equal to the smaller of them. \u003c/li\u003e \n \u003c/ul\u003e \n \u003cp\u003e\u003c/p\u003e \n \u003cp\u003eFind out minimum sum of costs of operations needed to convert the array into a single element.\u003c/p\u003e \n \u003ch3\u003eInput\u003c/h3\u003e \n \u003cp\u003eFirst line of input contains a single integer \u003cb\u003eT\u003c/b\u003e denoting the number of test cases. First line of each test case starts with an integer \u003cb\u003eN\u003c/b\u003e denoting the size of the array \u003cb\u003eA\u003c/b\u003e. Next line of input contains \u003cb\u003eN\u003c/b\u003e space separated integers, where the \u003cb\u003ei\u003csup\u003eth\u003c/sup\u003e\u003c/b\u003e integer denotes the value \u003cb\u003eA\u003csub\u003ei\u003c/sub\u003e\u003c/b\u003e.\u003c/p\u003e \n \u003ch3\u003eOutput\u003c/h3\u003e \n \u003cp\u003eFor each test case, print the minimum cost required for the transformation.\u003c/p\u003e \n \u003ch3\u003eConstraints\u003c/h3\u003e \n \u003cul\u003e \n \u003cli\u003e\u003cb\u003e1 ≤ T ≤ 10 \u003c/b\u003e\u003c/li\u003e \n \u003cli\u003e\u003cb\u003e2 ≤ N ≤ 50000 \u003c/b\u003e\u003c/li\u003e \n \u003cli\u003e\u003cb\u003e1 ≤ A\u003csub\u003ei\u003c/sub\u003e ≤ 10\u003csup\u003e5\u003c/sup\u003e \u003c/b\u003e\u003c/li\u003e \n \u003c/ul\u003e \n \u003ch3\u003eExample\u003c/h3\u003e \n \u003cpre\u003e\n\u003cb\u003eInput\u003c/b\u003e\n2\n2\n3 4\n3\n4 2 5\n\n\u003cb\u003eOutput\u003c/b\u003e\n3\n4\n\u003c/pre\u003e \n \u003ch3\u003eExplanation\u003c/h3\u003e \n \u003cb\u003eTest 1 : \u003c/b\u003e Chef will make only 1 move: pick up both the elements (that is, 3 and 4), remove the larger one (4), incurring a cost equal to the smaller one (3).\n \u003c/body\u003e\n\u003c/html\u003e"}}]}