#P6203. [USACO07CHN] The Bovine Accordion and Banjo Orchestra G

[USACO07CHN] The Bovine Accordion and Banjo Orchestra G

Problem Description

FJ’s 2N2N cows (3N10003 \leq N \leq 1000) are preparing to hold a concert. Among them, NN cows are accordion players, and the other NN cows are banjo players. Each accordion player has a talent index AiA_i (0Ai10000 \leq A_i \leq 1000), and each banjo player also has a talent index BiB_i (0Bi10000 \leq B_i \leq 1000).

FJ needs to pair accordion players with banjo players. Pairing the ii-th accordion player with the jj-th banjo player produces a profit of Ai×BjA_i \times B_j.

Unfortunately, FJ’s cows have a strange quirk: if the ii-th accordion player is paired with the jj-th banjo player, then accordion players i+1Ni+1 \sim N will not choose to pair with banjo players 1j11 \sim j-1. This causes a lot of trouble for FJ’s pairing plan.

Even worse, those disappointed cows who lose the chance to perform will, in order to ease their sadness, go to the bar in groups to drink.

If accordion players numbered xx to yy are all disappointed (accordion player x1x-1 and accordion player y+1y+1 do not exist or have participated in the performance), then these cows will go to the bar together, with a cost of:

(k=xyAk)2(\sum_{k=x}^y A_k)^2

Banjo players follow a similar rule.

Now FJ has to carefully consider his plan. He wants you to compute his maximum profit.

Input Format

The first line contains an integer NN.

The next NN lines each contain one integer AiA_i.

The next NN lines each contain one integer BiB_i.

Output Format

Output the maximum profit FJ can obtain.

3
1
1
5
5
1
1
17

Hint

Pair accordion player 33 with banjo player 11, and the profit is 2525.

Accordion players 1,21, 2 drink together, and the cost is 44.

Banjo players 2,32, 3 drink together, and the cost is 44.

The final profit is 1717.

Translated by ChatGPT 5