Library

No attempts yetTime limit1sMemory limit128 MB

Problem

During the holidays, Bajtazar became a lover of good literature and read a great many books that he borrowed from the library. One day his friend Wyjatek visited and took interest in one of the borrowed books, and after much persuasion Bajtazar agreed to lend it to him.

The holidays passed quickly and a new school year began. When it was time to return the books, Bajtazar remembered that he had lent one of them to Wyjatek, who admitted that he had lost it. On hearing this, the librarians decided that as punishment Bajtazar would have to help them sort the library cards.

The cards are split across many already-sorted files of various sizes. Bajtazar's task is to merge them into a single sorted file. He can merge only two files at a time, and for simplicity we assume that the time needed to merge two files equals the sum of their lengths.

Given the number of files and the length of each file, write a program that computes the minimum total time needed to merge all files into one.

Input

The first line contains the number of files nn (2n1000002 \le n \le 100000). The second line contains nn integers s1,s2,,sns_1, s_2, \dots, s_n separated by single spaces, where sis_i is the length of file number ii (1si100001 \le s_i \le 10000).

Output

Print the minimum total time needed to merge all files into one, as a single integer on one line.