/*! path: src/contest/atcoder/abc173/d.ts */!function(t){var e={};function n(i){if(e[i])return e[i].exports;var r=e[i]={i:i,l:!1,exports:{}};return t[i].call(r.exports,r,r.exports,n),r.l=!0,r.exports}n.m=t,n.c=e,n.d=function(t,e,i){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:i})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var i=Object.create(null);if(n.r(i),Object.defineProperty(i,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var r in t)n.d(i,r,function(e){return t[e]}.bind(null,r));return i},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=0)}([function(t,e,n){"use strict";(function(t){var i=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0}),e.main=void 0;const r=n(2),s=i(n(3)),o=n(4);class u{constructor(t,e){this.l=t,this.r=e}get min(){return Math.min(this.l,this.r)}split(t){return{a:new u(this.l,t),b:new u(t,this.r)}}}function c(t){const e=r.getNextInt(t),n=e(),i=[];for(let t=0;t<n;t++)i.push(e());i.sort((t,e)=>e-t);const s=new o.PriorityQueue(n+1,(t,e)=>e.min-t.min);s.push(new u(i[0],i[0]));let c=0;for(let t=1;t<n;t++){const e=i[t],n=s.pop();c+=n.min;const{a:r,b:o}=n.split(e);s.push(r),s.push(o)}console.log(c)}if(e.main=c,n.c[n.s]===t){c(s.default.readFileSync("/dev/stdin","utf8"))}}).call(this,n(1)(t))},function(t,e){t.exports=function(t){return t.webpackPolyfill||(t.deprecate=function(){},t.paths=[],t.children||(t.children=[]),Object.defineProperty(t,"loaded",{enumerable:!0,get:function(){return t.l}}),Object.defineProperty(t,"id",{enumerable:!0,get:function(){return t.i}}),t.webpackPolyfill=1),t}},function(t,e,n){"use strict";function*i(t){const e=t.split(/\s+/);for(const t of e)yield t}Object.defineProperty(e,"__esModule",{value:!0}),e.getNextBigInt=e.getNextInt=e.getNext=e.getIteratorWithParser=e.getIterator=void 0,e.getIterator=i,e.getIteratorWithParser=function*(t,e){const n=t.split(/\s+/);for(const t of n)yield e(t)},e.getNext=function(t){const e=i(t);return()=>e.next().value},e.getNextInt=function(t){const e=i(t);return()=>parseInt(e.next().value)},e.getNextBigInt=function(t){const e=i(t);return()=>BigInt(e.next().value)}},function(t,e){t.exports=require("fs")},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.PriorityQueue=void 0;e.PriorityQueue=class{constructor(t,e){this.capacity=t,this.comparator=e,this.upRotate=t=>{if(0===t)return;const e=(t-1)/2|0;e>=0&&this.compare(e,t)>0&&(this.swap(e,t),this.upRotate(e))},this.push=t=>{const e=this.n;this.n++,this.v[e]=t,this.upRotate(e)},this.downRotate=t=>{const e=2*t+1,n=2*t+2,i=this.minIndex(t,e,n);e===i?(this.swap(e,t),this.downRotate(e)):n===i&&(this.swap(n,t),this.downRotate(n))},this.pop=()=>{if(this.isEmpty)throw Error("Heap is empty");const t=this.v[0];return this.swap(0,this.n-1),this.v[this.n-1]=void 0,this.n--,this.downRotate(0),t},this.peek=()=>{if(this.isEmpty)throw Error("Heap is empty");return this.v[0]},this.showHeap=()=>{for(let t=1;t-1<this.n;t*=2)console.log(this.v.slice(t-1,Math.min(this.capacity,2*t-1)))},this.v=new Array(t),this.n=0,this.compare=(t,n)=>t>=this.n&&n>=this.n?0:t>=this.n?1:n>=this.n?-1:e(this.v[t],this.v[n])}swap(t,e){const n=this.v[t];this.v[t]=this.v[e],this.v[e]=n}minIndex(...t){return t.reduce((t,e)=>this.compare(t,e)>0?e:t,t[0])}get isEmpty(){return!this.n}get size(){return this.n}get full(){return this.n>=this.capacity}}}]);