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 N = 400005;
struct edge {
  int to, next;
} e[N * 2];
int head[N], tot, n, Q;
int sz[N], dep[N], fa[N], co[N];
int top[N], dfn[N], ed[N], pos[N];
void add(int x, int y) {
  e[++tot] = (edge){y, head[x]};
  head[x] = tot;
}
void dfs1(int x) {
  sz[x] = 1;
  dep[x] = dep[fa[x]] + 1;
  for (int i = head[x]; i; i = e[i].next)
    if (e[i].to != fa[x]) {
      fa[e[i].to] = x;
      dfs1(e[i].to);
      sz[x] += sz[e[i].to];
    }
}
void dfs2(int x, int tp) {
  dfn[x] = ++*dfn;
  pos[*dfn] = x;
  int k = 0;
  top[x] = tp;
  ed[x] = x;
  for (int i = head[x]; i; i = e[i].next)
    if (e[i].to != fa[x] && sz[e[i].to] > sz[k]) k = e[i].to;
  if (k) dfs2(k, tp), ed[x] = ed[k];
  for (int i = head[x]; i; i = e[i].next)
    if (e[i].to != fa[x] && e[i].to != k) dfs2(e[i].to, e[i].to);
}
struct info {
  long long sum;
  int sl, sr, s;
  info operator+(const info &a) const {
    info ans;
    ans.sum = sum + a.sum + 2ll * sr * a.sl;
    ans.s = s + a.s;
    ans.sl = (sl == s ? sl + a.sl : sl);
    ans.sr = (a.sr == a.s ? sr + a.sr : a.sr);
    return ans;
  }
} t[N * 3], T[N * 3];
int L, stk[25], vis[N];
long long ans[N];
void update(int k) {
  for (k = (k + L) >> 1; k; k >>= 1) t[k] = t[k * 2] + t[k * 2 + 1];
}
info query(int l, int r) {
  l = l + L - 1, r = r + L + 1;
  info ls = (info){0, 0, 0, 0}, rs = ls;
  for (; l ^ r ^ 1; l >>= 1, r >>= 1) {
    if (!(l & 1)) ls = ls + t[l ^ 1];
    if (r & 1) rs = t[r ^ 1] + rs;
  }
  return ls + rs;
}
void build() {
  for (L = 1; L <= n + 2; L <<= 1)
    ;
  for (int i = (int)(1); i <= (int)(n); i++) {
    t[dfn[i] + L] = (info){1, 1, 1, 1};
    T[dfn[i] + L].s = 1;
  }
  for (int i = (int)(n); i >= (int)(1); i--) {
    int x = pos[i];
    update(i);
    if (top[x] == x && x != 1) {
      info tmp = query(dfn[x], dfn[ed[x]]);
      int f = fa[x], pf = dfn[fa[x]];
      t[pf + L].sum += tmp.sum + 2ll * t[pf + L].sl * tmp.sl;
      T[pf + L].sum += tmp.sum;
      t[pf + L].s += tmp.sl;
      t[pf + L].sl += tmp.sl;
      t[pf + L].sr += tmp.sl;
    }
  }
}
void Update(int x) {
  int cnt = 0;
  for (int y = top[x]; y != 1; y = top[fa[y]]) stk[++cnt] = y;
  for (int i = (int)(cnt); i >= (int)(1); i--) {
    int x = stk[i];
    info tmp = query(dfn[x], dfn[ed[x]]);
    int f = fa[x], pf = dfn[fa[x]];
    if (vis[f]) swap(t[pf + L], T[pf + L]);
    t[pf + L].s -= tmp.sl;
    t[pf + L].sl -= tmp.sl;
    t[pf + L].sr -= tmp.sl;
    t[pf + L].sum -= tmp.sum + 2ll * t[pf + L].sl * tmp.sl;
    T[pf + L].sum -= tmp.sum;
    if (vis[f]) swap(t[pf + L], T[pf + L]);
  }
  swap(t[dfn[x] + L], T[dfn[x] + L]);
  update(dfn[x]);
  vis[x] ^= 1;
  for (int i = (int)(1); i <= (int)(cnt); i++) {
    int x = stk[i];
    info tmp = query(dfn[x], dfn[ed[x]]);
    int f = fa[x], pf = dfn[fa[x]];
    if (vis[f]) swap(t[pf + L], T[pf + L]);
    t[pf + L].sum += tmp.sum + 2ll * t[pf + L].sl * tmp.sl;
    T[pf + L].sum += tmp.sum;
    t[pf + L].s += tmp.sl;
    t[pf + L].sl += tmp.sl;
    t[pf + L].sr += tmp.sl;
    if (vis[f]) swap(t[pf + L], T[pf + L]);
    update(pf);
  }
}
vector<pair<int, int> > vec[N];
int main() {
  scanf("%d%d", &n, &Q);
  for (int i = (int)(1); i <= (int)(n); i++) {
    scanf("%d", &co[i]);
    vec[co[i]].push_back(pair<int, int>(i, 0));
  }
  for (int i = (int)(1); i <= (int)(n - 1); i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    add(x, y);
    add(y, x);
  }
  dfs1(1);
  dfs2(1, 1);
  for (int i = (int)(1); i <= (int)(Q); i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    vec[co[x]].push_back(pair<int, int>(x, i));
    vec[co[x] = y].push_back(pair<int, int>(x, i));
  }
  build();
  for (int i = (int)(1); i <= (int)(n); i++) {
    int sz = vec[i].size();
    ans[0] += 1ll * n * n;
    for (int j = 0, k; j < sz; j = k + 1) {
      for (k = j; k + 1 < sz && vec[i][k + 1].second == vec[i][j].second; ++k)
        ;
      ans[vec[i][j].second] -= query(1, dfn[ed[1]]).sum;
      for (int p = (int)(j); p <= (int)(k); p++) Update(vec[i][p].first);
      ans[vec[i][j].second] += query(1, dfn[ed[1]]).sum;
    }
    for (int j = (int)(0); j <= (int)(sz - 1); j++)
      if (vis[vec[i][j].first]) Update(vec[i][j].first);
  }
  for (int i = (int)(1); i <= (int)(Q); i++) ans[i] += ans[i - 1];
  for (int i = (int)(0); i <= (int)(Q); i++)
    printf("%lld\n", 1ll * n * n * n - ans[i]);
}