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;
vector<pair<int, int> > qry[400010];
long long res[400010], ans;
set<int> B;
int father[400010], sum[400010], tag[400010], son[400010][2], sta[400010], top;
int cur[400010], pre[400010], head[400010], nxt[400010 * 2], a[400010 * 2],
    edge;
int mx[400010];
long long val[400010];
int read() {
  int tmp = 0;
  char c = getchar();
  while (c < '0' || c > '9') c = getchar();
  while (c >= '0' && c <= '9') {
    tmp = tmp * 10 + c - '0';
    c = getchar();
  }
  return tmp;
}
void create(int u, int v) {
  edge++;
  a[edge] = v;
  nxt[edge] = head[u];
  head[u] = edge;
}
void dfs(int u, int fa) {
  pre[u] = fa;
  for (int i = head[u]; i; i = nxt[i]) {
    int v = a[i];
    if (v != fa) dfs(v, u);
  }
}
bool rela(int x) { return son[father[x]][1] == x; }
bool isroot(int x) { return son[father[x]][1] != x && son[father[x]][0] != x; }
void pushdown(int x) {
  if (tag[x]) {
    int tmp = tag[x], l = son[x][0], r = son[x][1];
    if (l) {
      tag[l] += tmp;
      sum[l] += tmp;
      mx[l] += tmp;
    }
    if (r) {
      tag[r] += tmp;
      sum[r] += tmp;
      mx[r] += tmp;
    }
    tag[x] = 0;
  }
}
void update(int x) { mx[x] = max(max(mx[son[x][0]], mx[son[x][1]]), sum[x]); }
void rotate(int x) {
  int y = father[x], ch = rela(x);
  son[y][ch] = son[x][1 ^ ch];
  if (son[x][1 ^ ch]) father[son[x][1 ^ ch]] = y;
  father[x] = father[y];
  if (son[father[y]][0] == y)
    son[father[y]][0] = x;
  else if (son[father[y]][1] == y)
    son[father[y]][1] = x;
  father[y] = x;
  son[x][1 ^ ch] = y;
  update(y);
  update(x);
}
void splay(int x) {
  int tmp = x;
  while (!isroot(tmp)) {
    sta[++top] = tmp;
    tmp = father[tmp];
  }
  sta[++top] = tmp;
  while (top) {
    pushdown(sta[top]);
    top--;
  }
  while (!isroot(x)) {
    int y = father[x];
    if (isroot(y)) {
      rotate(x);
      return;
    }
    if (rela(x) == rela(y))
      rotate(y);
    else
      rotate(x);
    rotate(x);
  }
}
void access(int u) {
  int tmp = 0;
  while (u) {
    splay(u);
    int yuan = son[u][1], cur = mx[yuan];
    val[u] += (long long)cur * cur;
    son[u][1] = tmp;
    update(u);
    if (tmp) father[tmp] = u;
    cur = mx[tmp];
    val[u] -= (long long)cur * cur;
    tmp = u;
    u = father[u];
  }
}
int get_root(int u) {
  access(u);
  splay(u);
  int res = u;
  while (son[res][0]) res = son[res][0];
  return res;
}
void link(int u) {
  splay(u);
  int tmp = mx[u];
  father[u] = pre[u];
  val[pre[u]] += (long long)tmp * tmp;
  access(pre[u]);
  splay(pre[u]);
  tag[pre[u]] += tmp;
  sum[pre[u]] += tmp;
  mx[pre[u]] += tmp;
}
void cut(int u) {
  access(u);
  splay(u);
  int tmp = sum[u];
  tag[son[u][0]] -= tmp;
  sum[son[u][0]] -= tmp;
  mx[son[u][0]] -= tmp;
  father[son[u][0]] = 0;
  son[u][0] = 0;
  update(u);
}
void change(int u) {
  if (cur[u] == 1) {
    B.insert(u);
    cur[u] = 0;
    int v = get_root(u);
    access(v);
    ans -= val[v];
    cut(u);
    access(u);
    access(v);
    splay(u);
    splay(v);
    ans += val[u] + val[v];
  } else {
    B.erase(u);
    cur[u] = 1;
    int v = get_root(pre[u]);
    access(u);
    access(v);
    ans -= val[u] + val[v];
    link(u);
    access(v);
    ans += val[v];
  }
}
int main() {
  int n = read(), m = read();
  for (int i = 1; i <= n; i++) {
    int x = read();
    cur[i] = x;
    qry[x].push_back(make_pair(i, 0));
  }
  for (int i = 2; i <= n; i++) {
    int u = read(), v = read();
    create(u, v);
    create(v, u);
  }
  dfs(1, n + 1);
  for (int i = 1; i <= m; i++) {
    int x = read(), y = read();
    qry[cur[x]].push_back(make_pair(x, i));
    cur[x] = y;
    qry[cur[x]].push_back(make_pair(x, i));
  }
  for (int i = 1; i <= n + 1; i++) {
    sum[i] = mx[i] = 1;
    cur[i] = 0;
  }
  for (int i = 1; i <= n; i++) change(i);
  for (int i = 1; i <= n; i++) {
    int len = qry[i].size();
    long long pre = ans;
    res[0] += ans;
    for (int j = 0; j <= len - 1; j++) {
      pair<int, int> tmp = qry[i][j];
      change(tmp.first);
      if (j == len - 1 || tmp.second != qry[i][j + 1].second) {
        res[tmp.second] += ans - pre;
        pre = ans;
      }
    }
    while (!B.empty()) change(*(B.begin()));
  }
  for (int i = 0; i <= m; i++) {
    if (i) res[i] += res[i - 1];
    long long tmp = (long long)n * n * n - res[i];
    printf("%lld\n", tmp);
  }
  return 0;
}