#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
const int INF = int (1e9) + int (1e5);
const ll INFL = ll(2e18) + ll(1e10);
const ui MOD = 1E9 + 7;
const double EPS = 1e-9;
#define FOR(i,n) for (int i=0;i<(n);++i)
#define ROF(i,x) for(int i = (x) ; i >= 0 ; --i)
#define MP make_pair
#define all(a) (a).begin(),(a).end()
#define ODD(x) ( ((x)&1)==0?0:1 )
#define SIGN(x) ( ((x) > 0) - ((x) < 0)  )
#define dbg(x) cerr << #x"= " << x << endl

std::mt19937_64  generator(std::chrono::system_clock::now().time_since_epoch().count());

inline ll powmod(ll a,ll b,ll mod) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a, ll b) { return a ? gcd(b%a, a): b; }
ll lcm(ll a, ll b) { return a / gcd(a,b) * b; }


void READ(bool _local){
    ios_base::sync_with_stdio(false); cin.tie(0);
#ifdef _DEBUG
    if (_local)
        freopen ("in.txt", "r", stdin);
#endif
}

int main() {
    READ(0);
    int n;cin>>n;
    vi a(n);
    FOR(i,n) cin>>a[i];
    sort(all(a));
    ll ret=a[0]+1;
    for(int i=1;i<n;++i){
        ret = ret * (a[i]-a[i-1]+1) % MOD;
    }
    cout << ret;


    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define Mp make_pair
#define pb push_back

using ll = long long;
using db = double;
using pii = pair<int, int>;
using vi = vector<int>;
mt19937 mrand(time(0));
ll get(ll r) { return ((ll)mrand() * mrand() % r + r) % r; }
ll get(ll l, ll r) { return get(r - l + 1) + l; }

int n, x[20], y[20], z[20], f[1 << 17][17], ans = 1e9;
int dis(int i, int j) { return abs(x[i] - x[j]) + abs(y[i] - y[j]) + max(0, z[j] - z[i]); }
signed main() {
    scanf("%d", &n);
    for(int i = 0; i < n; i++)
        scanf("%d %d %d", &x[i], &y[i], &z[i]);
    memset(f, 0x3f, sizeof(f)), f[1][0] = 0;
    for(int S = 2; S < 1 << n; S++)
        for(int i = 0; i < n; i++) if(S >> i & 1)
            for(int j = 0; j < n; j++) if((S >> j & 1) && j != i)
                f[S][i] = min(f[S][i], f[S ^ (1 << i)][j] + dis(j, i));
    for(int i = 0; i < n; i++) ans = min(ans, f[(1 << n) - 1][i] + dis(i, 0));
    printf("%d\n", ans);
    fprintf(stderr, "time=%.4f\n", (db)clock()/CLOCKS_PER_SEC);
    return 0;
}