Under construction

Still being built. Things may change

Luigi's Calculations

Interview

Time limit1sMemory limit1024 MB

Summary
Given tire range [A, B], rim range [C, D], and divisor k, find x and y with x + y divisible by k and the largest possible sum, or report -1.
Level

Easy3 of 10

Topics
Math, Greedy
Solved
No attempts yet

Problem

Luigi is good at choosing tires. Recently he asked Guido to run calculations that find the best combination of three factors: the road, the tires, and the rims.

In Luigi's calculations, the road is described by the number kk, the frequency of micro-bumps. The tires and rims are described by the numbers xx and yy, their toughness coefficients on Luigi's personal scale. Guido found through experiments that a combination is valid only if x+y≡0mod  kx + y \equiv 0 \mod k. In other words, the sum of the tire and rim coefficients must be divisible by the frequency of micro-bumps.

Luigi always works at full capacity and wants the toughest tires from his store's stock. The store sells tires with any toughness coefficient from AA to BB, and rims with any coefficient from CC to DD. If several valid options exist for a given road, Luigi picks any option whose coefficient sum is maximal.

Write a program that takes AA, BB, CC, DD, and kk and determines which tires and which rims Luigi should sell.

Input

The only line contains five natural numbers A,B,C,D,kA, B, C, D, k (1≤A,B,C,D,k≤1091 \le A, B, C, D, k \le 10^9), the limits of the assortment and the frequency of micro-bumps on the road.

Output

Print one line with two numbers xx and yy (A≤x≤BA \le x \le B, C≤y≤DC \le y \le D), the answer to the problem. If no answer exists, print -1.

Examples3

  1. Example 1

    Input
    1 10 1 7 3
    
    Expected output
    9 6
    
  2. Example 2

    Input
    1 2 2 3 7
    
    Expected output
    -1
    
  3. Example 3

    Input
    1 4 2 3 2
    
    Expected output
    4 2