Algorithm


B. Lara Croft and the New Game
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

You might have heard about the next game in Lara Croft series coming out this year. You also might have watched its trailer. Though you definitely missed the main idea about its plot, so let me lift the veil of secrecy.

Lara is going to explore yet another dangerous dungeon. Game designers decided to use good old 2D environment. The dungeon can be represented as a rectangle matrix of n rows and m columns. Cell (x, y) is the cell in the x-th row in the y-th column. Lara can move between the neighbouring by side cells in all four directions.

Moreover, she has even chosen the path for herself to avoid all the traps. She enters the dungeon in cell (1, 1), that is top left corner of the matrix. Then she goes down all the way to cell (n, 1) — the bottom left corner. Then she starts moving in the snake fashion — all the way to the right, one cell up, then to the left to the cell in 2-nd column, one cell up. She moves until she runs out of non-visited cells. n and m given are such that she always end up in cell (1, 2).

Lara has already moved to a neighbouring cell k times. Can you determine her current position?

Input

The only line contains three integers nm and k (2 ≤ n, m ≤ 109n is always even0 ≤ k < n·m). Note that k doesn't fit into 32-bit integer type!

Output

Print the cell (the row and the column where the cell is situated) where Lara ends up after she moves k times.

Examples
input
Copy
4 3 0
output
Copy
1 1
input
Copy
4 3 11
output
Copy
1 2
input
Copy
4 3 7
output
Copy
3 2
Note

Here is her path on matrix 4 by 3:

 

Code Examples

#1 Code Example with C++ Programming

Code - C++ Programming

#include <bits/stdc++.h>

using namespace std;

int const N = 1e5 + 1;
long long t, n, m, a[N];
long long k;
char s[N];

int main() {
	cin >> n >> m >> k;

	if(k < n) {
		++k;
		cout << k << ' ' << 1 << endl;
		return 0;
	}

	if(k == n) {
		cout << n << ' ' << 2 << endl;
		return 0;
	}

	k -= n;

	long long tmp = m;
	m -= 2;

	long long can = k / (m + 1);

	long long x = n, y = 2;

	if(can % 2 == 0) {
		x -= can;
	} else {
		x -= can;
		y = tmp;
	}

	long long mod = k % (m + 1);

	if(y == 2)
		y += mod;
	else
		y -= mod;

	cout << x << ' ' << y << endl;

	return 0;
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
4 3 0

Output

x
+
cmd
1 1
Advertisements

Demonstration


Codeforces Solution-B. Lara Croft and the New Game-Solution in C, C++, Java, Python

Previous
Codeforces solution 1080-B-B. Margarite and the best present codeforces solution
Next
CodeChef solution DETSCORE - Determine the Score CodeChef solution C,C+