DCD - DCD

Once upon a time, there was a secret group of boys. People used to call them 'Dushtu Cheler Dol' (Gang of Naughty boys) or DCD in short. Members of DCD were very good at making fool of people.

Suppose, you are a member of DCD and you want to borrow money from N people (you are definitely not going to return the money because that will go against the values of DCD). Some of  the N people will not lend you money as they know about DCD. But at first you don't know how many of them know about it. Then there are M members of DCD who want to borrow money from you. As you know none of the M people will return your money, you will try to escape from them when they will ask you for money, but you are not sure of being able to escape. Failure of escaping means, you must give them the money they want. So, before starting you wanted to determined how much money you will have after the whole process. As many solutions are possible, you will determine an interval, which contains the maximum number of possible solutions. The difference between the starting point and ending point will be of definite size (given in the input).

Input

Test cases start with two integers N and M. Next, there will be N integers in the same or different lines where [0 <= Ni <= 1015] is the amount of money you will borrow from the ith person. Then there will be M integers in the same or different lines, where [0 <= Mi <= 1015] is the amount of money ith DCD member will ask for. (N + M) <= 17. Then you will be given an integer D [1 <= D <= 1015], the difference between the starting point and ending point of the desired interval.

There will be at most 200 test cases.

Output

For each test case, you have to print three integers S, T and E. S and T are the endpoints of an interval of difference D, (S <= T). E is the number of solutions between S and T (inclusive).

If there are several solutions, print the interval where S itself is a possible solution. If still there are several solutions, print the interval having minimum value of S.

Note:

  1. Same money values achieved by different ways are considered different.
  2. If you can't escape, you will have to pay money even if you have zero or less money left. Then your amount will be considered negative.
  3. If the starting value of the interval is X, the ending value will be X + D - 1.

Example

Input:
2 0
1 2
1
4 1
5 6 9 9
2
5

Output:
0 0 1
11 15 9

Added by:Bidhan
Date:2011-08-06
Time limit:1s-6.864s
Source limit:20000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64
Resource:Own, Alternate Writer: Hasnain Heickal Jami

hide comments
2013-05-04 18:42:00 rav
how you get number of test case??
I am having tle much before 35s.

Last edit: 2013-05-04 18:44:04
2011-08-08 05:26:40 Bidhan
Kindly let me know if something needs to be clarified.
2011-08-08 05:26:40 যোবায়ের
" you've borrowed money from n people " and " Some of the n people will not lend you money " -- isn't that contradictory ?

reply : Yeah, updated :)

Last edit: 2011-08-07 12:49:55
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.