#include <bits/stdc++.h>
using namespace std;
int n, k, h[50005], cl[50005], fa[50005], facen[50005], mi[50005][505],
    euler[50005 * 2], rmq[50005 * 2][20], sz[50005], vt[50005], neu;
long long res = 0;
vector<int> a[50005], cen[50005], vec[50005];
void DFS(int u) {
  euler[++neu] = u;
  vt[u] = neu;
  cl[u] = 1;
  for (auto v : a[u])
    if (cl[v] == 0) {
      h[v] = h[u] + 1;
      DFS(v);
      euler[++neu] = u;
    }
  cl[u] = 0;
}
void DFS1(int u) {
  sz[u] = 1;
  cl[u] = 1;
  for (auto v : a[u])
    if (cl[v] == 0) {
      fa[v] = u;
      DFS1(v);
      sz[u] += sz[v];
    }
  cl[u] = 0;
}
void FCEN(int u, int pa) {
  DFS1(u);
  int tg = sz[u] / 2;
  while (1 + 1 == 2) {
    int ok = 0;
    for (auto v : a[u])
      if (cl[v] != -1 && v != fa[u] && sz[v] > tg) {
        u = v;
        ok = 1;
        break;
      }
    if (ok == 0) {
      if (pa) cen[pa].push_back(u), facen[u] = pa;
      cl[u] = -1;
      for (auto v : a[u])
        if (cl[v] != -1) FCEN(v, u);
      break;
    }
  }
}
int dist(int u, int v) {
  int uu = vt[u], vv = vt[v], tg;
  if (uu > vv) swap(uu, vv);
  int kc = log2(vv - uu + 1);
  uu = rmq[uu][kc];
  vv = rmq[vv - (1 << kc) + 1][kc];
  if (h[uu] < h[vv])
    tg = uu;
  else
    tg = vv;
  return h[u] + h[v] - h[tg] * 2;
}
void DFScen(int u) {
  vec[u].push_back(u);
  mi[u][0]++;
  for (auto v : cen[u]) {
    DFScen(v);
    for (auto t : vec[v]) {
      int val = dist(t, u);
      if (val <= k) res += mi[u][k - val];
    }
    for (auto t : vec[v]) {
      int val = dist(t, u);
      if (val <= k) mi[u][val]++;
      vec[u].push_back(t);
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> k;
  for (int i = 1; i <= n - 1; i++) {
    int u, v;
    cin >> u >> v;
    a[u].push_back(v);
    a[v].push_back(u);
  }
  DFS(1);
  FCEN(1, 0);
  for (int i = 1; i <= neu; i++) rmq[i][0] = euler[i];
  for (int j = 1; j <= 17; j++)
    for (int i = 1; i <= neu - (1 << j) + 1; i++) {
      int u = rmq[i][j - 1], v = rmq[i + (1 << (j - 1))][j - 1];
      if (h[u] < h[v])
        rmq[i][j] = u;
      else
        rmq[i][j] = v;
    }
  for (int i = 1; i <= n; i++)
    if (facen[i] == 0) {
      DFScen(i);
      break;
    }
  cout << res;
  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;
int n, k, h[50005], cl[50005], fa[50005], facen[50005], mi[50005][505],
    euler[50005 * 2], rmq[50005 * 2][20], sz[50005], vt[50005], neu;
long long res = 0;
vector<int> a[50005], cen[50005], vec[50005];
void DFS(int u) {
  euler[++neu] = u;
  vt[u] = neu;
  cl[u] = 1;
  for (auto v : a[u])
    if (cl[v] == 0) {
      h[v] = h[u] + 1;
      DFS(v);
      euler[++neu] = u;
    }
  cl[u] = 0;
}
void DFS1(int u) {
  sz[u] = 1;
  cl[u] = 1;
  for (auto v : a[u])
    if (cl[v] == 0) {
      fa[v] = u;
      DFS1(v);
      sz[u] += sz[v];
    }
  cl[u] = 0;
}
void FCEN(int u, int pa) {
  DFS1(u);
  int tg = sz[u] / 2;
  while (1 + 1 == 2) {
    int ok = 0;
    for (auto v : a[u])
      if (cl[v] != -1 && v != fa[u] && sz[v] > tg) {
        u = v;
        ok = 1;
        break;
      }
    if (ok == 0) {
      if (pa) cen[pa].push_back(u), facen[u] = pa;
      cl[u] = -1;
      for (auto v : a[u])
        if (cl[v] != -1) FCEN(v, u);
      break;
    }
  }
}
int dist(int u, int v) {
  int uu = vt[u], vv = vt[v], tg;
  if (uu > vv) swap(uu, vv);
  int kc = log2(vv - uu + 1);
  uu = rmq[uu][kc];
  vv = rmq[vv - (1 << kc) + 1][kc];
  if (h[uu] < h[vv])
    tg = uu;
  else
    tg = vv;
  return h[u] + h[v] - h[tg] * 2;
}
void DFScen(int u) {
  vec[u].push_back(u);
  mi[u][0]++;
  for (auto v : cen[u]) {
    DFScen(v);
    for (auto t : vec[v]) {
      int val = dist(t, u);
      if (val <= k) res += mi[u][k - val];
    }
    for (auto t : vec[v]) {
      int val = dist(t, u);
      if (val <= k) mi[u][val]++;
      vec[u].push_back(t);
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> k;
  for (int i = 1; i <= n - 1; i++) {
    int u, v;
    cin >> u >> v;
    a[u].push_back(v);
    a[v].push_back(u);
  }
  DFS(1);
  FCEN(1, 0);
  for (int i = 1; i <= neu; i++) rmq[i][0] = euler[i];
  for (int j = 1; j <= 17; j++)
    for (int i = 1; i <= neu - (1 << j) + 1; i++) {
      int u = rmq[i][j - 1], v = rmq[i + (1 << (j - 1))][j - 1];
      if (h[u] < h[v])
        rmq[i][j] = u;
      else
        rmq[i][j] = v;
    }
  for (int i = 1; i <= n; i++)
    if (facen[i] == 0) {
      DFScen(i);
      break;
    }
  cout << res;
  return 0;
}

```