This page is still under construction.

Parts of this page are still being built. What you see may change.

Math Notebook

Interview

Time limit1sMemory limit128 MB

Summary
Choose a contiguous block from both sequences to maximize its dot product with the reversed second block.
Level

Medium5 of 10

Topics
Brute force, Array
Solved
No attempts yet

Problem

You are given two integer sequences, each of length NN. Their blurriness is computed as follows: reverse the second sequence, multiply the two numbers that now share the same position, and add up all of those products.

3-4-3-220
-305-132

For example, the blurriness of the two sequences above is 3×2+(−4)×3+(−3)×(−1)+(−2)×5+2×0+0×(−3)=−133 \times 2 + (-4) \times 3 + (-3) \times (-1) + (-2) \times 5 + 2 \times 0 + 0 \times (-3) = -13.

You may delete BB columns from the front and EE columns from the back to make the blurriness as large as possible. BB and EE may be 00, and deleting a column removes the same position from both sequences at once. At least one column must remain, so B+E<NB + E < N.

Find BB and EE that maximize the blurriness, together with that maximum blurriness.

Input

The first line contains the length of the sequences NN (1≤N≤2000)(1 \le N \le 2000).

Each of the next two lines contains one sequence of space-separated integers. Every number is between −1000-1000 and 10001000 inclusive.

Output

On the first line, print BB and EE that maximize the blurriness, separated by a space (0≤B, 0≤E, B+E<N)(0 \le B,\ 0 \le E,\ B + E < N).

If several pairs (B,E)(B, E) reach the maximum, print the one with the smallest BB; if there is still a tie, print the one with the smallest EE.

On the second line, print the maximum blurriness.

Examples3

  1. Example 1

    Input
    6
    3 -4 -3 -2 2 0
    -3 0 5 -1 3 2
    
    Expected output
    0 3
    24
    
  2. Example 2

    Input
    5
    1 1 1 1 1
    2 2 2 2 2
    
    Expected output
    0 0
    10
    
  3. Example 3

    Input
    5
    5 -5 -5 -5 5
    -5 -5 5 -5 -5
    
    Expected output
    0 2
    75