#include <iostream>
using namespace std;
void solve(int x, int Vx, int y, int Vy, int z) {
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;
}
cout << x << " " << y << endl;
if (x != z && y != z)
solve(x, Vx, y, Vy, z);
}
int main() {
solve(0, 5, 0, 7, 4);
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKdm9pZCBzb2x2ZShpbnQgeCwgaW50IFZ4LCBpbnQgeSwgaW50IFZ5LCBpbnQgeikgewoJaWYgKHkgPT0gMCkKCQl5ID0gVnk7CgllbHNlIGlmICh4ID09IFZ4KQoJCXggPSAwOwoJZWxzZSBpZiAoeSA+IDAgJiYgeCA8IFZ4KSB7CgkJaW50IGsgPSBtaW4oeSwgVnggLSB4KTsKCQl4ID0geCArIGs7CgkJeSA9IHkgLSBrOwoJfQoJCgljb3V0IDw8IHggPDwgIiAiIDw8IHkgPDwgZW5kbDsKCWlmICh4ICE9IHogJiYgeSAhPSB6KQoJCXNvbHZlKHgsIFZ4LCB5LCBWeSwgeik7Cn0KCgppbnQgbWFpbigpIHsKCQoJc29sdmUoMCwgNSwgMCwgNywgNCk7CglyZXR1cm4gMDsKfQ==