#include <bits/stdc++.h>
using namespace std;
struct OperationInfo {
int type; // 1, 2, 3
int parent1; // for op1, op2: only parent1 is used
int parent2; // for op3: the second parent
};
struct Card {
int x;
int y;
OperationInfo op_info;
};
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
int a, b;
cin >> a >> b;
int c, d;
cin >> c >> d;
// Check direction consistency
if(a < b){
if(!(c < d)){
cout << "0";
return 0;
}
}
else if(a > b){
if(!(c > d)){
cout << "0";
return 0;
}
}
else { // a == b
if(!(c == d)){
cout << "0";
return 0;
}
}
// Edge case: initial and final cards are different as per problem statement
// So no need to handle a == c and b == d
// Initialize BFS structures
// Since x and y are up to 2000, use 2001 indices
// visited[x][y] = true if (x;y) has been visited
vector<vector<bool>> visited(2001, vector<bool>(2001, false));
// Initialize card list
vector<Card> cards;
cards.push_back(Card{a, b, OperationInfo{0, -1, -1}}); // index 0
// Mark visited
if(a >=1 && a <=2000 && b >=1 && b <=2000)
visited[a][b] = true;
else{
// Initial card out of bounds
cout << "0";
return 0;
}
// Mapping from a to list of card indices with that a
vector<vector<int>> map_a(2001, vector<int>());
map_a[a].push_back(0);
// Queue for BFS
queue<int> q;
q.push(0);
// Variable to store the index of (c; d) if found
int target_index = -1;
while(!q.empty()){
int current = q.front();
q.pop();
Card curr_card = cards[current];
int x = curr_card.x;
int y = curr_card.y;
// Operation 1: (x+1; y+1)
int new_x1 = x + 1;
int new_y1 = y + 1;
if(new_x1 <=2000 && new_y1 <=2000){
if(!visited[new_x1][new_y1]){
visited[new_x1][new_y1] = true;
cards.push_back(Card{new_x1, new_y1, OperationInfo{1, current, -1}});
int new_index = cards.size()-1;
map_a[new_x1].push_back(new_index);
q.push(new_index);
if(new_x1 == c && new_y1 == d){
target_index = new_index;
break;
}
}
}
// Operation 2: (x/2; y/2) if both even
if(x %2 ==0 && y %2 ==0){
int new_x2 = x /2;
int new_y2 = y /2;
if(new_x2 >=1 && new_y2 >=1){
if(!visited[new_x2][new_y2]){
visited[new_x2][new_y2] = true;
cards.push_back(Card{new_x2, new_y2, OperationInfo{2, current, -1}});
int new_index = cards.size()-1;
map_a[new_x2].push_back(new_index);
q.push(new_index);
if(new_x2 == c && new_y2 == d){
target_index = new_index;
break;
}
}
}
}
// Operation 3: for current card (x; y), combine with all (y; z) to make (x; z)
if(y >=1 && y <=2000){
for(auto &z_idx : map_a[y]){
Card z_card = cards[z_idx];
int z = z_card.y;
if(z >=1 && z <=2000){
// Generate (x; z)
if(!visited[x][z]){
visited[x][z] = true;
cards.push_back(Card{x, z, OperationInfo{3, current, z_idx}});
int new_index = cards.size()-1;
map_a[x].push_back(new_index);
q.push(new_index);
if(x == c && z == d){
target_index = new_index;
break;
}
}
}
}
if(target_index != -1) break;
}
}
if(target_index == -1){
cout << "0";
return 0;
}
// Now backtrack to get the operations
vector<string> operations_list;
vector<bool> processed(cards.size(), false);
// Recursive backtrack using lambda to avoid stack overflow
// Implemented iteratively using stack
int n = cards.size();
// To store the sequence in reverse
vector<string> temp_ops;
// Use DFS with stack
// Each element in stack: (current_index, state)
// state 0: first time, need to process children
// state 1: children processed, add operation
stack<pair<int, int>> stk;
stk.emplace(target_index, 0);
while(!stk.empty()){
auto &[idx, state] = stk.top();
stk.pop();
if(processed[idx]) continue;
if(state == 0){
// Push back with state 1 to add operation after children
stk.emplace(idx, 1);
// Push children
if(cards[idx].op_info.type ==1 || cards[idx].op_info.type ==2){
int parent = cards[idx].op_info.parent1;
if(parent != -1){
stk.emplace(parent, 0);
}
}
else if(cards[idx].op_info.type ==3){
int parent1 = cards[idx].op_info.parent1;
int parent2 = cards[idx].op_info.parent2;
if(parent2 != -1){
stk.emplace(parent2, 0);
}
if(parent1 != -1){
stk.emplace(parent1, 0);
}
}
}
else if(state ==1){
// Add the operation
if(cards[idx].op_info.type ==1){
// Operation 1: "1 x y"
int parent = cards[idx].op_info.parent1;
string op_str = "1 " + to_string(cards[parent].x) + " " + to_string(cards[parent].y);
temp_ops.push_back(op_str);
}
else if(cards[idx].op_info.type ==2){
// Operation 2: "2 x y"
int parent = cards[idx].op_info.parent1;
string op_str = "2 " + to_string(cards[parent].x) + " " + to_string(cards[parent].y);
temp_ops.push_back(op_str);
}
else if(cards[idx].op_info.type ==3){
// Operation 3: "3 x1 y1 x2 y2"
int parent1 = cards[idx].op_info.parent1;
int parent2 = cards[idx].op_info.parent2;
string op_str = "3 " + to_string(cards[parent1].x) + " " + to_string(cards[parent1].y) + " " + to_string(cards[parent2].x) + " " + to_string(cards[parent2].y);
temp_ops.push_back(op_str);
}
processed[idx] = true;
}
}
// Reverse the operations to get the correct order
reverse(temp_ops.begin(), temp_ops.end());
// Check if operations count exceeds 15000
if(temp_ops.size() > 15000){
cout << "0";
return 0;
}
// Output
cout << temp_ops.size() << "\n";
for(auto &s: temp_ops){
cout << s << "\n";
}
}