#Lutece2039. 心的距离

心的距离

Migrated from Lutece 2039 心的距离

All parts of this problem, including description, images, samples, data and checker, might be broken. If you find bugs in this problem, please contact the admins.

Description

通过坡道上的交谈,子辉知道了她叫Sakura,如樱花一样美丽的名字。而且还是同一个班上的。但在子辉Sakura的班级座位之间却隔着有nn位同学,子辉想要支走中间这nn位同学,从而和Sakura拉近心的距离。包括子辉Sakura在内一共n+2n+2个人(子辉编号为11Sakura编号为n+2n+2),从左到右第ii个人的任性指数为aia_i。支走第ii个人时,设第ii个人左边最近的还没走的人(可以是子辉Sakura)编号为jj,右边为kk,需付出aj×ai×aka_j \times a_i \times a_k 的精力。子辉想要知道最少付出多少精力,可以支走中间所有的同学,拉近与Sakura的距离,这就需要机智地安排顺序了。

Input

第一行一个整数 nn (1n2001≤n≤200). 第二行 n+2n+2 个用空格分隔的整数 a1a_1,a2a_2,...,an+2a_{n+2}, 保证 1ai1001 \le a_i \le 100.

Output

输出最少需要付出的精力

Samples

2
10 100 5 50
7500

Resources

2018 UESTC Training for Dynamic Programming