QOJ.ac

QOJ

总分: 100 不可用

#6075. Taxes [A]

统计

Bajtazar the merchant has arrived in Bajtogród with the intention of getting rich in the real estate market. He plans to buy a section of the city's buildings to rent out premises. However, Bajtazar's main concern is taxes...

The streets of Bajtogród form a regular grid. There are $n + 1$ streets running from west to east and $m + 1$ streets running from south to north. Based on the flat map of Bajtogród, we will call the first type of streets horizontal streets and the second type vertical streets. Each horizontal street intersects every vertical street. Thus, there are $n \cdot m$ blocks in Bajtogród, which are areas bounded on all sides by streets. The sides of each block are expressed in integer numbers of bajtometers. A block of size $k \times l$ is divided into $k \cdot l$ residential units.

One day, the mayor of Bajtogród decided to introduce a land tax. Wishing to simplify the tax calculation for residents, he decided that in each of the $n$ horizontal rows of blocks, the tax rate would be the same. More precisely, if in the $i$-th row of blocks ($1 \le i \le n$) the mayor set a tax rate of $a_{i}$, and this row has a height of $x_{i}$, then each residential unit in that row pays a tax equal to $a_{i}/ x_{i}$. If many buildings with residential units in a given row are historical, the mayor introduced a subsidy for the renovation of historical sites paid from the city budget instead of a tax. The subsidy rate was also constant for a given row of units. Thus, if a tax is in effect in a given row of blocks, we assume $a_{i} < 0$, and if a subsidy is in effect, $a_{i} \ge 0$.

Unfortunately, the mayor did not coordinate his idea with the city council, which also came up with the idea of introducing a land tax. As luck would have it, the city council decided to tax the columns of blocks, applying exactly the same principle as the mayor (with a tax rate of $b_{i}$ in a column of width $y_{i}$, each unit pays a tax of $b_{i}/y_{i}$). The city council also took historical sites into account and sometimes, instead of a tax, introduced a subsidy for their renovation.

The mayor and the city council announced their resolutions at about the same time. To avoid political disputes, the mayor and the city council reached a compromise. The tax rate for a given residential unit will be equal to the sum of the rates from the tax introduced by the mayor and the tax introduced by the city council.

Bajtazar would like to purchase all residential units located in a certain rectangular area. He can only buy entire blocks. Help him determine the area where the sum of subsidies and taxes will be as large as possible.

Input

The first line of input contains one integer $n$. The second line of input contains a sequence of $n$ integers $a_{i}$. The third line of input contains a sequence of $n$ positive integers $x_{i}$. The fourth line of input contains one integer $m$. The fifth line of input contains a sequence of $m$ integers $b_{i}$. The sixth line of input contains a sequence of $m$ positive integers $y_{i}$.

The numbers $n$ and $m$ satisfy the conditions: $1 \le n, m \le 200\,000$. The elements of the sequences $a_{i}$ and $b_{i}$ satisfy the conditions: $-10,000 \le a_{i}, b_{i} \le 10,000$. Negative values of these sequences represent the tax rate introduced by the mayor and the city council, respectively, while non-negative values represent subsidies for the renovation of historical sites. The elements of the sequences $x_{i}$ and $y_{i}$ (i.e., the heights of the rows and widths of the columns of blocks) satisfy the conditions: $1 \le x_{i}, y_{i} \le 10,000$.

Output

Your program should output a single integer - the largest sum of subsidies and taxes in a rectangular area of blocks.

Examples

Input 1

5
-3 0 1 -3 1
1 3 1 3 1
3
-3 -1 1
3 1 2

Output 1

6

Note

The numbers placed on the left side of the drawing represent the tax rates in the rows of blocks (sequence $a_i$), and the numbers below the drawing represent the rates in the columns of blocks (sequence $b_i$). The number in a unit square represents the tax rate in that block. The highlighted rectangle represents the area in which Bajtazar should invest.


或者逐个上传:

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.