You are given four integers a, b, x and y. Initially, a ≥ x and b ≥ y. You can do the…
- User
You are given four integers a, b, x and y. Initially, a ≥ x and b ≥ y. You can do the following operation no more than n times:
- Choose either a or b and decrease it by one. However, as a result of this operation, value of a cannot become less than x, and value of b cannot become less than y.
Your task is to find the minimum possible product of a and b (a ⋅ b) you can achieve by applying the given operation no more than n times.
You have to answer t independent test cases. Input
The first line of the input contains one integer t (1 ≤ t ≤ 2 ⋅ 10^4) — the number of test cases. Then t test cases follow.
The only line of the test case contains five integers a, b, x, y and n (1 ≤ a, b, x, y, n ≤ 10^9). Additional constraint on the input: a ≥ x and b ≥ y always holds.
Output
For each test case, print one integer: the minimum possible product of a and b (a ⋅ b) you can achieve by applying the given operation no more than n times.
Example
Input
7 10 10 8 5 3 12 8 8 7 2 12343 43 4543 39 123212 1000000000 1000000000 1 1 1 1000000000 1000000000 1 1 1000000000 10 11 2 1 5 10 11 9 1 10
Output
70 77 177177 999999999000000000 999999999 55 10
Note
In the first test case of the example, you need to decrease b three times and obtain 10 ⋅ 7 = 70.
In the second test case of the example, you need to decrease a one time, b one time and obtain 11 ⋅ 7 = 77.
In the sixth test case of the example, you need to decrease a five times and obtain 5 ⋅ 11 = 55.
In the seventh test case of the example, you need to decrease b ten times and obtain 10 ⋅ 1 = 10.
Assistant
def main(): import sys input = sys.stdin.read().split() t = int(input[0]) idx = 1 for _ in range(t): a = int(input[idx]) b = int(input[idx+1]) x = int(input[idx+2]) y = int(input[idx+3]) n = int(input[idx+4]) idx +=5 # Calculate first scenario: reduce a first da = min(n, a - x) new_a1 = a - da rem = n - da db1 = min(rem, b - y) new_b1 = b - db1 product1 = new_a1 * new_b1 # Calculate second scenario: reduce b first db = min(n, b - y) new_b2 = b - db rem = n - db da2 = min(rem, a - x) new_a2 = a - da2 product2 = new_a2 * new_b2 print(min(product1, product2)) if __name__ == "__main__": main()
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.