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;
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#pragma GCC optimize("-fgcse")
#pragma GCC optimize("-fgcse-lm")
#pragma GCC optimize("-fipa-sra")
#pragma GCC optimize("-ftree-pre")
#pragma GCC optimize("-ftree-vrp")
#pragma GCC optimize("-fpeephole2")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-fsched-spec")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-falign-jumps")
#pragma GCC optimize("-falign-loops")
#pragma GCC optimize("-falign-labels")
#pragma GCC optimize("-fdevirtualize")
#pragma GCC optimize("-fcaller-saves")
#pragma GCC optimize("-fcrossjumping")
#pragma GCC optimize("-fthread-jumps")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-fwhole-program")
#pragma GCC optimize("-freorder-blocks")
#pragma GCC optimize("-fschedule-insns")
#pragma GCC optimize("inline-functions")
#pragma GCC optimize("-ftree-tail-merge")
#pragma GCC optimize("-fschedule-insns2")
#pragma GCC optimize("-fstrict-aliasing")
#pragma GCC optimize("-fstrict-overflow")
#pragma GCC optimize("-falign-functions")
#pragma GCC optimize("-fcse-skip-blocks")
#pragma GCC optimize("-fcse-follow-jumps")
#pragma GCC optimize("-fsched-interblock")
#pragma GCC optimize("-fpartial-inlining")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("-freorder-functions")
#pragma GCC optimize("-findirect-inlining")
#pragma GCC optimize("-frerun-cse-after-loop")
#pragma GCC optimize("inline-small-functions")
#pragma GCC optimize("-finline-small-functions")
#pragma GCC optimize("-ftree-switch-conversion")
#pragma GCC optimize("-foptimize-sibling-calls")
#pragma GCC optimize("-fexpensive-optimizations")
#pragma GCC optimize("-funsafe-loop-optimizations")
#pragma GCC optimize("inline-functions-called-once")
#pragma GCC optimize("-fdelete-null-pointer-checks")
char buf[100000], *buff = buf + 100000;
inline long long read() {
  long long x = 0, y = 0,
            c = (buff == buf + 100000
                     ? (fread(buf, 1, 100000, stdin), buff = buf)
                     : 0,
                 *buff++);
  while (!isdigit(c))
    y = c,
    c = (buff == buf + 100000 ? (fread(buf, 1, 100000, stdin), buff = buf) : 0,
         *buff++);
  while (isdigit(c))
    x = (x << 1) + (x << 3) + (c ^ '0'),
    c = (buff == buf + 100000 ? (fread(buf, 1, 100000, stdin), buff = buf) : 0,
         *buff++);
  return y == '-' ? -x : x;
}
inline void print(long long q) {
  if (q < 0) putchar('-'), q = -q;
  if (q >= 10) print(q / 10);
  putchar(q % 10 + '0');
}
int n, m, a[500010];
struct edge {
  int to, nxt;
} e[1000010];
int cnt, fir[500010];
inline void ins(int u, int v) {
  e[++cnt].to = v;
  e[cnt].nxt = fir[u];
  fir[u] = cnt;
  e[++cnt].to = u;
  e[cnt].nxt = fir[v];
  fir[v] = cnt;
}
struct cz {
  int x, y;
  bool fg;
  cz(int _x = 0, int _y = 0, bool _z = 0) {
    x = _x;
    y = _y;
    fg = _z;
  }
};
vector<cz> cc[500010];
int f[500010], l[500010], r[500010];
bool ys[500010], p6[500010];
long long as[500010], p0[500010], p1[500010], p2[500010], p3[500010],
    p4[500010], p5[500010];
inline void ud(int q) {
  p6[q] = p6[l[q]] | p6[r[q]] | ys[q];
  if (ys[q]) {
    p0[q] = p0[l[q]] + p0[r[q]] + p5[q];
    p1[q] = p1[l[q]];
    p2[q] = p2[r[q]];
  } else {
    p0[q] = p0[l[q]] + p0[r[q]] + p5[q] + p3[q] * p3[q] - p4[q] +
            2 * (p3[q] + p2[l[q]] + p1[r[q]] + p3[q] * p2[l[q]] +
                 p3[q] * p1[r[q]] + p2[l[q]] * p1[r[q]]) +
            1;
    if (!p6[l[q]])
      p1[q] = p1[l[q]] + 1 + p3[q] + p1[r[q]];
    else
      p1[q] = p1[l[q]];
    if (!p6[r[q]])
      p2[q] = p2[r[q]] + 1 + p3[q] + p2[l[q]];
    else
      p2[q] = p2[r[q]];
  }
}
inline bool is(int q) { return l[f[q]] != q && r[f[q]] != q; }
int dx[500010], hv[500010], fa[500010], rt, vl[500010];
inline void dfs(int q) {
  dx[q] = 1;
  for (int i = fir[q]; i; i = e[i].nxt)
    if (e[i].to != fa[q]) {
      fa[e[i].to] = q;
      dfs(e[i].to);
      dx[q] += dx[e[i].to];
      if (dx[hv[q]] < dx[e[i].to]) hv[q] = e[i].to;
    }
  vl[q] = 1;
  for (int i = fir[q]; i; i = e[i].nxt)
    if (e[i].to != fa[q] && e[i].to != hv[q]) vl[q] += dx[e[i].to];
}
int st[500010], ft;
inline int wk(int ll, int rr) {
  if (ll > rr) return 0;
  int i, tt = 0, p = 0, mn, t2 = 0;
  for (i = ll; i <= rr; ++i) tt += vl[st[i]];
  mn = tt + 1;
  for (i = ll; i <= rr; ++i) {
    if (abs(t2 - (tt - t2 - vl[st[i]])) < mn)
      mn = abs(t2 - (tt - t2 - vl[st[i]])), p = i;
    t2 += vl[st[i]];
  }
  l[st[p]] = wk(ll, p - 1);
  if (l[st[p]]) f[l[st[p]]] = st[p];
  r[st[p]] = wk(p + 1, rr);
  if (r[st[p]]) f[r[st[p]]] = st[p];
  ud(st[p]);
  return st[p];
}
inline void dfs2(int q) {
  for (int i = fir[q]; i; i = e[i].nxt)
    if (e[i].to != fa[q]) dfs2(e[i].to);
  if (hv[fa[q]] != q) {
    ft = 0;
    for (int i = q; i; i = hv[i]) st[++ft] = i;
    if (!fa[q])
      rt = wk(1, ft);
    else {
      int tp = wk(1, ft);
      f[tp] = fa[q];
      p3[f[tp]] += p1[tp];
      p4[f[tp]] += p1[tp] * p1[tp];
      p5[f[tp]] += p0[tp];
    }
  }
}
int main() {
  int i, j, k, u, v, mx = 0;
  n = read();
  m = read();
  for (i = 1; i <= n; ++i) {
    a[i] = read();
    cc[a[i]].push_back(cz(0, i, 1));
    mx = max(mx, a[i]);
  }
  for (i = 1; i < n; ++i) ins(read(), read());
  for (i = 1; i <= m; ++i) {
    u = read();
    v = read();
    mx = max(mx, v);
    if (a[u] == v) continue;
    cc[a[u]].push_back(cz(i, u, 0));
    a[u] = v;
    cc[v].push_back(cz(i, u, 1));
  }
  for (i = 1; i <= n; ++i) cc[a[i]].push_back(cz(m + 1, i, 0));
  for (i = 1; i <= n; ++i) p0[i] = p1[i] = p2[i] = 1;
  dfs(1);
  dfs2(1);
  for (i = 1; i <= mx; ++i) {
    int lst = 0;
    for (j = 0; j < cc[i].size(); ++j) {
      cz tp = cc[i][j];
      as[lst] += p0[rt];
      as[tp.x] -= p0[rt];
      lst = tp.x;
      ys[k = tp.y] ^= 1;
      while (k) {
        if (is(k) && k != rt) {
          p3[f[k]] -= p1[k];
          p4[f[k]] -= p1[k] * p1[k];
          p5[f[k]] -= p0[k];
          ud(k);
          p3[f[k]] += p1[k];
          p4[f[k]] += p1[k] * p1[k];
          p5[f[k]] += p0[k];
        } else
          ud(k);
        k = f[k];
      }
    }
    as[lst] += 1ll * n * n;
  }
  for (i = 1; i <= m; ++i) as[i] += as[i - 1];
  for (i = 0; i <= m; ++i) print(1ll * mx * n * n - as[i]), putchar('\n');
  return 0;
}