#include <bits/stdc++.h>
using namespace std;
const long double EPS = 1e-7;
const long double PI = 3.141592653589793;
const int MAX_N = 51234, MAX_K = 555;
int N, K, topsort[MAX_N], topsort_p = 0;
vector<int> g[MAX_N];
struct Node {
  int pred;
  vector<int> ch;
} t[MAX_N];
int used[MAX_N];
void dfs(int v, int p = -1) {
  used[v] = 1;
  t[v].pred = p;
  for (int i = 0; i < g[v].size(); ++i)
    if (!used[g[v][i]]) {
      t[v].ch.push_back(g[v][i]);
      dfs(g[v][i], v);
    }
  topsort[topsort_p++] = v;
}
void input() {
  cin >> K;
  int a, b;
  for (int i = 0; i < N - 1; ++i) {
    cin >> a >> b;
    --a;
    --b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  dfs(0);
}
unsigned long long dp[MAX_N][MAX_K];
bool solve() {
  while (cin >> N) {
    input();
    for (int i = 0; i < N; ++i) dp[i][0] = 1;
    for (int i = 0; i < N; ++i) {
      int v = topsort[i];
      for (int j = 1; j < MAX_K; ++j)
        for (int k = 0; k < t[v].ch.size(); ++k)
          dp[v][j] += dp[t[v].ch[k]][j - 1];
    }
    long double res = 0;
    for (int i = 0; i < N; ++i) res += dp[i][K];
    int a, b;
    unsigned long long sum, sum1 = 0;
    for (int i = 0; i < N; ++i) {
      for (int j = 1; j <= K - 1; ++j) {
        a = j, b = K - j;
        sum = 0;
        for (int k = 0; k < t[i].ch.size(); ++k) sum += dp[t[i].ch[k]][b - 1];
        for (int k = 0; k < t[i].ch.size(); ++k)
          sum1 += ((sum - dp[t[i].ch[k]][b - 1]) * dp[t[i].ch[k]][a - 1]);
      }
    }
    cout << fixed << setprecision(0) << res + (sum1 >> 1) << '\n';
    return true;
  }
  return false;
}
int main() {
  ios_base::sync_with_stdio(0);
  while (solve())
    ;
  return 0;
}

### Prompt

Generate a Cpp solution to the following problem:

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;
const long double EPS = 1e-7;
const long double PI = 3.141592653589793;
const int MAX_N = 51234, MAX_K = 555;
int N, K, topsort[MAX_N], topsort_p = 0;
vector<int> g[MAX_N];
struct Node {
  int pred;
  vector<int> ch;
} t[MAX_N];
int used[MAX_N];
void dfs(int v, int p = -1) {
  used[v] = 1;
  t[v].pred = p;
  for (int i = 0; i < g[v].size(); ++i)
    if (!used[g[v][i]]) {
      t[v].ch.push_back(g[v][i]);
      dfs(g[v][i], v);
    }
  topsort[topsort_p++] = v;
}
void input() {
  cin >> K;
  int a, b;
  for (int i = 0; i < N - 1; ++i) {
    cin >> a >> b;
    --a;
    --b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  dfs(0);
}
unsigned long long dp[MAX_N][MAX_K];
bool solve() {
  while (cin >> N) {
    input();
    for (int i = 0; i < N; ++i) dp[i][0] = 1;
    for (int i = 0; i < N; ++i) {
      int v = topsort[i];
      for (int j = 1; j < MAX_K; ++j)
        for (int k = 0; k < t[v].ch.size(); ++k)
          dp[v][j] += dp[t[v].ch[k]][j - 1];
    }
    long double res = 0;
    for (int i = 0; i < N; ++i) res += dp[i][K];
    int a, b;
    unsigned long long sum, sum1 = 0;
    for (int i = 0; i < N; ++i) {
      for (int j = 1; j <= K - 1; ++j) {
        a = j, b = K - j;
        sum = 0;
        for (int k = 0; k < t[i].ch.size(); ++k) sum += dp[t[i].ch[k]][b - 1];
        for (int k = 0; k < t[i].ch.size(); ++k)
          sum1 += ((sum - dp[t[i].ch[k]][b - 1]) * dp[t[i].ch[k]][a - 1]);
      }
    }
    cout << fixed << setprecision(0) << res + (sum1 >> 1) << '\n';
    return true;
  }
  return false;
}
int main() {
  ios_base::sync_with_stdio(0);
  while (solve())
    ;
  return 0;
}

```