#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
long long gcd(long long a, long long b, long long &x, long long &y) {
  if (b == 0) {
    x = 1;
    y = 0;
    return a;
  }
  long long x1, y1;
  long long g = gcd(b, a % b, x1, y1);
  x = y1;
  y1 = x1 - y1 * (a / b);
  return g;
}
long long qpow(long long a, long long n) {
  long long res = 1;
  while (n) {
    if (n % 2) {
      res = (res * a) % MOD;
      n--;
    } else {
      n = n / 2;
      a = (a * a) % MOD;
    }
  }
  return res;
}
long long inv(long long a) { return qpow(a, MOD - 2); }
bool cmp(pair<long long, long long> &p1, pair<long long, long long> &p2) {
  if (p1.second != p2.second) return p1.second < p2.second;
  return p1.first < p2.first;
}
bool prime(long long n) {
  for (long long i = 2; i * i <= n; i++) {
    if (n % i == 0) return false;
  }
  return true;
}
void dfs1(vector<vector<int>> &list, vector<int> &vis, int node,
          vector<vector<int>> &depth, vector<int> &par) {
  int n = list.size() - 1;
  int k = depth[1].size() - 1;
  vis[node] = 1;
  for (int j = 0; j < list[node].size(); j++) {
    if (vis[list[node][j]] == 0) {
      par[list[node][j]] = node;
      dfs1(list, vis, list[node][j], depth, par);
      for (int h = 0; h < k; h++) {
        if (depth[list[node][j]][h] > 0)
          depth[node][h + 1] += depth[list[node][j]][h];
      }
    }
  }
  depth[node][0]++;
}
void dfs2(vector<vector<int>> &list, vector<int> &vis, int node,
          vector<vector<int>> &depth, vector<vector<int>> &ans,
          vector<int> &par) {
  int n = list.size() - 1;
  int k = depth[1].size() - 1;
  vis[node] = 1;
  for (int h = 0; h <= k; h++) ans[node][h] = depth[node][h];
  if (node != 1) {
    for (int h = 1; h <= k; h++)
      ans[node][h] += ans[par[node]][h - 1] - (h > 1 ? depth[node][h - 2] : 0);
  }
  for (int j = 0; j < list[node].size(); j++) {
    if (vis[list[node][j]] == 0)
      dfs2(list, vis, list[node][j], depth, ans, par);
  }
}
void solve() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int n, k;
  cin >> n >> k;
  vector<vector<int>> list(n + 1);
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    cin >> u >> v;
    list[u].push_back(v);
    list[v].push_back(u);
  }
  vector<vector<int>> depth(n + 1, vector<int>(k + 1)),
      ans(n + 1, vector<int>(k + 1));
  vector<int> vis(n + 1), par(n + 1);
  dfs1(list, vis, 1, depth, par);
  for (int i = 0; i < vis.size(); i++) vis[i] = 0;
  dfs2(list, vis, 1, depth, ans, par);
  long long res = 0;
  for (int i = 1; i <= n; i++) res += ans[i][k];
  cout << res / 2 << '\n';
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}

### Prompt

Please create a solution in CPP 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 long MOD = 1e9 + 7;
long long gcd(long long a, long long b, long long &x, long long &y) {
  if (b == 0) {
    x = 1;
    y = 0;
    return a;
  }
  long long x1, y1;
  long long g = gcd(b, a % b, x1, y1);
  x = y1;
  y1 = x1 - y1 * (a / b);
  return g;
}
long long qpow(long long a, long long n) {
  long long res = 1;
  while (n) {
    if (n % 2) {
      res = (res * a) % MOD;
      n--;
    } else {
      n = n / 2;
      a = (a * a) % MOD;
    }
  }
  return res;
}
long long inv(long long a) { return qpow(a, MOD - 2); }
bool cmp(pair<long long, long long> &p1, pair<long long, long long> &p2) {
  if (p1.second != p2.second) return p1.second < p2.second;
  return p1.first < p2.first;
}
bool prime(long long n) {
  for (long long i = 2; i * i <= n; i++) {
    if (n % i == 0) return false;
  }
  return true;
}
void dfs1(vector<vector<int>> &list, vector<int> &vis, int node,
          vector<vector<int>> &depth, vector<int> &par) {
  int n = list.size() - 1;
  int k = depth[1].size() - 1;
  vis[node] = 1;
  for (int j = 0; j < list[node].size(); j++) {
    if (vis[list[node][j]] == 0) {
      par[list[node][j]] = node;
      dfs1(list, vis, list[node][j], depth, par);
      for (int h = 0; h < k; h++) {
        if (depth[list[node][j]][h] > 0)
          depth[node][h + 1] += depth[list[node][j]][h];
      }
    }
  }
  depth[node][0]++;
}
void dfs2(vector<vector<int>> &list, vector<int> &vis, int node,
          vector<vector<int>> &depth, vector<vector<int>> &ans,
          vector<int> &par) {
  int n = list.size() - 1;
  int k = depth[1].size() - 1;
  vis[node] = 1;
  for (int h = 0; h <= k; h++) ans[node][h] = depth[node][h];
  if (node != 1) {
    for (int h = 1; h <= k; h++)
      ans[node][h] += ans[par[node]][h - 1] - (h > 1 ? depth[node][h - 2] : 0);
  }
  for (int j = 0; j < list[node].size(); j++) {
    if (vis[list[node][j]] == 0)
      dfs2(list, vis, list[node][j], depth, ans, par);
  }
}
void solve() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int n, k;
  cin >> n >> k;
  vector<vector<int>> list(n + 1);
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    cin >> u >> v;
    list[u].push_back(v);
    list[v].push_back(u);
  }
  vector<vector<int>> depth(n + 1, vector<int>(k + 1)),
      ans(n + 1, vector<int>(k + 1));
  vector<int> vis(n + 1), par(n + 1);
  dfs1(list, vis, 1, depth, par);
  for (int i = 0; i < vis.size(); i++) vis[i] = 0;
  dfs2(list, vis, 1, depth, ans, par);
  long long res = 0;
  for (int i = 1; i <= n; i++) res += ans[i][k];
  cout << res / 2 << '\n';
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}

```