#include <bits/stdc++.h>
using namespace std;
int n, k;
stack<int> finalOrder;
int par[202020];
long long sz[202020];
long long ans = 0;
class Graph {
 private:
  int mNodeCount;

 public:
  vector<int> edge[201010];

 public:
  Graph(int nodeCount) {
    mNodeCount = nodeCount;
    return;
  }
  void addEdge(int u, int v) {
    edge[u].push_back(v);
    edge[v].push_back(u);
  }
  void getParent(int root, int par[], stack<int> &w) {
    for (int i = 0; i <= mNodeCount; i++) par[i] = -1;
    queue<int> bank;
    bank.push(root);
    while (!bank.empty()) {
      int cur = bank.front();
      bank.pop();
      w.push(cur);
      for (int i = 0; i < edge[cur].size(); i++) {
        int tar = edge[cur][i];
        if (par[cur] == tar) continue;
        par[tar] = cur;
        bank.push(tar);
      }
    }
  }
};
Graph tree(200007);
struct info {
  long long sure;
  long long bonus[7];
  long long cnt[7];
};
info dp[202020];
info evolve(info old) {
  info tmp;
  for (int i = 0; i < k - 1; i++) {
    tmp.bonus[i] = old.bonus[i + 1];
    tmp.cnt[i] = old.cnt[i + 1];
  }
  tmp.bonus[k - 1] = old.bonus[0] + old.cnt[0];
  tmp.cnt[k - 1] = old.cnt[0];
  return tmp;
}
void calculation(int node) {
  sz[node] = 1;
  for (int i = 0; i < tree.edge[node].size(); i++) {
    int tar = tree.edge[node][i];
    if (tar == par[node]) continue;
    sz[node] += sz[tar];
  }
  ans += sz[node] * (n - sz[node]);
  for (int i = 0; i < tree.edge[node].size(); i++) {
    int tar = tree.edge[node][i];
    if (tar == par[node]) continue;
    for (int j = 0; j < k; j++)
      dp[node].bonus[j] += dp[tar].bonus[(j - 1 + k) % k];
  }
  long long headBonus = 0;
  for (int i = 0; i < k; i++) {
    long long req = (k - i) % k;
    headBonus += req * dp[node].bonus[i];
  }
  ans += headBonus;
  long long penalty = 0;
  for (int i = 0; i < tree.edge[node].size(); i++) {
    int tar = tree.edge[node][i];
    if (tar == par[node]) continue;
    for (int j1 = 0; j1 < k; j1++)
      for (int j2 = 0; j2 < k; j2++) {
        long long sm = (j1 + j2) % k;
        long long req = (k - sm) % k;
        penalty += req * dp[tar].bonus[(j1 - 1 + k) % k] *
                   (dp[node].bonus[j2] - dp[tar].bonus[(j2 - 1 + k) % k]);
      }
  }
  ans += penalty / 2;
  dp[node].bonus[0]++;
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i < n; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    tree.addEdge(u, v);
  }
  tree.getParent(1, par, finalOrder);
  for (int i = 1; i <= n; i++) {
    dp[i].sure = 0;
    for (int j = 0; j < k; j++) dp[i].bonus[j] = 0;
    for (int j = 0; j < k; j++) dp[i].cnt[j] = 0;
  }
  while (!finalOrder.empty()) {
    int cur = finalOrder.top();
    finalOrder.pop();
    calculation(cur);
  }
  printf("%I64d\n", ans / k);
  return 0;
}

### Prompt

Please create a solution in cpp to the following problem:

A tree is an undirected connected graph without cycles. The distance between two vertices is the number of edges in a simple path between them.

Limak is a little polar bear. He lives in a tree that consists of n vertices, numbered 1 through n.

Limak recently learned how to jump. He can jump from a vertex to any vertex within distance at most k.

For a pair of vertices (s, t) we define f(s, t) as the minimum number of jumps Limak needs to get from s to t. Your task is to find the sum of f(s, t) over all pairs of vertices (s, t) such that s < t.

Input

The first line of the input contains two integers n and k (2 ≤ n ≤ 200 000, 1 ≤ k ≤ 5) — the number of vertices in the tree and the maximum allowed jump distance respectively.

The next n - 1 lines describe edges in the tree. The i-th of those lines contains two integers ai and bi (1 ≤ ai, bi ≤ n) — the indices on vertices connected with i-th edge.

It's guaranteed that the given edges form a tree.

Output

Print one integer, denoting the sum of f(s, t) over all pairs of vertices (s, t) such that s < t.

Examples

Input

6 2
1 2
1 3
2 4
2 5
4 6


Output

20


Input

13 3
1 2
3 2
4 2
5 2
3 6
10 6
6 7
6 13
5 8
5 9
9 11
11 12


Output

114


Input

3 5
2 1
3 1


Output

3

Note

In the first sample, the given tree has 6 vertices and it's displayed on the drawing below. Limak can jump to any vertex within distance at most 2. For example, from the vertex 5 he can jump to any of vertices: 1, 2 and 4 (well, he can also jump to the vertex 5 itself).

<image>

There are <image> pairs of vertices (s, t) such that s < t. For 5 of those pairs Limak would need two jumps: (1, 6), (3, 4), (3, 5), (3, 6), (5, 6). For other 10 pairs one jump is enough. So, the answer is 5·2 + 10·1 = 20.

In the third sample, Limak can jump between every two vertices directly. There are 3 pairs of vertices (s < t), so the answer is 3·1 = 3.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int n, k;
stack<int> finalOrder;
int par[202020];
long long sz[202020];
long long ans = 0;
class Graph {
 private:
  int mNodeCount;

 public:
  vector<int> edge[201010];

 public:
  Graph(int nodeCount) {
    mNodeCount = nodeCount;
    return;
  }
  void addEdge(int u, int v) {
    edge[u].push_back(v);
    edge[v].push_back(u);
  }
  void getParent(int root, int par[], stack<int> &w) {
    for (int i = 0; i <= mNodeCount; i++) par[i] = -1;
    queue<int> bank;
    bank.push(root);
    while (!bank.empty()) {
      int cur = bank.front();
      bank.pop();
      w.push(cur);
      for (int i = 0; i < edge[cur].size(); i++) {
        int tar = edge[cur][i];
        if (par[cur] == tar) continue;
        par[tar] = cur;
        bank.push(tar);
      }
    }
  }
};
Graph tree(200007);
struct info {
  long long sure;
  long long bonus[7];
  long long cnt[7];
};
info dp[202020];
info evolve(info old) {
  info tmp;
  for (int i = 0; i < k - 1; i++) {
    tmp.bonus[i] = old.bonus[i + 1];
    tmp.cnt[i] = old.cnt[i + 1];
  }
  tmp.bonus[k - 1] = old.bonus[0] + old.cnt[0];
  tmp.cnt[k - 1] = old.cnt[0];
  return tmp;
}
void calculation(int node) {
  sz[node] = 1;
  for (int i = 0; i < tree.edge[node].size(); i++) {
    int tar = tree.edge[node][i];
    if (tar == par[node]) continue;
    sz[node] += sz[tar];
  }
  ans += sz[node] * (n - sz[node]);
  for (int i = 0; i < tree.edge[node].size(); i++) {
    int tar = tree.edge[node][i];
    if (tar == par[node]) continue;
    for (int j = 0; j < k; j++)
      dp[node].bonus[j] += dp[tar].bonus[(j - 1 + k) % k];
  }
  long long headBonus = 0;
  for (int i = 0; i < k; i++) {
    long long req = (k - i) % k;
    headBonus += req * dp[node].bonus[i];
  }
  ans += headBonus;
  long long penalty = 0;
  for (int i = 0; i < tree.edge[node].size(); i++) {
    int tar = tree.edge[node][i];
    if (tar == par[node]) continue;
    for (int j1 = 0; j1 < k; j1++)
      for (int j2 = 0; j2 < k; j2++) {
        long long sm = (j1 + j2) % k;
        long long req = (k - sm) % k;
        penalty += req * dp[tar].bonus[(j1 - 1 + k) % k] *
                   (dp[node].bonus[j2] - dp[tar].bonus[(j2 - 1 + k) % k]);
      }
  }
  ans += penalty / 2;
  dp[node].bonus[0]++;
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i < n; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    tree.addEdge(u, v);
  }
  tree.getParent(1, par, finalOrder);
  for (int i = 1; i <= n; i++) {
    dp[i].sure = 0;
    for (int j = 0; j < k; j++) dp[i].bonus[j] = 0;
    for (int j = 0; j < k; j++) dp[i].cnt[j] = 0;
  }
  while (!finalOrder.empty()) {
    int cur = finalOrder.top();
    finalOrder.pop();
    calculation(cur);
  }
  printf("%I64d\n", ans / k);
  return 0;
}

```