#include <bits/stdc++.h>
using namespace std;
long long read() {
  long long x = 0, f = 1;
  char c = getchar();
  while (!isdigit(c)) {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (isdigit(c)) {
    x = x * 10 + c - '0';
    c = getchar();
  }
  return x * f;
}
const int N = 50000 + 100;
struct road {
  int w, to;
  road(int A, int B) { to = A, w = B; }
};
vector<road> e[N];
int n, K, size[N], t_size, root;
bool t_vis[N], vis[N], done[N];
void GetSize(int now) {
  t_vis[now] = true;
  size[now] = 1;
  for (int i = 0; i < int(e[now].size()); i++)
    if (t_vis[e[now][i].to] == false and vis[e[now][i].to] == false) {
      GetSize(e[now][i].to);
      size[now] += size[e[now][i].to];
    }
  t_vis[now] = false;
}
void GetRoot(int now) {
  t_vis[now] = true;
  int OK = true, size_now = 1;
  for (int i = 0; i < int(e[now].size()); i++)
    if (t_vis[e[now][i].to] == false and vis[e[now][i].to] == false) {
      GetRoot(e[now][i].to);
      size_now += size[e[now][i].to];
      if (size[e[now][i].to] > (t_size / 2)) OK = false;
    }
  if (t_size - size_now > (t_size / 2)) OK = false;
  if (OK == true) root = now;
  t_vis[now] = false;
}
int cnt[N], ans;
void dfs2(int now, int dis, int type) {
  t_vis[now] = true;
  if (type == 1 and K - dis >= 0) ans += cnt[K - dis];
  if (type == 2) cnt[dis]++;
  if (type == 3) cnt[dis]--;
  for (int i = 0; i < int(e[now].size()); i++)
    if (t_vis[e[now][i].to] == false and done[e[now][i].to] == true)
      dfs2(e[now][i].to, dis + e[now][i].w, type);
  t_vis[now] = false;
}
void dfs(int now) {
  vis[now] = true;
  vector<road> son;
  son.reserve(32);
  for (int i = 0; i < int(e[now].size()); i++)
    if (vis[e[now][i].to] == false) {
      GetSize(e[now][i].to), t_size = size[e[now][i].to];
      GetRoot(e[now][i].to);
      dfs(root);
      son.push_back(e[now][i]);
    }
  for (int i = 0; i < int(son.size()); i++)
    dfs2(son[i].to, son[i].w, 1), dfs2(son[i].to, son[i].w, 2);
  for (int i = 0; i < int(son.size()); i++) dfs2(son[i].to, son[i].w, 3);
  done[now] = true;
}
int main() {
  n = read(), K = read();
  for (int i = 1; i <= n; i++) e[i].reserve(4);
  for (int i = 1; i < n; i++) {
    int s = read(), t = read();
    e[s].push_back(road(t, 1));
    e[t].push_back(road(s, 1));
  }
  cnt[0]++;
  GetSize(1), t_size = size[1];
  GetRoot(1);
  dfs(root);
  printf("%d", ans);
  return 0;
}

### Prompt

In Cpp, your task is to solve 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;
long long read() {
  long long x = 0, f = 1;
  char c = getchar();
  while (!isdigit(c)) {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (isdigit(c)) {
    x = x * 10 + c - '0';
    c = getchar();
  }
  return x * f;
}
const int N = 50000 + 100;
struct road {
  int w, to;
  road(int A, int B) { to = A, w = B; }
};
vector<road> e[N];
int n, K, size[N], t_size, root;
bool t_vis[N], vis[N], done[N];
void GetSize(int now) {
  t_vis[now] = true;
  size[now] = 1;
  for (int i = 0; i < int(e[now].size()); i++)
    if (t_vis[e[now][i].to] == false and vis[e[now][i].to] == false) {
      GetSize(e[now][i].to);
      size[now] += size[e[now][i].to];
    }
  t_vis[now] = false;
}
void GetRoot(int now) {
  t_vis[now] = true;
  int OK = true, size_now = 1;
  for (int i = 0; i < int(e[now].size()); i++)
    if (t_vis[e[now][i].to] == false and vis[e[now][i].to] == false) {
      GetRoot(e[now][i].to);
      size_now += size[e[now][i].to];
      if (size[e[now][i].to] > (t_size / 2)) OK = false;
    }
  if (t_size - size_now > (t_size / 2)) OK = false;
  if (OK == true) root = now;
  t_vis[now] = false;
}
int cnt[N], ans;
void dfs2(int now, int dis, int type) {
  t_vis[now] = true;
  if (type == 1 and K - dis >= 0) ans += cnt[K - dis];
  if (type == 2) cnt[dis]++;
  if (type == 3) cnt[dis]--;
  for (int i = 0; i < int(e[now].size()); i++)
    if (t_vis[e[now][i].to] == false and done[e[now][i].to] == true)
      dfs2(e[now][i].to, dis + e[now][i].w, type);
  t_vis[now] = false;
}
void dfs(int now) {
  vis[now] = true;
  vector<road> son;
  son.reserve(32);
  for (int i = 0; i < int(e[now].size()); i++)
    if (vis[e[now][i].to] == false) {
      GetSize(e[now][i].to), t_size = size[e[now][i].to];
      GetRoot(e[now][i].to);
      dfs(root);
      son.push_back(e[now][i]);
    }
  for (int i = 0; i < int(son.size()); i++)
    dfs2(son[i].to, son[i].w, 1), dfs2(son[i].to, son[i].w, 2);
  for (int i = 0; i < int(son.size()); i++) dfs2(son[i].to, son[i].w, 3);
  done[now] = true;
}
int main() {
  n = read(), K = read();
  for (int i = 1; i <= n; i++) e[i].reserve(4);
  for (int i = 1; i < n; i++) {
    int s = read(), t = read();
    e[s].push_back(road(t, 1));
    e[t].push_back(road(s, 1));
  }
  cnt[0]++;
  GetSize(1), t_size = size[1];
  GetRoot(1);
  dfs(root);
  printf("%d", ans);
  return 0;
}

```