#include <iostream>
using namespace std;
void solve(int x, int Vx, int y, int Vy, int z) {
cout << x << " " << y << endl;
if (x == z || y == z)
return;
if (y == 0)
y = Vy;
else if (x == Vx)
x = 0;
else if (y > 0 && x < Vx) {
int k = min(y, Vx - x);
x = x + k;
y = y - k;
}
solve(x, Vx, y, Vy, z);
}
int main() {
solve(0, 5, 0, 7, 4);
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKdm9pZCBzb2x2ZShpbnQgeCwgaW50IFZ4LCBpbnQgeSwgaW50IFZ5LCBpbnQgeikgewoJY291dCA8PCB4IDw8ICIgIiA8PCB5IDw8IGVuZGw7CglpZiAoeCA9PSB6IHx8IHkgPT0geikKCQlyZXR1cm47CgkJCglpZiAoeSA9PSAwKQoJCXkgPSBWeTsKCWVsc2UgaWYgKHggPT0gVngpCgkJeCA9IDA7CgllbHNlIGlmICh5ID4gMCAmJiB4IDwgVngpIHsKCQlpbnQgayA9IG1pbih5LCBWeCAtIHgpOwoJCXggPSB4ICsgazsKCQl5ID0geSAtIGs7Cgl9CgkKCXNvbHZlKHgsIFZ4LCB5LCBWeSwgeik7Cn0KCgppbnQgbWFpbigpIHsKCQoJc29sdmUoMCwgNSwgMCwgNywgNCk7CglyZXR1cm4gMDsKfQ==