#include <bits/stdc++.h>
using namespace std;
struct Info {
int type; // 1, 2, 3
pair<int, int> from1;
pair<int, int> from2; // Only for type 3
};
struct Operation {
int type;
int x;
int y;
int w; // for type 3
int z;
};
const int MAX_VAL = 4000;
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
int a, b;
cin >> a >> b;
int c, d;
cin >> c >> d;
// Initialize structures
int size = MAX_VAL +1;
// Using 1D arrays for memory efficiency
// info[x * size + y]
vector<Info> info(size * size);
vector<bool> visited(size * size, false);
// forward[x] = list of y where (x, y) exists
vector<vector<int>> forward_(size, vector<int>());
// reverse_[y] = list of x where (x, y) exists
vector<vector<int>> reverse_(size, vector<int>());
// BFS queue
queue<pair<int, int>> q;
q.push({a, b});
visited[a * size + b] = true;
forward_[a].push_back(b);
reverse_[b].push_back(a);
bool found = false;
pair<int, int> target;
// BFS loop
while(!q.empty()){
pair<int, int> current = q.front(); q.pop();
int x = current.first;
int y = current.second;
// Machine 1
int nx = x +1;
int ny = y +1;
if(nx <= MAX_VAL && ny <= MAX_VAL){
int idx = nx * size + ny;
if(!visited[idx]){
visited[idx] = true;
info[idx].type = 1;
info[idx].from1 = {x, y};
q.push({nx, ny});
forward_[nx].push_back(ny);
reverse_[ny].push_back(nx);
if(nx == c && ny == d){
found = true;
target = {nx, ny};
break;
}
}
}
// Machine 2
if(x %2 ==0 && y %2 ==0){
int nx2 = x /2;
int ny2 = y /2;
if(nx2 >=1 && ny2 >=1){
int idx = nx2 * size + ny2;
if(!visited[idx]){
visited[idx] = true;
info[idx].type = 2;
info[idx].from1 = {x, y};
q.push({nx2, ny2});
forward_[nx2].push_back(ny2);
reverse_[ny2].push_back(nx2);
if(nx2 == c && ny2 == d){
found = true;
target = {nx2, ny2};
break;
}
}
}
}
// Machine 3: (x,y) with (y,z) to make (x,z)
for(auto &z : forward_[y]){
int nx3 = x;
int ny3 = z;
if(nx3 >=1 && ny3 >=1 && nx3 <= MAX_VAL && ny3 <= MAX_VAL){
int idx = nx3 * size + ny3;
if(!visited[idx]){
visited[idx] = true;
info[idx].type = 3;
info[idx].from1 = {x, y};
info[idx].from2 = {y, z};
q.push({nx3, ny3});
forward_[nx3].push_back(ny3);
reverse_[ny3].push_back(nx3);
if(nx3 == c && ny3 == d){
found = true;
target = {nx3, ny3};
break;
}
}
}
}
if(found) break;
// Machine 3: (w,x) with (x,y) to make (w,y)
for(auto &w : reverse_[x]){
int nx4 = w;
int ny4 = y;
if(nx4 >=1 && ny4 >=1 && nx4 <= MAX_VAL && ny4 <= MAX_VAL){
int idx = nx4 * size + ny4;
if(!visited[idx]){
visited[idx] = true;
info[idx].type = 3;
info[idx].from1 = {w, x};
info[idx].from2 = {x, y};
q.push({nx4, ny4});
forward_[nx4].push_back(ny4);
reverse_[ny4].push_back(nx4);
if(nx4 == c && ny4 == d){
found = true;
target = {nx4, ny4};
break;
}
}
}
}
if(found) break;
}
if(!found){
// It might still be that (a,b) is (c,d), but problem states they're different
// So output 0
cout << "0";
return 0;
}
// Now, reconstruct the operations by traversing from (c,d) to (a,b)
vector<Operation> operations;
// To avoid duplicate operations
vector<bool> processed(size * size, false);
// Recursive function to collect operations
// Implemented iteratively to prevent stack overflow
// Using DFS with a stack
stack<pair<int, int>> s;
s.push(target);
// To store the order in reverse
vector<Operation> temp_ops;
// To mark processed during traversal
// processed array already defined
// Implement DFS with memoization
// Use a stack and a visited flag for traversal
// To handle dependencies first
// Implement using colors: 0 = unvisited, 1 = visiting, 2 = processed
vector<int> color(size * size, 0);
// Define a lambda for DFS
function<void(int, int)> dfs = [&](int x, int y) {
int idx = x * size + y;
if (color[idx] == 2) return;
if (color[idx] ==1){
// Should not have cycles
return;
}
color[idx] =1;
Info current_info = info[idx];
if(current_info.type ==1 || current_info.type ==2){
int fx = current_info.from1.first;
int fy = current_info.from1.second;
dfs(fx, fy);
Operation op;
op.type = current_info.type;
op.x = fx;
op.y = fy;
op.w = 0;
op.z = 0;
temp_ops.push_back(op);
}
else if(current_info.type ==3){
int fx = current_info.from1.first;
int fy = current_info.from1.second;
int sx = current_info.from2.first;
int sy = current_info.from2.second;
dfs(fx, fy);
dfs(sx, sy);
Operation op;
op.type =3;
op.x = fx;
op.y = fy;
op.w = sx;
op.z = sy;
temp_ops.push_back(op);
}
color[idx] =2;
};
dfs(target.first, target.second);
// Now, temp_ops contains operations in the order they should be performed
// Reverse to get the correct order
// But since we added after dependencies, it's already correct
// So we don't need to reverse
// However, to ensure the starting operations are first, we can reverse
// to match the sample
// Let's reverse the temp_ops
reverse(temp_ops.begin(), temp_ops.end());
// Now, print the operations
// Ensure k does not exceed 15000
if(temp_ops.size() > 15000){
cout << "0";
return 0;
}
cout << temp_ops.size() << "\n";
for(auto &op: temp_ops){
if(op.type ==1){
cout << "1 " << op.x << " " << op.y << "\n";
}
else if(op.type ==2){
cout << "2 " << op.x << " " << op.y << "\n";
}
else if(op.type ==3){
cout << "3 " << op.x << " " << op.y << " " << op.w << " " << op.z << "\n";
}
}
}