#include <fstream>
#include <iostream>
using namespace std;
const int MAXN = 101;
bool t[MAXN][MAXN][MAXN] = {false};
int n, x[3], y[3], z[3], ans = 0;
main()
{
ifstream fin("combo.in");
ofstream fout("combo.out");
#define cin fin
#define cout fout
ios::sync_with_stdio(false);
cin >> n;
if (n == 1){
cout << 1;
return 0;
}
for (int i = 1; i <= 2; ++i){
cin >> x[i] >> y[i] >> z[i];
for (int a = x[i] - 2, d; a <= x[i] + 2; ++a){
d = a;
if (a <= 0)
d += n;
else if (a > n)
d -= n;
for (int b = y[i] - 2, e; b <= y[i] + 2; ++b){
e = b;
if (b <= 0)
e += n;
else if (b > n)
e -= n;
for (int c = z[i] - 2, f; c <= z[i] + 2; ++c){
f = c;
if (c <= 0)
f += n;
else if (c > n)
f -= n;
if (! t[d][e][f]){
ans++;
t[d][e][f] = true;
}
}
}
}
}
cout << ans;
}