Under construction

Still being built. Things may change

Ant

Interview

Time limit0.15sMemory limit256 MB

Summary
Compute the position of an ant moving diagonally and reflecting off the walls of a w by h box after t hours.
Level

Easy3 of 10

Topics
Math
Solved
No attempts yet

Problem

A rectangular grid area is ww wide and hh tall. Its lower left corner is (0,0)(0, 0) and its upper right corner is (w,h)(w, h). One ant sits at the point (p,q)(p, q) inside this area.

The ant starts moving at a constant speed in the up-right 45 degree direction. After one hour the ant that started at (p,q)(p, q) has moved to (p+1,q+1)(p+1, q+1). When it hits a boundary while moving at that speed, it reflects and keeps the same speed.

The picture above shows the path of an ant that starts at (4,1)(4, 1) on a 6×46 \times 4 grid. That ant is at (6,3)(6, 3) after 2 hours and at (0,1)(0, 1) after 8 hours. If the ant had started at (5,3)(5, 3) on the same grid, it would move to (6,4)(6, 4), (5,3)(5, 3), (4,2)(4, 2), (3,1)(3, 1) hour by hour.

Compute and print the position (x,y)(x, y) of the ant tt hours after it starts at (p,q)(p, q) on a grid of size w×hw \times h. Assume the ant never tires and keeps the same speed.

ww and hh are natural numbers with 2≤w,h≤400002 \le w, h \le 40000. The starting coordinates pp and qq are natural numbers with 0<p<w0 < p < w and 0<q<h0 < q < h. The time tt satisfies 1≤t≤2000000001 \le t \le 200000000.

Input

The first line contains ww and hh separated by a space. The second line contains the starting coordinates pp and qq separated by a space. The third line contains the time tt the ant moves.

Output

Print xx and yy of the ant position (x,y)(x, y) after tt hours, separated by a space, on one line.

Examples5

  1. Example 1

    Input
    6 4
    4 1
    8
    
    Expected output
    0 1
    
  2. Example 2

    Input
    6 4
    5 3
    4
    
    Expected output
    3 1
    
  3. Example 3

    Input
    6 4
    4 1
    2
    
    Expected output
    6 3
    
  4. Example 4

    Input
    2 2
    1 1
    1
    
    Expected output
    2 2
    
  5. Example 5

    Input
    5 7
    4 6
    1
    
    Expected output
    5 7