Cross Spiral

No attempts yetTime limit1sMemory limit128 MB

Problem

An old house has a room shaped like a cross. You can picture the cross as one large outlining rectangle with a small rectangle cut out of each of its four corners. The floor of the room is completely covered with square tiles.

Bridget walks around the room, stepping from one tile to an adjacent one, spiralling inward toward the centre. She always walks clockwise and stays as close to the edge of the room as possible without ever stepping on the same tile twice. It is possible for her to become trapped, unable to move to any adjacent tile, before she has reached every tile.

Let the upper-left corner of the outlining rectangle be position $(1, 1)$, that is, column 1 and row 1. The walk always starts at column $X$ and row 1, where $X$ is the leftmost column of row 1 that belongs to the cross; the start is therefore $(X, 1)$. The starting tile $(X, 1)$ may not be revisited during the walk, and the first step is counted when Bridget first moves to an adjacent tile.

In the figure above, the dimensions of the cross are 10 8 3 2: the outlining rectangle is 10 wide and 8 high, and each cut-out rectangle is 3 wide and 2 high.

Write a program that computes Bridget's final column and row after she has taken the given number of steps (or, if she is trapped earlier, from the tile where she is trapped).

Input

Five integers are given, one per line, in this order:

  • the width $W$ of the outlining rectangle
  • the height $H$ of the outlining rectangle
  • the width $C_w$ of each cut-out rectangle
  • the height $C_h$ of each cut-out rectangle
  • the number of steps $S$ that Bridget takes

Output

Print Bridget's final position on two lines: the column number on the first line and the row number on the second line.

Constraints

  • The width and height of the outlining rectangle are at most $20 \times 20$.
  • The minimum width of the cross is 1.
  • The vertical and horizontal parts of the cross are not necessarily the same width.