There is a tree T with N vertices, numbered 1 through N. For each 1 ≤ i ≤ N - 1, the i-th edge connects vertices a_i and b_i.

Snuke is constructing a directed graph T' by arbitrarily assigning direction to each edge in T. (There are 2^{N - 1} different ways to construct T'.)

For a fixed T', we will define d(s,\ t) for each 1 ≤ s,\ t ≤ N, as follows:

* d(s,\ t) = (The number of edges that must be traversed against the assigned direction when traveling from vertex s to vertex t)



In particular, d(s,\ s) = 0 for each 1 ≤ s ≤ N. Also note that, in general, d(s,\ t) ≠ d(t,\ s).

We will further define D as the following:

3d2f3f88e8fa23f065c04cd175c14ebf.png

Snuke is constructing T' so that D will be the minimum possible value. How many different ways are there to construct T' so that D will be the minimum possible value, modulo 10^9 + 7?

Constraints

* 2 ≤ N ≤ 1000
* 1 ≤ a_i,\ b_i ≤ N
* The given graph is a tree.

Input

The input is given from Standard Input in the following format:


N
a_1 b_1
a_2 b_2
:
a_{N - 1} b_{N - 1}


Output

Print the number of the different ways to construct T' so that D will be the minimum possible value, modulo 10^9 + 7.

Examples

Input

4
1 2
1 3
1 4


Output

2


Input

4
1 2
2 3
3 4


Output

6


Input

6
1 2
1 3
1 4
2 5
2 6


Output

14


Input

10
2 4
2 5
8 3
10 7
1 6
2 8
9 5
8 6
10 6


Output

102
#include <bits/stdc++.h>
using namespace std;
void getre() {
  int x = 0;
  printf("%d\n", 1 / x);
}
void gettle() {
  int res = 1;
  while (1) res <<= 1;
  printf("%d\n", res);
}
template <typename T, typename S>
inline bool upmin(T &a, const S &b) {
  return a > b ? a = b, 1 : 0;
}
template <typename T, typename S>
inline bool upmax(T &a, const S &b) {
  return a < b ? a = b, 1 : 0;
}
template <typename N, typename PN>
inline N flo(N a, PN b) {
  return a >= 0 ? a / b : -((-a - 1) / b) - 1;
}
template <typename N, typename PN>
inline N cei(N a, PN b) {
  return a > 0 ? (a - 1) / b + 1 : -(-a / b);
}
template <typename N>
N gcd(N a, N b) {
  return b ? gcd(b, a % b) : a;
}
template <typename N>
inline int sgn(N a) {
  return a > 0 ? 1 : (a < 0 ? -1 : 0);
}
inline void gn(long long &x) {
  int sg = 1;
  char c;
  while (((c = getchar()) < '0' || c > '9') && c != '-')
    ;
  c == '-' ? (sg = -1, x = 0) : (x = c - '0');
  while ((c = getchar()) >= '0' && c <= '9') x = x * 10 + c - '0';
  x *= sg;
}
inline void gn(int &x) {
  long long t;
  gn(t);
  x = t;
}
inline void gn(unsigned long long &x) {
  long long t;
  gn(t);
  x = t;
}
inline void gn(double &x) {
  double t;
  scanf("%lf", &t);
  x = t;
}
inline void gn(long double &x) {
  double t;
  scanf("%lf", &t);
  x = t;
}
inline void gs(char *s) { scanf("%s", s); }
inline void gc(char &c) {
  while ((c = getchar()) > 126 || c < 33)
    ;
}
inline void pc(char c) { putchar(c); }
inline long long sqr(long long a) { return a * a; }
inline double sqrf(double a) { return a * a; }
const int inf = 0x3f3f3f3f;
const double pi = 3.14159265358979323846264338327950288L;
const double eps = 1e-6;
const int mo = 1e9 + 7;
const int TREE_MAXV = 3000 + 5;
struct edge {
  int v, next;
} e[TREE_MAXV * 2];
int g[TREE_MAXV], etot;
int qu[TREE_MAXV], pre[TREE_MAXV];
int h[33333];
int n;
void ae(int u, int v) {
  e[etot].v = v;
  e[etot].next = g[u];
  g[u] = etot++;
}
int bel[33333];
void bfs(int rt) {
  int p = 0, q = 0;
  pre[rt] = 0;
  h[rt] = 0;
  qu[q++] = rt;
  while (p != q) {
    int u = qu[p++];
    for (int i = g[u]; ~i; i = e[i].next)
      if (e[i].v != pre[u]) {
        pre[e[i].v] = u;
        bel[e[i].v] |= bel[u];
        h[e[i].v] = h[u] + 1;
        qu[q++] = e[i].v;
      }
  }
}
void tree_init() {
  static bool ini = 0;
  if (!ini) {
    ini = 1;
    memset(g, -1, sizeof(g));
  } else {
    for (int i = 0; i <= n; i++) g[i] = -1;
  }
  etot = 0;
}
void readedge() {
  for (int i = 1; i < n; i++) {
    int x, y;
    gn(x);
    gn(y);
    ae(x, y);
    ae(y, x);
  }
}
int boun[2222], to[2222];
const int zer = 1111;
int f[1111][2222];
int dp() {
  memset((f), (0), sizeof(f));
  for (int i = n - 1; i >= 0; i--) {
    int u = qu[i];
    for (int j = to[u] - boun[u]; j <= to[u] + boun[u]; j++) {
      f[u][j + zer] = 1;
      for (int t = g[u]; ~t; t = e[t].next)
        if (e[t].v != pre[u])
          (((f[u][j + zer]) =
                1ll * (f[u][j + zer]) *
                ((f[e[t].v][j - 1 + zer] + f[e[t].v][j + 1 + zer])) % mo) < 0
               ? (f[u][j + zer]) += mo
               : (f[u][j + zer]));
    }
  }
  int ret = 0;
  for (int t = (0), _ed = (2222); t < _ed; t++)
    (((ret) = ((ret) + (f[qu[0]][t])) % mo) < 0 ? (ret) += mo : (ret));
  return ret;
}
int main() {
  gn(n);
  tree_init();
  readedge();
  static int dis1[2222];
  bfs(1);
  int ma = 1;
  for (int u = (2), _ed = (n + 1); u < _ed; u++)
    if (h[u] > h[ma]) ma = u;
  bfs(ma);
  int mav = 1;
  for (int u = (1), _ed = (n + 1); u < _ed; u++)
    if (h[u] > h[mav]) mav = u;
  bfs(mav);
  for (int i = (1), _ed = (n + 1); i < _ed; i++) dis1[i] = h[i];
  bfs(ma);
  int r;
  r = cei(h[mav], 2);
  int rt = 0, rt2 = 0;
  if (h[mav] % 2 == 0) {
    for (int i = (1), _ed = (n + 1); i < _ed; i++) {
      if (dis1[i] == h[i] && h[i] == h[mav] / 2) rt = i;
    }
  } else {
    for (int i = (1), _ed = (n + 1); i < _ed; i++) {
      if (dis1[i] == h[mav] / 2 && h[i] == (h[mav] + 1) / 2) rt = i;
      if (dis1[i] == (h[mav] + 1) / 2 && h[i] == (h[mav] + 0) / 2) rt2 = i;
    }
  }
  bel[rt2] = 1;
  bfs(rt);
  int ans = 0;
  if (rt2 == 0) {
    for (int u = (1), _ed = (n + 1); u < _ed; u++)
      boun[u] = r - h[u], to[u] = 0;
    (((ans) = ((ans) + (dp())) % mo) < 0 ? (ans) += mo : (ans));
  } else {
    for (int u = (1), _ed = (n + 1); u < _ed; u++) {
      int d;
      if (!bel[u])
        d = r - 1 - h[u];
      else
        d = r - h[u];
      if (bel[u]) {
        to[u] = 0;
        boun[u] = d;
      } else {
        to[u] = 0;
        boun[u] = d + 1;
      }
    }
    (((ans) = ((ans) + (dp())) % mo) < 0 ? (ans) += mo : (ans));
    for (int u = (1), _ed = (n + 1); u < _ed; u++) {
      int d;
      if (!bel[u])
        d = r - 1 - h[u];
      else
        d = r - h[u];
      if (bel[u]) {
        to[u] = 0;
        boun[u] = d;
      } else {
        to[u] = 0;
        boun[u] = d + 1;
        if (d == 0) {
          to[u] = 1;
          boun[u] = 0;
        }
      }
    }
    (((ans) = ((ans) + (-dp())) % mo) < 0 ? (ans) += mo : (ans));
    for (int u = (1), _ed = (n + 1); u < _ed; u++) {
      int d;
      if (!bel[u])
        d = r - 1 - h[u];
      else
        d = r - h[u];
      if (bel[u]) {
        to[u] = 0;
        boun[u] = d;
      } else {
        to[u] = 0;
        boun[u] = d + 1;
        if (d == 0) {
          to[u] = -1;
          boun[u] = 0;
        }
      }
    }
    (((ans) = ((ans) + (-dp())) % mo) < 0 ? (ans) += mo : (ans));
    for (int u = (1), _ed = (n + 1); u < _ed; u++) {
      int d;
      if (!bel[u])
        d = r - 1 - h[u];
      else
        d = r - h[u];
      if (bel[u]) {
        to[u] = 0;
        boun[u] = d + 1;
      } else {
        to[u] = 0;
        boun[u] = d;
      }
    }
    (((ans) = ((ans) + (dp())) % mo) < 0 ? (ans) += mo : (ans));
    for (int u = (1), _ed = (n + 1); u < _ed; u++) {
      int d;
      if (!bel[u])
        d = r - 1 - h[u];
      else
        d = r - h[u];
      if (!bel[u]) {
        to[u] = 0;
        boun[u] = d;
      } else {
        to[u] = 0;
        boun[u] = d + 1;
        if (d == 0) {
          to[u] = 1;
          boun[u] = 0;
        }
      }
    }
    (((ans) = ((ans) + (-dp())) % mo) < 0 ? (ans) += mo : (ans));
    for (int u = (1), _ed = (n + 1); u < _ed; u++) {
      int d;
      if (!bel[u])
        d = r - 1 - h[u];
      else
        d = r - h[u];
      if (!bel[u]) {
        to[u] = 0;
        boun[u] = d;
      } else {
        to[u] = 0;
        boun[u] = d + 1;
        if (d == 0) {
          to[u] = -1;
          boun[u] = 0;
        }
      }
    }
    (((ans) = ((ans) + (-dp())) % mo) < 0 ? (ans) += mo : (ans));
    for (int u = (1), _ed = (n + 1); u < _ed; u++) {
      int d;
      if (!bel[u])
        d = r - 1 - h[u];
      else
        d = r - h[u];
      if (!bel[u]) {
        to[u] = 1;
        boun[u] = d + 1;
        if (d == 0) {
          to[u] = 0;
          boun[u] = 0;
        }
      } else {
        to[u] = 0;
        boun[u] = d + 1;
        if (d == 0) {
          to[u] = 1;
          boun[u] = 0;
        }
      }
    }
    (((ans) = ((ans) + (dp())) % mo) < 0 ? (ans) += mo : (ans));
    for (int u = (1), _ed = (n + 1); u < _ed; u++) {
      int d;
      if (!bel[u])
        d = r - 1 - h[u];
      else
        d = r - h[u];
      if (bel[u]) {
        to[u] = 1;
        boun[u] = d + 1;
        if (d == 0) {
          to[u] = 0;
          boun[u] = 0;
        }
      } else {
        to[u] = 0;
        boun[u] = d + 1;
        if (d == 0) {
          to[u] = 1;
          boun[u] = 0;
        }
      }
    }
    (((ans) = ((ans) + (dp())) % mo) < 0 ? (ans) += mo : (ans));
    return 0;
  }
  printf("%d\n", ans);
  return 0;
}
