Type: Default 1000ms 256MiB

那LH问你

You cannot submit for this problem because the contest is ended. You can click "Open in Problem Set" to view this problem in normal mode.

Background

lhlh 在讲课时发现有的同学居然还不知道什么是树,lh非常气愤,于是决定出一道题来考考大家。

Description

给定一个只包含整数的数组 A=(A1,A2,,AN)A=(A_1,A_2,\dots,A_N), 对于一颗有 NN 个节点的树 TT,定义 f(T)f(T) 如下:


  • did_i为树TT中节点ii的度,则f(T)=i=1Ndi2Aif(T)=\sum_{i=1}^{N} {d_i^2A_i}

请你计算出最小的f(T)f(T)值。

保证最后的答案不超过2632^{63}

Format

Input

第一行输入一个整数:N(2N2×105)N(2{\le}N{\le}2\times{10}^5)
第二行输入NN个整数:A1A2ANA_1{\quad}A_2{\quad}{\dots}{\quad}A_N(1Ai109)(1{\le}A_i{\le}{10}^9)

Output

一个整数,代表f(T)f(T)的最小值

Samples1

4
3 2 5 2
24

Samples2

7
10 5 10 2 10 13 15
128

Limitation

2s, 1024MB for each test case.

SDNU_ACM_ICPC_2024秋季结训赛

Not Attended
Status
Done
Rule
ACM/ICPC
Problem
12
Start at
2024-12-15 12:00
End at
2024-12-15 16:00
Duration
4 hour(s)
Host
Partic.
41