QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 128 MB Total points: 10

#6070. Panorama of Bajhattan [B]

Statistics

Bajtłomiej is about to take his first trip across the ocean to the United States of Byteland. He really wants to see Bajhattan, a district in one of the massive cities there. Bajhattan is full of tall skyscrapers. It is famous for its skyline, which is the view of the buildings from a distance.

Bajhattan consists of $n \times m$ blocks. Each block is either empty or occupied by exactly one skyscraper of a certain height. For simplicity, empty blocks are identified with blocks occupied by skyscrapers of height $0$. We also ignore the streets between the blocks. For example, for $n = 3$, $m = 4$, and skyscraper heights as in the grid below (bird's-eye view, north at the top):

1 2 0 3
1 0 1 2
2 1 0 1

Bajhattan looks like the drawing below:

Bajtłomiej has only seen Bajhattan in pictures. The most famous ones are the two skylines: the western and the southern. In the example, the western skyline features skyscrapers of heights 3, 2, and 2, and the southern skyline features skyscrapers of heights 2, 2, 1, and 3. The photos were taken from quite far away, so only the outlines of the buildings are visible.

For the skyscraper layout from the example, the western skyline looks as follows:

And here is the southern skyline:

Bajtłomiej would like to determine the sizes of the skyscrapers in Bajhattan based on the photos. He wants to estimate their volume (total capacity).

Help him and determine the maximum possible total volume of all skyscrapers in Bajhattan. In the example, the volume of all skyscrapers is 14, but if their layout were slightly different (while keeping the same skylines), the volume could be as high as 22.

Input

The first line of input contains two integers $n$ and $m$ ($1 \le n, m \le 1\,000\,000$). The next line contains $n$ integers $z_{i}$ ($1 \le i \le n$), representing the heights of the skyscrapers in the western skyline, starting from the northernmost skyscraper. The third line contains $m$ integers $p_{j}$ ($1 \le j \le m$), representing the heights of the skyscrapers in the southern skyline, starting from the westernmost skyscraper. You may assume that $0 \le z_{i}, p_{j} \le 1\,000\,000$.

Output

Your program should output the maximum possible total volume of Bajhattan. If Bajtłomiej made a mistake (for example, by taking one skyline of Bajhattan and one of San Bytelisco, which he also visits) and the photos cannot represent the same city, output the single word NIE.

Examples

Input 1

3 4
3 2 2
2 2 1 3

Output 1

22

Input 2

3 3
0 0 0
2 2 2

Output 2

NIE

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.