#include <bits/stdc++.h>
using namespace std;
#define all(c) (c).begin(),(c).end()
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define iter(c) __typeof((c).begin())
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
#define mem(a) memset(a,0,sizeof(a))
#define pd(a) printf("%.10f\n",a)
#define pb(a) push_back(a)
#define in(a) insert(a)
#define pi M_PI
#define R cin>>
#define F first
#define S second
#define C class
#define ll long long
#define ln cout<<'\n'
template<C T>void pr(T a){cout<<a;ln;}
template<C T,C T2>void pr(T a,T2 b){cout<<a<<' '<<b;ln;}
template<C T,C T2,C T3>void pr(T a,T2 b,T3 c){cout<<a<<' '<<b<<' '<<c;ln;}
template<C T>void PR(T a,int n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
bool check(int n,int m,int x,int y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1000000007,MAXL=1LL<<60,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<ll,vector<int> > P;

void Main() {
  int n;
  R n;
  ll c[n][n];
  rep(i,n)rep(j,n)R c[i][j];
  vector<int> v(n);
  rep(i,n) v[i]=i;
  map<vector<int>,int> m;
  m[v]=0;
  priority_queue<P,vector<P>,greater<P> > que;
  que.push(P(0,v));
  ll ans=0;
  while(!que.empty()) {
    P p=que.top();que.pop();
    ll cc=p.F;
    vector<int> a=p.S;
    if(m[a]<cc) continue;
    ans=max(ans,cc);
    rep(i,n) {
      REP(j,i+1,n) {
        vector<int> b=a;
        swap(b[i],b[j]);
        if(!m.count(b)||m[b]>cc+c[i][j]) {
          m[b]=cc+c[i][j];
          que.push(P(cc+c[i][j],b));
        }
      }
    }
  }
  pr(ans);
}

int main() {
  ios::sync_with_stdio(0);cin.tie(0);
  Main();return 0;
}

### Prompt

Please formulate a Cpp solution to the following problem:

Problem statement

There is a permutation with $ 1,2, ..., N $ sorted. I want to select two different numbers $ i $, $ j $ and replace them repeatedly to make them sorted (in the order of $ 1,2, ..., N $). Every time you replace the numbers $ i $, $ j $, you need $ c_ {i, j} $.

Let $ f (p) $ be the minimum cost required to sort $ p $ for the permutation $ p $. Find the maximum possible value of $ f (p) $.

Constraint

* $ 2 \ leq N \ leq 8 $
* $ 0 \ leq c_ {i, j} \ leq 10 ^ 5 $
* $ c_ {i, j} = c_ {j, i} $
* $ c_ {i, i} = 0 $



input

Input follows the following format. All given numbers are integers.


$ N $
$ c_ {1,1} $ $ c_ {1,2} $ $ ... $ $ c_ {1, N} $
$ c_ {2,1} $ $ c_ {2,2} $ $ ... $ $ c_ {2, N} $
$ ... $
$ c_ {N, 1} $ $ c_ {N, 2} $ $ ... $ $ c_ {N, N} $

output

Output the maximum value on one line.

Example

Input

3
0 1 3
1 0 8
3 8 0


Output

5

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
#define all(c) (c).begin(),(c).end()
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define iter(c) __typeof((c).begin())
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
#define mem(a) memset(a,0,sizeof(a))
#define pd(a) printf("%.10f\n",a)
#define pb(a) push_back(a)
#define in(a) insert(a)
#define pi M_PI
#define R cin>>
#define F first
#define S second
#define C class
#define ll long long
#define ln cout<<'\n'
template<C T>void pr(T a){cout<<a;ln;}
template<C T,C T2>void pr(T a,T2 b){cout<<a<<' '<<b;ln;}
template<C T,C T2,C T3>void pr(T a,T2 b,T3 c){cout<<a<<' '<<b<<' '<<c;ln;}
template<C T>void PR(T a,int n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
bool check(int n,int m,int x,int y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1000000007,MAXL=1LL<<60,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<ll,vector<int> > P;

void Main() {
  int n;
  R n;
  ll c[n][n];
  rep(i,n)rep(j,n)R c[i][j];
  vector<int> v(n);
  rep(i,n) v[i]=i;
  map<vector<int>,int> m;
  m[v]=0;
  priority_queue<P,vector<P>,greater<P> > que;
  que.push(P(0,v));
  ll ans=0;
  while(!que.empty()) {
    P p=que.top();que.pop();
    ll cc=p.F;
    vector<int> a=p.S;
    if(m[a]<cc) continue;
    ans=max(ans,cc);
    rep(i,n) {
      REP(j,i+1,n) {
        vector<int> b=a;
        swap(b[i],b[j]);
        if(!m.count(b)||m[b]>cc+c[i][j]) {
          m[b]=cc+c[i][j];
          que.push(P(cc+c[i][j],b));
        }
      }
    }
  }
  pr(ans);
}

int main() {
  ios::sync_with_stdio(0);cin.tie(0);
  Main();return 0;
}

```