#P1846. 游戏

游戏

Description

Given two sequences of positive integers, you will play a game with them: you need to perform several operations. In each operation, choose two positive integers k1k_1 and k2k_2, remove the last k1k_1 numbers of the first sequence and compute their sum s1s_1; remove the last k2k_2 numbers of the second sequence and compute their sum s2s_2. The score of this operation is (s2k2)×(s1k1)(s_2-k_2)\times(s_1-k_1). Both sequences must become empty at the same time; it is not allowed for one sequence to be empty while the other still contains numbers. The total score of the game is the sum of the scores of all operations.

Find the minimum possible total score.

Input Format

The first line contains two integers nn and mm, the initial lengths of the first and second sequences, respectively.

The second line contains nn positive integers, the numbers of the first sequence.

The third line contains mm positive integers, the numbers of the second sequence.

All numbers in the sequences are at most 10001000.

Output Format

Output a single integer, the minimum total score.

3 2
1 2 3 
1 2 
2

Hint

  • For 20%20\% of the testdata, n,m20n, m \le 20.
  • For 40%40\% of the testdata, n,m200n, m \le 200.
  • For 100%100\% of the testdata, n,m2000n, m \le 2000.

Translated by ChatGPT 5