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;
long long fa[1000010], c[1000010][2], cnt, a[1000010], s[1000010], h[1000010],
    v[1000010], nxt[1000010], ec, n, m, cc[1000010], f[1000010], r[1000010],
    cl[1000010], nm, vs[1000010], sv[1000010];
void add(long long x, long long y) {
  v[++ec] = y;
  nxt[ec] = h[x];
  h[x] = ec;
}
long long son(long long x) { return c[fa[x]][1] == x; }
void up(long long x) { s[x] = s[c[x][0]] + s[c[x][1]] + 1 + vs[x]; }
long long isr(long long x) { return c[fa[x]][0] != x && c[fa[x]][1] != x; }
struct no {
  long long x, y;
};
vector<no> q[1000010];
void dfs(long long x, long long fa) {
  f[x] = fa;
  for (long long i = h[x]; i; i = nxt[i])
    if (v[i] != fa) dfs(v[i], x);
}
void rotate(long long x) {
  long long y = fa[x], z = fa[y], t = son(x);
  if (!isr(y)) c[z][son(y)] = x;
  fa[x] = z;
  c[y][t] = c[x][t ^ 1];
  fa[c[x][t ^ 1]] = y;
  c[x][t ^ 1] = y;
  fa[y] = x;
  up(y);
  up(x);
}
void splay(long long x) {
  long long y;
  for (; !isr(x); rotate(x)) {
    y = fa[x];
    if (!isr(y)) rotate(son(y) ^ son(x) ? x : y);
  }
}
void access(long long x) {
  for (long long y = 0; x; y = x, x = fa[x]) {
    splay(x);
    vs[x] -= s[y];
    vs[x] += s[c[x][1]];
    sv[x] -= s[y] * s[y];
    sv[x] += s[c[x][1]] * s[c[x][1]];
    c[x][1] = y;
    up(x);
  }
}
long long fr(long long x) {
  access(x);
  splay(x);
  while (c[x][0]) x = c[x][0];
  splay(x);
  return x;
}
void link(long long x, long long y) {
  splay(x);
  nm -= sv[x] + s[c[x][1]] * s[c[x][1]];
  long long z = fr(y);
  access(x);
  splay(z);
  nm -= s[c[z][1]] * s[c[z][1]];
  fa[x] = y;
  splay(y);
  vs[y] += s[x];
  sv[y] += s[x] * s[x];
  up(y);
  access(x);
  splay(z);
  nm += s[c[z][1]] * s[c[z][1]];
}
void cut(long long x, long long y) {
  access(x);
  nm += sv[x];
  long long z = fr(y);
  access(x);
  splay(z);
  nm -= s[c[z][1]] * s[c[z][1]];
  splay(x);
  c[x][0] = fa[c[x][0]] = 0;
  up(x);
  splay(z);
  nm += s[c[z][1]] * s[c[z][1]];
}
signed main() {
  cin >> n >> m;
  for (long long i = 1; i <= n; i++) cin >> cc[i];
  for (long long i = 1; i < n; i++) {
    long long x, y;
    cin >> x >> y;
    add(x, y);
    add(y, x);
  }
  for (long long i = 1; i <= n; i++) q[cc[i]].push_back((no){0, i});
  for (long long i = 1; i <= m; i++) {
    long long x, y;
    cin >> x >> y;
    q[cc[x]].push_back((no){i, x});
    cc[x] = y;
    q[cc[x]].push_back((no){i, x});
  }
  dfs(1, n + 1);
  for (long long i = 1; i < n + 2; i++) up(i);
  for (long long i = 1; i <= n; i++) link(i, f[i]);
  for (long long i = 1; i <= n; i++) {
    long long ls = 0;
    for (no x : q[i]) {
      if (cl[x.y])
        link(x.y, f[x.y]);
      else
        cut(x.y, f[x.y]);
      cl[x.y] ^= 1;
      r[x.x] += n * n - nm - ls;
      ls = n * n - nm;
    }
    for (no x : q[i])
      if (cl[x.y]) {
        link(x.y, f[x.y]);
        cl[x.y] ^= 1;
      }
  }
  for (long long i = 1; i <= m; i++) r[i] += r[i - 1];
  for (long long i = 0; i <= m; i++) cout << r[i] << '\n';
}