3MLE 3WA
#include <bits/stdc++.h>
using namespace std;
constexpr int MAXN = 4.1e6 + 5;
int a[MAXN];
int b[MAXN][4];
int st;
int dis[MAXN], pre[MAXN];
int op[MAXN];
int get(int x, int id) {
return (x >> (id << 1)) & 3;
}
int calc(int x, int id, int v) {
return x ^ ((1ll * (v & 3)) << (id << 1));
}
double h(int x) {
double res = 0;
for (int i = 0; i < 12; i++) {
res += ((4 - get(x, i)) & 3) / 2.0;
}
return res;
}
void Ax() {
// cerr << h(st) << endl;
memset(pre, 0xff, sizeof pre);
priority_queue<pair<double, int>, vector<pair<double, int>>, greater<pair<double, int>>> q;
q.push(make_pair(h(st) + dis[st], st));
while (q.size()) {
auto [f, x] = q.top();
// cerr << f << " " << x << endl;
q.pop();
if (!x)
return;
for (int i = 0; i < 12; i++) {
int now = get(x, i);
int j = b[i][now];
int then = get(x, j);
int res = x;
res = calc(res, i, now);
res = calc(res, i, now + 1);
res = calc(res, j, then);
res = calc(res, j, then + 1);
if (!(~pre[res])) {
op[res] = i + 1;
dis[res] = dis[x] + 1;
pre[res] = x;
q.push(make_pair(h(res) + dis[res], res));
}
}
}
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
for (int i = 0; i < 12; i++) {
cin >> a[i];
a[i]--;
st |= (a[i] << (i << 1));
for (int j = 0; j < 4; j++) {
cin >> b[i][j];
b[i][j]--;
}
}
Ax();
cout << dis[0] << endl;
vector<int> st;
for (int i = 0; ~i; i = pre[i]) {
if (op[i] != 0)
st.push_back(op[i]);
// cerr << i << endl;
}
while (st.size()) {
cout << st.back() << " ";
st.pop_back();
}
cout << endl;
return 0;
}