Problem: Nauuo is a girl who loves traveling.

One day she went to a tree, Old Driver Tree, literally, a tree with an old driver on it.

The tree is a connected graph consisting of n nodes and n-1 edges. Each node has a color, and Nauuo will visit the ODT through a simple path on the tree in the old driver's car.

Nauuo wants to visit see more different colors in her journey, but she doesn't know which simple path she will be traveling on. So, she wants to calculate the sum of the numbers of different colors on all different paths. Can you help her?

What's more, the ODT is being redecorated, so there will be m modifications, each modification will change a single node's color. Nauuo wants to know the answer after each modification too.

Note that in this problem, we consider the simple path from u to v and the simple path from v to u as two different simple paths if and only if u≠ v.

Input

The first line contains two integers n and m (2≤ n≤ 4⋅ 10^5, 1≤ m≤ 4⋅ 10^5) — the number of nodes and the number of modifications.

The second line contains n integers c_1,c_2,…,c_n (1≤ c_i≤ n), where c_i is the initial color of node i.

Each of the next n-1 lines contains two integers u and v (1≤ u,v≤ n), denoting there is an edge between u and v. It is guaranteed that the given edges form a tree.

Each of the next m lines contains two integers u and x (1≤ u,x≤ n), which means a modification that changes the color of node u into x.

Output

The output contains m+1 integers — the first integer is the answer at the beginning, the rest integers are the answers after every modification in the given order.

Examples

Input


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


Output


47
51
49
45


Input


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


Output


36
46

Note

Example 1

<image>

The number of colors on each simple path at the beginning:

<image>

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 4e5 + 200;
int n, q, head[MAX_N], current, up[MAX_N], ch[MAX_N][2], fa[MAX_N], siz[MAX_N],
    vsiz[MAX_N], color[MAX_N];
vector<int> opts[MAX_N][2];
long long vsiz2[MAX_N], ans, delta[MAX_N];
bool tag[MAX_N];
struct edge {
  int to, nxt;
} edges[MAX_N << 1];
long long siz2(int p) { return 1LL * siz[p] * siz[p]; }
void addpath(int src, int dst) {
  edges[current].to = dst, edges[current].nxt = head[src];
  head[src] = current++;
}
void dfs(int u) {
  for (int i = head[u]; i != -1; i = edges[i].nxt)
    if (edges[i].to != up[u]) up[edges[i].to] = u, dfs(edges[i].to);
}
void pushup(int p) { siz[p] = siz[(ch[p][0])] + siz[(ch[p][1])] + vsiz[p] + 1; }
bool isRoot(int p) { return ch[fa[p]][1] != p && ch[fa[p]][0] != p; }
int check(int p) { return ch[fa[p]][1] == p; }
void rotate(int x) {
  int y = fa[x], z = fa[y], dir = check(x), w = ch[x][dir ^ 1];
  fa[x] = z;
  if (!isRoot(y)) ch[z][check(y)] = x;
  fa[y] = x, ch[x][dir ^ 1] = y;
  fa[w] = y, ch[y][dir] = w;
  pushup(y), pushup(x);
}
void splay(int p) {
  for (int fat = fa[p]; fat = fa[p], !isRoot(p); rotate(p))
    if (!isRoot(fat)) rotate(check(fat) == check(p) ? fat : p);
  pushup(p);
}
void access(int p) {
  for (int pre = 0; p; pre = p, p = fa[p])
    splay(p), vsiz[p] += siz[(ch[p][1])] - siz[pre],
        vsiz2[p] += siz2((ch[p][1])) - siz2(pre), (ch[p][1]) = pre, pushup(p);
}
int find(int p) {
  access(p), splay(p);
  while ((ch[p][0])) p = (ch[p][0]);
  splay(p);
  return p;
}
void link(int p) {
  int fat = up[p];
  splay(p), ans -= vsiz2[p] + siz2((ch[p][1]));
  int rt = find(fat);
  access(p), splay(rt), ans -= siz2(ch[rt][1]);
  fa[p] = fat, splay(fat), vsiz[fat] += siz[p], vsiz2[fat] += siz2(p);
  pushup(fat), access(p), splay(rt), ans += siz2(ch[rt][1]);
}
void cut(int p) {
  int fat = up[p];
  access(p), ans += vsiz2[p];
  int rt = find(fat);
  access(p), splay(rt), ans -= siz2(ch[rt][1]);
  splay(p), (ch[p][0]) = fa[(ch[p][0])] = 0, pushup(p), splay(rt),
            ans += siz2(ch[rt][1]);
}
int main() {
  memset(head, -1, sizeof(head));
  scanf("%d%d", &n, &q);
  for (int i = 1; i <= n; i++)
    scanf("%d", &color[i]), opts[color[i]][0].push_back(i),
        opts[color[i]][1].push_back(0);
  for (int i = 1; i <= n + 1; i++) siz[i] = 1;
  for (int i = 1, u, v; i <= n - 1; i++)
    scanf("%d%d", &u, &v), addpath(u, v), addpath(v, u);
  for (int i = 1, u, v; i <= q; i++) {
    scanf("%d%d", &u, &v);
    opts[color[u]][0].push_back(u), opts[color[u]][1].push_back(i);
    color[u] = v;
    opts[color[u]][0].push_back(u), opts[color[u]][1].push_back(i);
  }
  long long last = 0;
  up[1] = n + 1, dfs(1);
  for (int i = 1; i <= n; i++) link(i);
  for (int i = 1; i <= n; i++) {
    if (opts[i][0].empty()) {
      delta[0] += 1LL * n * n;
      continue;
    }
    if (opts[i][1][0])
      delta[0] += 1LL * n * n, last = 1LL * n * n;
    else
      last = 0;
    for (int j = 0, siz = opts[i][0].size(); j < siz; j++) {
      int u = opts[i][0][j];
      if (tag[u])
        link(u);
      else
        cut(u);
      tag[u] ^= 1;
      if (j == opts[i][0].size() - 1 || opts[i][1][j] != opts[i][1][j + 1]) {
        delta[opts[i][1][j]] += ans - last;
        last = ans;
      }
    }
    for (int j = opts[i][0].size() - 1; j >= 0; j--) {
      int u = opts[i][0][j];
      if (tag[u])
        link(u);
      else
        cut(u);
      tag[u] ^= 1;
    }
  }
  ans = 1LL * n * n * n;
  for (int i = 0; i <= q; i++) ans -= delta[i], printf("%lld\n", ans);
  return 0;
}