#include <bits/stdc++.h>
using namespace std;
long long n, k;
vector<long long> g[100100];
bool cnt[100100];
bool used[100100];
long long dp[100100];
long long w[100100];
long long ww[100100];
long long tt;
long long dfs(int v, int p) {
  dp[v] = 0;
  tt++;
  for (int i = 0; i < g[v].size(); i++) {
    long long to = g[v][i];
    if (to != p && !cnt[to]) {
      dp[v] += dfs(to, v);
    }
  }
  dp[v]++;
  return dp[v];
}
long long findCentroid(int v, int p) {
  long long mmax = 0;
  long long nnext = -1;
  for (int i = 0; i < g[v].size(); i++) {
    long long to = g[v][i];
    if (to != p && !cnt[to]) {
      if (dp[to] > mmax) {
        mmax = dp[to];
        nnext = to;
      }
    }
  }
  if (tt / 2 < mmax && nnext != -1) {
    return findCentroid(nnext, v);
  } else {
    return v;
  }
}
long long StartfindCentroid(int v) {
  tt = 0;
  dfs(v, -1);
  long long c = findCentroid(v, -1);
  return c;
}
void solve(long long v, long long kk, long long p) {
  if (kk > k) return;
  w[kk]++;
  for (int i = 0; i < g[v].size(); i++) {
    long long to = g[v][i];
    if (to != p && !cnt[to]) {
      solve(to, kk + 1, v);
    }
  }
}
long long sol = 0;
void Stsolve(long long v) {
  cnt[v] = 1;
  long long mmaxk = 0;
  for (int i = 0; i < g[v].size(); i++) {
    long long to = g[v][i];
    if (!cnt[to]) {
      solve(to, 1, v);
      for (int i = 1; i < k; i++) {
        if (w[i] == 0) break;
        mmaxk = max(mmaxk, k);
        sol += (w[i] * ww[k - i]);
      }
      for (int i = 1; i < k; i++) {
        if (w[i] == 0) break;
        ww[i] += w[i];
        w[i] = 0;
      }
      sol += w[k];
      w[k] = 0;
    }
  }
  for (int i = 0; i <= mmaxk + 1; i++) {
    ww[i] = 0;
  }
  ww[k] = 0;
  for (int i = 0; i < g[v].size(); i++) {
    long long to = g[v][i];
    if (!cnt[to]) {
      long long c = StartfindCentroid(to);
      Stsolve(c);
    }
  }
  return;
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> k;
  for (int i = 0; i < n - 1; i++) {
    long long a, b;
    cin >> a >> b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  long long c = StartfindCentroid(1);
  Stsolve(c);
  cout << sol << endl;
  return 0;
}

### Prompt

Please formulate 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;
long long n, k;
vector<long long> g[100100];
bool cnt[100100];
bool used[100100];
long long dp[100100];
long long w[100100];
long long ww[100100];
long long tt;
long long dfs(int v, int p) {
  dp[v] = 0;
  tt++;
  for (int i = 0; i < g[v].size(); i++) {
    long long to = g[v][i];
    if (to != p && !cnt[to]) {
      dp[v] += dfs(to, v);
    }
  }
  dp[v]++;
  return dp[v];
}
long long findCentroid(int v, int p) {
  long long mmax = 0;
  long long nnext = -1;
  for (int i = 0; i < g[v].size(); i++) {
    long long to = g[v][i];
    if (to != p && !cnt[to]) {
      if (dp[to] > mmax) {
        mmax = dp[to];
        nnext = to;
      }
    }
  }
  if (tt / 2 < mmax && nnext != -1) {
    return findCentroid(nnext, v);
  } else {
    return v;
  }
}
long long StartfindCentroid(int v) {
  tt = 0;
  dfs(v, -1);
  long long c = findCentroid(v, -1);
  return c;
}
void solve(long long v, long long kk, long long p) {
  if (kk > k) return;
  w[kk]++;
  for (int i = 0; i < g[v].size(); i++) {
    long long to = g[v][i];
    if (to != p && !cnt[to]) {
      solve(to, kk + 1, v);
    }
  }
}
long long sol = 0;
void Stsolve(long long v) {
  cnt[v] = 1;
  long long mmaxk = 0;
  for (int i = 0; i < g[v].size(); i++) {
    long long to = g[v][i];
    if (!cnt[to]) {
      solve(to, 1, v);
      for (int i = 1; i < k; i++) {
        if (w[i] == 0) break;
        mmaxk = max(mmaxk, k);
        sol += (w[i] * ww[k - i]);
      }
      for (int i = 1; i < k; i++) {
        if (w[i] == 0) break;
        ww[i] += w[i];
        w[i] = 0;
      }
      sol += w[k];
      w[k] = 0;
    }
  }
  for (int i = 0; i <= mmaxk + 1; i++) {
    ww[i] = 0;
  }
  ww[k] = 0;
  for (int i = 0; i < g[v].size(); i++) {
    long long to = g[v][i];
    if (!cnt[to]) {
      long long c = StartfindCentroid(to);
      Stsolve(c);
    }
  }
  return;
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> k;
  for (int i = 0; i < n - 1; i++) {
    long long a, b;
    cin >> a >> b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  long long c = StartfindCentroid(1);
  Stsolve(c);
  cout << sol << endl;
  return 0;
}

```