#include <bits/stdc++.h>
using namespace std;
int Int() {
  int x;
  scanf("%d", &x);
  return x;
}
long long Long() {
  long long x;
  scanf("%lld", &x);
  return x;
}
void err(istream_iterator<string> it) { cout << endl; }
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << a << ' ';
  err(++it, args...);
}
const int N = (int)5e4 + 5;
const int maxN = (int)1e6 + 6;
const long long Mod = (long long)1e9 + 7;
const int inf = (int)2e9;
const long long Inf = (long long)1e18;
vector<vector<int> > g;
int sub[N], len, k, n, dp[505];
bool vis[N];
void dfs(int s, int p = 0) {
  sub[s] = 1;
  ++len;
  for (int i : g[s]) {
    if (i == p or vis[i]) continue;
    dfs(i, s);
    sub[s] += sub[i];
  }
}
int Centroid(int s, int p) {
  for (int i : g[s]) {
    if (i != p and vis[i] == 0 and sub[i] > len / 2) return Centroid(i, s);
  }
  return s;
}
void modify(int s, int p, int d) {
  if (d > k) return;
  dp[d]++;
  for (int i : g[s]) {
    if (i == p or vis[i]) continue;
    modify(i, s, d + 1);
  }
}
int ans;
void Answer(int s, int p, int dist) {
  if (dist > k) return;
  ans += dp[k - dist];
  for (int i : g[s]) {
    if (i == p or vis[i]) continue;
    Answer(i, s, dist + 1);
  }
}
void decompose(int s, int p) {
  len = 0;
  dfs(s);
  int cen = Centroid(s, s);
  memset(dp, 0, sizeof dp);
  dp[0]++;
  for (int i : g[cen]) {
    if (vis[i]) continue;
    Answer(i, cen, 1);
    modify(i, cen, 1);
  }
  vis[cen] = 1;
  for (int i : g[cen]) {
    if (vis[i]) continue;
    decompose(i, cen);
  }
}
int main() {
  int test = 1, tc = 0;
  while (test--) {
    n = Int(), k = Int();
    g.resize(n + 1);
    for (int i = 1; i < n; ++i) {
      int x = Int(), y = Int();
      g[x].push_back(y);
      g[y].push_back(x);
    }
    decompose(1, 1);
    printf("%d\n", ans);
  }
  return 0;
}

### Prompt

Construct a Cpp code solution to the problem outlined:

A tree is a connected graph that doesn't contain any cycles.

The distance between two vertices of a tree is the length (in edges) of the shortest path between these vertices.

You are given a tree with n vertices and a positive number k. Find the number of distinct pairs of the vertices which have a distance of exactly k between them. Note that pairs (v, u) and (u, v) are considered to be the same pair.

Input

The first line contains two integers n and k (1 ≤ n ≤ 50000, 1 ≤ k ≤ 500) — the number of vertices and the required distance between the vertices.

Next n - 1 lines describe the edges as "ai bi" (without the quotes) (1 ≤ ai, bi ≤ n, ai ≠ bi), where ai and bi are the vertices connected by the i-th edge. All given edges are different.

Output

Print a single integer — the number of distinct pairs of the tree's vertices which have a distance of exactly k between them.

Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.

Examples

Input

5 2
1 2
2 3
3 4
2 5


Output

4


Input

5 3
1 2
2 3
3 4
4 5


Output

2

Note

In the first sample the pairs of vertexes at distance 2 from each other are (1, 3), (1, 5), (3, 5) and (2, 4).

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int Int() {
  int x;
  scanf("%d", &x);
  return x;
}
long long Long() {
  long long x;
  scanf("%lld", &x);
  return x;
}
void err(istream_iterator<string> it) { cout << endl; }
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << a << ' ';
  err(++it, args...);
}
const int N = (int)5e4 + 5;
const int maxN = (int)1e6 + 6;
const long long Mod = (long long)1e9 + 7;
const int inf = (int)2e9;
const long long Inf = (long long)1e18;
vector<vector<int> > g;
int sub[N], len, k, n, dp[505];
bool vis[N];
void dfs(int s, int p = 0) {
  sub[s] = 1;
  ++len;
  for (int i : g[s]) {
    if (i == p or vis[i]) continue;
    dfs(i, s);
    sub[s] += sub[i];
  }
}
int Centroid(int s, int p) {
  for (int i : g[s]) {
    if (i != p and vis[i] == 0 and sub[i] > len / 2) return Centroid(i, s);
  }
  return s;
}
void modify(int s, int p, int d) {
  if (d > k) return;
  dp[d]++;
  for (int i : g[s]) {
    if (i == p or vis[i]) continue;
    modify(i, s, d + 1);
  }
}
int ans;
void Answer(int s, int p, int dist) {
  if (dist > k) return;
  ans += dp[k - dist];
  for (int i : g[s]) {
    if (i == p or vis[i]) continue;
    Answer(i, s, dist + 1);
  }
}
void decompose(int s, int p) {
  len = 0;
  dfs(s);
  int cen = Centroid(s, s);
  memset(dp, 0, sizeof dp);
  dp[0]++;
  for (int i : g[cen]) {
    if (vis[i]) continue;
    Answer(i, cen, 1);
    modify(i, cen, 1);
  }
  vis[cen] = 1;
  for (int i : g[cen]) {
    if (vis[i]) continue;
    decompose(i, cen);
  }
}
int main() {
  int test = 1, tc = 0;
  while (test--) {
    n = Int(), k = Int();
    g.resize(n + 1);
    for (int i = 1; i < n; ++i) {
      int x = Int(), y = Int();
      g[x].push_back(y);
      g[y].push_back(x);
    }
    decompose(1, 1);
    printf("%d\n", ans);
  }
  return 0;
}

```