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>
#pragma GCC optimize("Ofast")
using namespace std;
const int N = 4e5 + 5;
int n, q, cnt, ti, col[N], a[N], hd[N], dep[N], fa[N], hv[N], sz[N], dfn[N],
    xl[N], top[N];
long long ans, ANS[N], L[N];
struct edge {
  int tt, nxt;
} e[N << 1];
vector<pair<int, int> > Q[N];
long long sqr(int x) { return 1ll * x * x; }
void addedge(int u, int v) { e[++cnt] = (edge){v, hd[u]}, hd[u] = cnt; }
void dfs(int x) {
  dep[x] = dep[fa[x]] + 1, sz[x] = 1;
  for (int i = hd[x]; i; i = e[i].nxt) {
    int v = e[i].tt;
    if (!dep[v]) {
      fa[v] = x, dfs(v), sz[x] += sz[v];
      if (!hv[x] || sz[hv[x]] < sz[v]) hv[x] = v;
    }
  }
}
void dfs2(int x, int t) {
  xl[dfn[x] = ++ti] = x, top[x] = t;
  if (hv[x]) dfs2(hv[x], t);
  for (int i = hd[x]; i; i = e[i].nxt) {
    int v = e[i].tt;
    if (v != fa[x] && v != hv[x]) dfs2(v, v);
  }
}
struct BIT {
  int c[N];
  void A(int o, int w) {
    while (o <= n) c[o] += w, o += (o & -o);
  }
  int S(int o) {
    int s = 0;
    while (o) s += c[o], o -= (o & -o);
    return s;
  }
} F, W, H;
int fd(int x) {
  int y = x;
  if (x == 1) return 1;
  x = fa[x];
  while (x) {
    if (F.S(dfn[x]) - F.S(dfn[top[x]] - 1)) break;
    y = top[x], x = fa[y];
  }
  if (!x) return 1;
  int l = dfn[top[x]], r = dfn[x], s = F.S(dfn[x]);
  while (l <= r) {
    int mid = (l + r) >> 1;
    if (F.S(mid - 1) < s)
      l = mid + 1;
    else
      y = xl[mid], r = mid - 1;
  }
  return y;
}
void chg(int x) {
  a[x] ^= 1;
  int y = fd(x), t = (a[x] ? 1 : -1);
  if (t < 0 || x != y) ans -= sqr(W.S(dfn[y]));
  if (x != 1) {
    int u = fa[x], v = (y > 1 ? fa[y] : y);
    int w = W.S(dfn[x]);
    if (x == hv[u])
      H.A(dfn[u], t * w), H.A(dfn[u] + 1, -t * w);
    else
      L[u] += 1ll * t * w * w;
    while (top[u] != top[v]) {
      W.A(dfn[top[u]], t * w), W.A(dfn[u] + 1, -t * w);
      if (u != top[u]) H.A(dfn[top[u]], t * w), H.A(dfn[u], -t * w);
      int c = W.S(dfn[top[u]]);
      long long cc = 1ll * c * c;
      u = fa[top[u]], L[u] += cc - sqr(c - t * w);
    }
    W.A(dfn[v], t * w), W.A(dfn[u] + 1, -t * w);
    if (u != v) H.A(dfn[v], t * w), H.A(dfn[u], -t * w);
  }
  if (t > 0 || x != y) ans += sqr(W.S(dfn[y]));
  ans -= t * (sqr(H.S(dfn[x])) + L[x]), F.A(dfn[x], -t);
}
int main() {
  scanf("%d%d", &n, &q);
  for (int i = (1); i <= (n); ++i)
    scanf("%d", &col[i]), Q[col[i]].push_back(make_pair(i, 0));
  for (int i = (2); i <= (n); ++i) {
    int u, v;
    scanf("%d%d", &u, &v);
    addedge(u, v), addedge(v, u);
  }
  for (int i = (1); i <= (q); ++i) {
    int x, c;
    scanf("%d%d", &x, &c);
    Q[col[x]].push_back(make_pair(x, i)), Q[c].push_back(make_pair(x, i));
    col[x] = c;
  }
  dfs(1), dfs2(1, 1);
  ans = 1ll * n * n;
  for (int x = (1); x <= (n); ++x) {
    a[x] = 1, W.A(dfn[x], sz[x]), W.A(dfn[x] + 1, -sz[x]);
    if (hv[x]) H.A(dfn[x], sz[hv[x]]), H.A(dfn[x] + 1, -sz[hv[x]]);
    for (int i = hd[x]; i; i = e[i].nxt) {
      int v = e[i].tt;
      if (v != fa[x] && v != hv[x]) L[x] += 1ll * sz[v] * sz[v];
    }
  }
  for (int i = (1); i <= (n); ++i)
    if (Q[i].size()) {
      for (vector<pair<int, int> >::iterator it = Q[i].begin(); it < Q[i].end();
           ++it) {
        long long tmp = ans;
        chg(it->first), ANS[it->second] += tmp - ans;
      }
      for (vector<pair<int, int> >::iterator it = Q[i].begin(); it < Q[i].end();
           ++it)
        chg(it->first);
    }
  for (int i = (1); i <= (q); ++i) ANS[i] += ANS[i - 1];
  for (int i = (0); i <= (q); ++i) printf("%lld\n", ANS[i]);
  return 0;
}