#include #include #include #include using namespace std; #include "testlib.h" vector> reduce(int a, int b) { // (a, b) -> (abs(gcd(a, b)), 0) vector> ret; ret.emplace_back(a, b); while (a and b) { if (abs(a) > abs(b)) { int r = abs(a) / abs(b); if (a > 0) { a -= r * abs(b); } else { a += r * abs(b); } } else { int r = abs(b) / abs(a); if (b > 0) { b -= r * abs(a); } else { b += r * abs(a); } } ret.emplace_back(a, b); } if (a < 0) { b = abs(a); ret.emplace_back(a, b); a = 0; ret.emplace_back(a, b); } if (a == 0) { a = abs(b); ret.emplace_back(a, b); b = 0; ret.emplace_back(a, b); } return ret; } constexpr int MAXI = 100000000; int main(int argc, char *argv[]) { registerValidation(argc, argv); int a = inf.readInt(-MAXI, MAXI); inf.readSpace(); int b = inf.readInt(-MAXI, MAXI); inf.readSpace(); int c = inf.readInt(-MAXI, MAXI); inf.readSpace(); int d = inf.readInt(-MAXI, MAXI); inf.readEoln(); inf.readEof(); if (std::gcd(abs(a), abs(b)) != std::gcd(abs(c), abs(d))) { puts("-1"); return 0; } auto ab_to_i = reduce(a, b); auto cd_to_i = reduce(c, d); auto ret = ab_to_i; ret.insert(ret.end(), cd_to_i.rbegin(), cd_to_i.rend()); cout << ret.size() - 1 << '\n'; for (int i = 1; i < int(ret.size()); ++i) { auto [px, py] = ret.at(i - 1); auto [nx, ny] = ret.at(i); if (px != nx) { cout << "1 " << (nx - px) / py << '\n'; } else if (py != ny) { cout << "2 " << (ny - py) / px << '\n'; } else { cout << "1 0\n"; } } }