cswork / OAOpen practice workspace

IxlOA #4

Prison Break

Estimated EasyJudge-ready

Topics (AI-labelled)In-place Arrays

Find the longest consecutive run of removed horizontal bars and of removed vertical bars separately; the side length of the largest hole is the length of the consecutive run plus 1.

Input

The first line contains n, m, |h|, |v|; the second line gives the indices of the removed horizontal bars, and the third line gives the indices of the removed vertical bars. 1≤n,m≤100000; the arrays are non-empty and the indices lie within 1..n/m respectively; each bar appears at most once.

Output

Output the area of the largest hole (64-bit integer).

Example 1

Input:

6 6 3 2
1 2 4
2 3

Output:

9

Example notes

Derive a linear-scan/dynamic-programming solution directly from the problem rules; the examples have been checked case by case against an independently built oracle.

Editorial

Loading solution…