cho.sh
Notes
Loading...

Tug of War

Time limit

1s

Memory limit

128 MB

Problem

Residents of villages A and B will play tug of war. The people from each village are already standing in one line, called line A and line B. Each line must be cut into three consecutive nonempty unit lines: A1, A2, A3 and B1, B2, B3. The matches are A1 against B1, A2 against B2, and A3 against B3.

The weight of a unit line is the sum of the weights of the people in it. The original order inside each line cannot be changed. For every paired match, the absolute difference between the two unit-line weights must be at most 50.

The tug-of-war value of a segmentation is the largest of the three paired weight differences. Find a valid segmentation whose tug-of-war value is as small as possible.

Input

The first line contains two integers N and M, the numbers of people in lines A and B.

The second line contains N integers, the weights of the people in line A in order. The third line contains M integers, the weights of the people in line B in order.

N and M are integers between 3 and 30,000 inclusive. Each weight is an integer between 20 and 100 inclusive.

Output

If no valid segmentation exists, print -1 on the first line.

Otherwise, print two lines. The first line must contain the numbers of people in A1, A2, and A3, in order. The second line must contain the numbers of people in B1, B2, and B3, in order.

If there is more than one segmentation with the minimum tug-of-war value, print any one of them.