PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#GL0000322. Số bước bóng nảy (Bouncing Ball Steps)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Số bước bóng nảy (Bouncing Ball Steps)

Bouncing Ball Steps

Source: CSES

Version: Phuoc Hung OJ Extended

Problem Statement

You are given an n×mn\times m grid indexed from 11. A ball starts in the top-left cell (1,1)(1,1) and initially moves diagonally down and right. Every step moves it by one row and one column in its current direction. On reaching a top/bottom border the vertical component reverses, and on reaching a left/right border the horizontal component reverses. At a corner both components may reverse simultaneously.

After exactly kk steps, determine the ball's position and the number of times it has changed direction. Simultaneous reversals at a corner count as one direction change. A collision occurring at the end of step kk is included.

Input

One line contains n,m,kn,m,k: the number of rows, the number of columns, and the number of steps.

Output

Print three space-separated integers r,c,dr,c,d: the row and column after kk steps, and the number of direction changes.

Subtasks

  • Subtask 1 (20 points): 2≤n,m≤102\le n,m\le10; 0≤k≤500\le k\le50.
  • Subtask 2 (30 points): 2≤n,m≤1052\le n,m\le10^5; 0≤k≤1060\le k\le10^6.
  • Subtask 3 (50 points): 2≤n,m≤1092\le n,m\le10^9; 0≤k≤10180\le k\le10^{18}.

Examples

Example 1

Input

3 4 0

Output

1 1 0

Explanation

No steps have been taken; the ball remains at (1,1)(1,1) with no direction changes.

Example 2

Input

3 4 3

Output

2 4 2

Explanation

Step 1 reaches (2,2)(2,2). Step 2 reaches (3,3)(3,3) and reverses vertically (first change). Step 3 reaches (2,4)(2,4) and reverses horizontally (second change).