You build a graph with N nodes and N−1 edges. The graph must be connected.
The figure below is a graph with N=5 nodes and N−1=4 edges.

An edge can connect two nodes. The degree of a node is the number of edges attached to it. In the figure above, A has degree 3 and B has degree 1.
The score of the graph is the sum of the scores of all nodes, and the score of a node is decided by its degree alone. Given the score for each degree, write a program that finds the largest score among the graphs that meet the conditions.