#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define repd(i,a,b) for (int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p) {
    if(p) cout << fixed << setprecision(p)  << a << "\n";
    else cout << a << "\n";
}
// end of template
struct point {int x, y, z;};

pair<point, point> rot(int axis, int dir, point s, point g, int N){
    point rs = s, rg = g;
    if (axis == 0) {
        if (dir == 0) {
            rs.y = N - 1 - s.z;
            rs.z = s.y;
            if (s.x == g.x) {
                rg.y = N - 1 - g.z;
                rg.z = g.y;
            }
        }
        if (dir == 1) {
            rs.y = s.z;
            rs.z = N - 1 - s.y;
            if (s.x == g.x) {
                rg.y = g.z;
                rg.z = N - 1 - g.y;
            }
        }
    }
    if (axis == 1) {
        if (dir == 0) {
            rs.z = N - 1 - s.x;
            rs.x = s.z;
            if (s.y == g.y) {
                rg.z = N - 1 - g.x;
                rg.x = g.z;
            }
        }
        if (dir == 1) {
            rs.z = s.x;
            rs.x = N - 1 - s.z;
            if (s.y == g.y) {
                rg.z = g.x;
                rg.x = N - 1 - g.z;
            }
        }
    }
    if (axis == 2) {
        if (dir == 0) {
            rs.x = N - 1 - s.y;
            rs.y = s.x;
            if (s.z == g.z) {
                rg.x = N - 1 - g.y;
                rg.y = g.x;
            }
        }
        if (dir == 1) {
            rs.x = s.y;
            rs.y = N - 1 - s.x;
            if (s.z == g.z) {
                rg.x = g.y;
                rg.y = N - 1 - g.x;
            }
        }
    }
    
    return mp(rs, rg);
}

int d(point s, point g){
    return abs(s.x - g.x) + abs(s.y - g.y) + abs(s.z - g.z);
}

int dx[3] = {0, 1, -1};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    int N;
    cin >> N;
    point s,g;
    cin >> s.x >> s.y >> s.z;
    cin >> g.x >> g.y >> g.z;
    
    vector<pair<pair<point, point>, int>> dist, tmp;
    rep(i, 3){
        rep(j, 3){
            rep(k, 3){
                dist.pb(mp(mp(point{s.x + dx[i] , s.y + dx[j], s.z + dx[k]}, g), abs(dx[i]) + abs(dx[j]) + abs(dx[k])));
            }
        }
    }
    
    
    rep(a, 3){
        rep(i, dist.size()){
            rep(j, 3){
                rep(k, 2){
                    tmp.pb(mp(rot(j, k, dist[i].first.first, dist[i].first.second, N), dist[i].second + 1));
                }
            }
            tmp.pb(dist[i]);
        }
        dist = tmp;
        tmp.resize(0);
    }
    
    int ret = inf;
    rep(i, dist.size()){
        ret = min(ret, dist[i].second + d(dist[i].first.first, dist[i].first.second));
    }
    output(ret, 0);
    return 0;
}
### Prompt

In cpp, your task is to solve the following problem:

Problem

You've come to an n x n x n cubic Rubik's Cube dungeon.
You are currently in the room (x1, y1, z1).
The target treasure is in the room (x2, y2, z2).
You can move to adjacent rooms in front, back, left, right, up and down in unit time.

<image>


Each room has 6 buttons, and by pressing each button, you can perform the following operations like a Rubik's cube in a unit time:


* All rooms with the same x-coordinate value as the current room can be rotated 90 degrees clockwise or counterclockwise.

<image>


* All rooms with the same y-coordinate value as the current room can be rotated 90 degrees clockwise or counterclockwise.

<image>


* All rooms with the same z-coordinate value as the current room can be rotated 90 degrees clockwise or counterclockwise.

<image>


You cannot move to another room while rotating.
Find the time to move to the room with the treasure in the shortest time.

Constraints

* 2 ≤ n ≤ 105
* 0 ≤ x1, y1, z1, x2, y2, z2 ≤ n−1
* (x1, y1, z1) ≠ (x2, y2, z2)

Input


n
x1 y1 z1
x2 y2 z2


All inputs are given as integers.
N is given on the first line.
The coordinates of the current location (x1, y1, z1) are given on the second line, and the coordinates of the room with the treasure (x2, y2, z2) are given on the third line, separated by spaces.

Output

Output the shortest time.

Examples

Input

3
0 0 0
1 2 2


Output

3


Input

3
0 0 0
0 0 2


Output

2

### Response

```cpp
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define repd(i,a,b) for (int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p) {
    if(p) cout << fixed << setprecision(p)  << a << "\n";
    else cout << a << "\n";
}
// end of template
struct point {int x, y, z;};

pair<point, point> rot(int axis, int dir, point s, point g, int N){
    point rs = s, rg = g;
    if (axis == 0) {
        if (dir == 0) {
            rs.y = N - 1 - s.z;
            rs.z = s.y;
            if (s.x == g.x) {
                rg.y = N - 1 - g.z;
                rg.z = g.y;
            }
        }
        if (dir == 1) {
            rs.y = s.z;
            rs.z = N - 1 - s.y;
            if (s.x == g.x) {
                rg.y = g.z;
                rg.z = N - 1 - g.y;
            }
        }
    }
    if (axis == 1) {
        if (dir == 0) {
            rs.z = N - 1 - s.x;
            rs.x = s.z;
            if (s.y == g.y) {
                rg.z = N - 1 - g.x;
                rg.x = g.z;
            }
        }
        if (dir == 1) {
            rs.z = s.x;
            rs.x = N - 1 - s.z;
            if (s.y == g.y) {
                rg.z = g.x;
                rg.x = N - 1 - g.z;
            }
        }
    }
    if (axis == 2) {
        if (dir == 0) {
            rs.x = N - 1 - s.y;
            rs.y = s.x;
            if (s.z == g.z) {
                rg.x = N - 1 - g.y;
                rg.y = g.x;
            }
        }
        if (dir == 1) {
            rs.x = s.y;
            rs.y = N - 1 - s.x;
            if (s.z == g.z) {
                rg.x = g.y;
                rg.y = N - 1 - g.x;
            }
        }
    }
    
    return mp(rs, rg);
}

int d(point s, point g){
    return abs(s.x - g.x) + abs(s.y - g.y) + abs(s.z - g.z);
}

int dx[3] = {0, 1, -1};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    int N;
    cin >> N;
    point s,g;
    cin >> s.x >> s.y >> s.z;
    cin >> g.x >> g.y >> g.z;
    
    vector<pair<pair<point, point>, int>> dist, tmp;
    rep(i, 3){
        rep(j, 3){
            rep(k, 3){
                dist.pb(mp(mp(point{s.x + dx[i] , s.y + dx[j], s.z + dx[k]}, g), abs(dx[i]) + abs(dx[j]) + abs(dx[k])));
            }
        }
    }
    
    
    rep(a, 3){
        rep(i, dist.size()){
            rep(j, 3){
                rep(k, 2){
                    tmp.pb(mp(rot(j, k, dist[i].first.first, dist[i].first.second, N), dist[i].second + 1));
                }
            }
            tmp.pb(dist[i]);
        }
        dist = tmp;
        tmp.resize(0);
    }
    
    int ret = inf;
    rep(i, dist.size()){
        ret = min(ret, dist[i].second + d(dist[i].first.first, dist[i].first.second));
    }
    output(ret, 0);
    return 0;
}
```