#include <bits/stdc++.h>
using namespace std;
#define GET_MACRO(_1, _2, _3, NAME, ...) NAME
#define _repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define _rep(i,n) _repl(i,0,n)
#define rep(...) GET_MACRO(__VA_ARGS__, _repl, _rep)(__VA_ARGS__)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cout<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cout<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream &o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream &o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 1120000000
#define MOD 1000000007

long mod_pow(long x, long n, long p=MOD){
  if(x==0) return 0;
  long res=1;
  x %= p;
  while(n>0){
    if(n&1) res=res*x%p;
    x=x*x%p;
    n>>=1;
  }
  return res;
}
inline long mod_inv(long x, long p=MOD){ return mod_pow(x%p, p-2, p); }

vector<int> g[5003];

int dfs(int v, int from){
  int ret = 1;
  for(auto to : g[v]) if(to != from) ret += dfs(to, v);
  return ret;
}

vector<int> calc_ch(int root){
  vector<int> ret;
  for(auto to : g[root]) ret.pb(dfs(to, root));
  return ret;
}

int main(){
  int n;
  cin>>n;
  rep(i,n-1){
    int a,b;
    cin>>a>>b;
    a--;b--;
    g[a].pb(b);
    g[b].pb(a);
  }

  vector<pair<int,int>> v;
  rep(i,n){
    auto rv = calc_ch(i);
    v.pb(mp(*max_element(all(rv)), i));
  }
  sort(all(v));

  vector<long> fact(n+1,1);
  rep(i,n) fact[i+1] = fact[i]*(i+1) %MOD;

  if(v[0].fi == v[1].fi){
    assert(v[0].fi == n/2 && v[1].fi == n/2);
    cout << fact[n/2] * fact[n/2] %MOD << endl;
    return 0;
  }
  else {
    auto a = calc_ch(v[0].se);
    int m = a.size();
    sort(all(a));
    vector<long> sel(1,1);
    rep(i,m){
      vector<long> nxt(sel.size() + a[i], 0);
      rep(j,sel.size()){
        long comb = 1;
        rep(k,a[i]+1){
          nxt[j+k] += sel[j]*(comb*comb%MOD *fact[k]%MOD) %MOD;
          nxt[j+k] %= MOD;
          comb = comb * (a[i]-k) %MOD * mod_inv(k+1) %MOD;
        }
      }
      swap(nxt, sel);
    }
    assert(sel.size() == n);
    // dbg(a);dbg(sel);

    long ans = 0;
    long sgn = 1;
    rep(k,n){
      ans += sel[k] * fact[n-k] * sgn %MOD;
      sgn *= -1;
    }
    ans %= MOD;
    if(ans < 0) ans += MOD;

    cout << ans %MOD << endl;
  }

  return 0;
}

### Prompt

Generate a cpp solution to the following problem:

There is a tree with N vertices. The vertices are numbered 1 through N. The i-th edge (1 \leq i \leq N - 1) connects Vertex x_i and y_i. For vertices v and w (1 \leq v, w \leq N), we will define the distance between v and w d(v, w) as "the number of edges contained in the path v-w".

A squirrel lives in each vertex of the tree. They are planning to move, as follows. First, they will freely choose a permutation of (1, 2, ..., N), p = (p_1, p_2, ..., p_N). Then, for each 1 \leq i \leq N, the squirrel that lived in Vertex i will move to Vertex p_i.

Since they like long travels, they have decided to maximize the total distance they traveled during the process. That is, they will choose p so that d(1, p_1) + d(2, p_2) + ... + d(N, p_N) will be maximized. How many such ways are there to choose p, modulo 10^9 + 7?

Constraints

* 2 \leq N \leq 5,000
* 1 \leq x_i, y_i \leq N
* The input graph is a tree.

Input

Input is given from Standard Input in the following format:


N
x_1 y_1
x_2 y_2
:
x_{N - 1} y_{N - 1}


Output

Print the number of the ways to choose p so that the condition is satisfied, modulo 10^9 + 7.

Examples

Input

3
1 2
2 3


Output

3


Input

4
1 2
1 3
1 4


Output

11


Input

6
1 2
1 3
1 4
2 5
2 6


Output

36


Input

7
1 2
6 3
4 5
1 7
1 5
2 3


Output

396

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
#define GET_MACRO(_1, _2, _3, NAME, ...) NAME
#define _repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define _rep(i,n) _repl(i,0,n)
#define rep(...) GET_MACRO(__VA_ARGS__, _repl, _rep)(__VA_ARGS__)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cout<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cout<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream &o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream &o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 1120000000
#define MOD 1000000007

long mod_pow(long x, long n, long p=MOD){
  if(x==0) return 0;
  long res=1;
  x %= p;
  while(n>0){
    if(n&1) res=res*x%p;
    x=x*x%p;
    n>>=1;
  }
  return res;
}
inline long mod_inv(long x, long p=MOD){ return mod_pow(x%p, p-2, p); }

vector<int> g[5003];

int dfs(int v, int from){
  int ret = 1;
  for(auto to : g[v]) if(to != from) ret += dfs(to, v);
  return ret;
}

vector<int> calc_ch(int root){
  vector<int> ret;
  for(auto to : g[root]) ret.pb(dfs(to, root));
  return ret;
}

int main(){
  int n;
  cin>>n;
  rep(i,n-1){
    int a,b;
    cin>>a>>b;
    a--;b--;
    g[a].pb(b);
    g[b].pb(a);
  }

  vector<pair<int,int>> v;
  rep(i,n){
    auto rv = calc_ch(i);
    v.pb(mp(*max_element(all(rv)), i));
  }
  sort(all(v));

  vector<long> fact(n+1,1);
  rep(i,n) fact[i+1] = fact[i]*(i+1) %MOD;

  if(v[0].fi == v[1].fi){
    assert(v[0].fi == n/2 && v[1].fi == n/2);
    cout << fact[n/2] * fact[n/2] %MOD << endl;
    return 0;
  }
  else {
    auto a = calc_ch(v[0].se);
    int m = a.size();
    sort(all(a));
    vector<long> sel(1,1);
    rep(i,m){
      vector<long> nxt(sel.size() + a[i], 0);
      rep(j,sel.size()){
        long comb = 1;
        rep(k,a[i]+1){
          nxt[j+k] += sel[j]*(comb*comb%MOD *fact[k]%MOD) %MOD;
          nxt[j+k] %= MOD;
          comb = comb * (a[i]-k) %MOD * mod_inv(k+1) %MOD;
        }
      }
      swap(nxt, sel);
    }
    assert(sel.size() == n);
    // dbg(a);dbg(sel);

    long ans = 0;
    long sgn = 1;
    rep(k,n){
      ans += sel[k] * fact[n-k] * sgn %MOD;
      sgn *= -1;
    }
    ans %= MOD;
    if(ans < 0) ans += MOD;

    cout << ans %MOD << endl;
  }

  return 0;
}

```