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 = 1e6 + 7;
bool fl[N];
long long ans, f1[N], f2[N], f3[N], f4[N];
int n, q, k, tp, og, lt[N], rt[N], fp[N], c[N], ft[N], dft[N], dfn[N], dfx[N],
    fa[N], ch[N], siz[N];
vector<int> v[N];
struct node {
  int u, t;
} e[N];
vector<node> g[N];
inline int read() {
  int num = 0;
  char g = getchar();
  while (g < 48 || 57 < g) g = getchar();
  while (47 < g && g < 58)
    num = (num << 1) + (num << 3) + g - 48, g = getchar();
  return num;
}
inline void add1(int u, long long c) {
  while (u <= n + 1) f1[u] += c, u += (u & (-u));
}
inline long long get1(int u) {
  long long sum = 0;
  while (u > 0) sum += f1[u], u -= (u & (-u));
  return sum;
}
inline void add3(int u, long long c) {
  while (u <= n + 1) f3[u] += c, u += (u & (-u));
}
inline long long get3(int u) {
  long long sum = 0;
  while (u > 0) sum += f3[u], u -= (u & (-u));
  return sum;
}
inline void add4(int u, long long c) {
  while (u <= n + 1) f4[u] += c, u += (u & (-u));
}
inline long long get4(int u) {
  long long sum = 0;
  while (u > 0) sum += f4[u], u -= (u & (-u));
  return sum;
}
inline void add2(int u, long long c) {
  while (u <= q + 1) f2[u] += c, u += (u & (-u));
}
inline long long get2(int u) {
  long long sum = 0;
  while (u > 0) sum += f2[u], u -= (u & (-u));
  return sum;
}
inline void dfs1(int u) {
  siz[u] = 1;
  for (int i = 0; i < v[u].size(); i++) {
    int x = v[u][i];
    if (fa[u] == x) continue;
    fa[x] = u, dfs1(x), siz[u] += siz[x];
    if (siz[ch[u]] < siz[x]) ch[u] = x;
  }
}
inline void dfs2(int u) {
  dfn[u] = dft[u] = ++k, fp[k] = u;
  if (!ft[u]) ft[u] = u;
  if (ch[u]) ft[ch[u]] = ft[u], dfs2(ch[u]), dft[u] = dft[ch[u]];
  for (int i = 0; i < v[u].size(); i++) {
    int x = v[u][i];
    if (fa[u] == x || ch[u] == x) continue;
    dfs2(x), dft[u] = dft[x];
  }
}
inline void dfs3(int u) {
  if (!dfx[u]) dfx[u] = ++tp;
  add4(dfx[u], 1ll * siz[u] * siz[u]);
  for (int i = 0; i < v[u].size(); i++) {
    int x = v[u][i];
    if (fa[u] == x || ch[u] == x) continue;
    dfx[x] = ++tp;
    if (!lt[u]) lt[u] = tp;
    rt[u] = tp;
  }
  for (int i = 0; i < v[u].size(); i++) {
    int x = v[u][i];
    if (fa[u] == x || ch[u] == x) continue;
    dfs3(x);
  }
  if (ch[u]) dfs3(ch[u]);
}
inline int getfa(int u) {
  u = fa[u];
  int pt = 0;
  while (u > 0) {
    if (get1(dfn[u]) - get1(dfn[ft[u]] - 1) > 0) {
      int l = dfn[u], r = dfn[ft[u]], p = pt;
      swap(l, r);
      while (l <= r) {
        int d = (l + r) >> 1;
        if (get1(dfn[u]) - get1(d - 1) == 0)
          p = d, r = d - 1;
        else
          l = d + 1;
      }
      return fp[p];
    }
    pt = dfn[ft[u]], u = fa[ft[u]];
  }
  return 0;
}
inline void add(int u) {
  og++;
  ans += get4(rt[u]) - get4(lt[u] - 1);
  if (ch[u]) {
    long long v = siz[ch[u]] - (get3(dft[ch[u]]) - get3(dfn[ch[u]] - 1));
    ans += v * v;
  }
  int c = siz[u] - (get3(dft[u]) - get3(dfn[u]));
  int x = getfa(u);
  add1(dfn[u], 1);
  if (x == 0) {
    ans = ans - 1ll * c * c;
    if (dfn[fa[u]] > 0) {
      long long v = get3(dft[u]) - get3(dfn[u] - 1);
      add3(dfn[u], siz[u] - v);
      add3(dfn[fa[u]], v - siz[u]);
    }
    return;
  }
  long long v = get3(dft[u]) - get3(dfn[u] - 1);
  add3(dfn[u], siz[u] - v);
  add3(dfn[fa[x]], v - siz[u]);
  int h = siz[x] - (get3(dft[x]) - get3(dfn[x]));
  ans = ans + 1ll * h * h - 1ll * (h + c) * (h + c),
  add4(dfx[x], 1ll * h * h - 1ll * (h + c) * (h + c));
}
inline void del(int u) {
  og--;
  ans -= get4(rt[u]) - get4(lt[u] - 1);
  if (ch[u]) {
    long long v = siz[ch[u]] - (get3(dft[ch[u]]) - get3(dfn[ch[u]] - 1));
    ans -= v * v;
  }
  int c = siz[u] - (get3(dft[u]) - get3(dfn[u]));
  add1(dfn[u], -1);
  int x = getfa(u);
  if (x == 0) {
    ans = ans + 1ll * c * c;
    if (dfn[fa[u]] > 0) {
      long long v = get3(dft[u]) - get3(dfn[u] - 1);
      add3(dfn[u], siz[u] - c - v);
      add3(dfn[fa[u]], v + c - siz[u]);
    }
    return;
  }
  long long v = get3(dft[u]) - get3(dfn[u] - 1);
  add3(dfn[u], siz[u] - c - v), add3(dfn[fa[x]], v + c - siz[u]);
  int h = siz[x] - (get3(dft[x]) - get3(dfn[x]));
  ans = ans + 1ll * h * h - 1ll * (h - c) * (h - c);
}
inline void updatex(int v) {
  long long c = siz[v] - (get3(dft[v]) - get3(dfn[v] - 1)),
            w = get4(dfx[v]) - get4(dfx[v] - 1);
  add4(dfx[v], c * c - w);
}
inline void update(int v) {
  while (v > 0) {
    updatex(ft[v]), v = fa[ft[v]];
  }
}
inline void getx(int u) {
  if (!fl[u])
    add(u), fl[u] ^= 1;
  else
    del(u), fl[u] ^= 1;
  update(u);
}
signed main() {
  n = read(), q = read();
  int u, t;
  for (int i = 1; i <= n; i++) {
    c[i] = read();
    node x;
    x.u = i, x.t = 0;
    g[c[i]].push_back(x);
  }
  for (int i = 1; i < n; i++)
    u = read(), t = read(), v[u].push_back(t), v[t].push_back(u);
  v[n + 1].push_back(1), v[1].push_back(n + 1);
  dfs1(n + 1), dfs2(n + 1), dfs3(n + 1);
  for (int i = 1; i <= q; i++) {
    u = read(), t = read();
    node x;
    x.u = u, x.t = i, g[c[u]].push_back(x), c[u] = t;
    x.u = u, x.t = i, g[c[u]].push_back(x);
  }
  getx(n + 1);
  for (int i = 1; i <= n; i++) {
    ans = 1ll * n * n, og = 0;
    for (int j = 0; j < g[i].size();) {
      int k = j;
      while (k < g[i].size() && g[i][j].t == g[i][k].t) getx(g[i][k].u), k++;
      if (k == g[i].size()) {
        add2(g[i][j].t + 1, 1ll * n * n - ans - og);
      } else {
        add2(g[i][j].t + 1, 1ll * n * n - ans - og);
        add2(g[i][k].t + 1, ans + og - 1ll * n * n);
      }
      j = k;
    }
    for (int j = 0; j < g[i].size(); j++)
      if (fl[g[i][j].u]) getx(g[i][j].u);
  }
  for (int i = 1; i <= q + 1; i++) printf("%lld\n", get2(i) + n);
}