#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
struct P{
ll x1,y1,x2,y2;
P(ll X1, ll Y1, ll X2 ,ll Y2) : x1(X1),y1(Y1),x2(X2),y2(Y2) {}
};
ll Dist(ll x1, ll y1, ll x2 , ll y2){
return abs(x1-x2)+abs(y1-y2);
}
vector<P> adj;
vector<int> v;
vector<int> used;
int sx,sy,ex,ey;
ll ans = 1e15;
void go(int idx){
if (idx == 7){
int nx = sx;
int ny = sy;
ll cur_d = 0;
for (int i=0;i < v.size(); i++){
cur_d += Dist(nx,ny,adj[v[i]].x1,adj[v[i]].y1);
if (adj[v[i]].x2 == ex && adj[v[i]].y2 == ey) break;
cur_d += 10;
nx = adj[v[i]].x2;
ny = adj[v[i]].y2;
}
if (ans > cur_d) ans = cur_d;
return;
}
for (int i = 0; i < 7; i++){
if (used[i]) continue;
used[i] = 1;
v.push_back(i);
go(idx+1);
used[i] = 0;
v.pop_back();
}
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
used = vector<int>(7);
cin >> sx >> sy >> ex >> ey;
for (int i = 0; i < 3; i++){
ll x1,y1,x2,y2;
cin >> x1 >> y1 >> x2 >> y2;
adj.push_back(P(x1,y1,x2,y2));
adj.push_back(P(x2,y2,x1,y1));
}
adj.push_back(P(ex,ey,ex,ey));
go(0);
cout << ans <<"\n";
return 0;
}