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;
int n, m, f[400001], c[400001], h[400001], p, vis[400001];
long long now, ans[400001];
struct splay {
  int ch[2], f;
  long long si, si2, size;
} t[1000001];
bool notrt(int x) {
  return t[x].f && ((t[t[x].f].ch[0] == x) || (t[t[x].f].ch[1] == x));
}
void update(int x) {
  t[x].size = t[t[x].ch[0]].size + t[t[x].ch[1]].size + t[x].si + 1;
}
void rotate(int x) {
  int y = t[x].f, z = t[y].f, k = (t[y].ch[1] == x);
  if (notrt(y)) t[z].ch[t[z].ch[1] == y] = x;
  t[x].f = z;
  t[y].ch[k] = t[x].ch[k ^ 1];
  t[t[x].ch[k ^ 1]].f = y;
  t[x].ch[k ^ 1] = y;
  t[y].f = x;
  update(y);
  update(x);
}
void splay(int x) {
  while (notrt(x)) {
    int y = t[x].f, z = t[y].f;
    if (notrt(y))
      ((t[y].ch[1] == x) ^ (t[z].ch[1] == y)) ? rotate(x) : rotate(y);
    rotate(x);
  }
}
void access(int x) {
  for (int y = 0; x; y = x, x = t[x].f) {
    splay(x);
    t[x].si += t[t[x].ch[1]].size;
    t[x].si2 += t[t[x].ch[1]].size * t[t[x].ch[1]].size;
    t[x].ch[1] = y;
    t[x].si -= t[t[x].ch[1]].size;
    t[x].si2 -= t[t[x].ch[1]].size * t[t[x].ch[1]].size;
    update(x);
  }
}
void add(int x) {
  splay(x);
  access(f[x]);
  splay(f[x]);
  t[f[x]].si += t[x].size;
  t[f[x]].si2 += t[x].size * t[x].size;
  t[x].f = f[x];
  update(f[x]);
}
int findrt(int x) {
  access(x);
  splay(x);
  while (t[x].ch[0]) x = t[x].ch[0];
  return x;
}
void add(int x, long long &now) {
  int y = f[x], z = findrt(y);
  splay(x);
  splay(z);
  now += t[x].si2 + t[t[x].ch[1]].size * t[t[x].ch[1]].size +
         t[t[z].ch[1]].size * t[t[z].ch[1]].size -
         (t[x].size + t[t[z].ch[1]].size) * (t[x].size + t[t[z].ch[1]].size);
  splay(y);
  t[y].si += t[x].size;
  t[y].si2 += t[x].size * t[x].size;
  t[x].f = y;
  update(y);
}
void del(int x, long long &now) {
  int z = findrt(x);
  now -= t[x].si2;
  splay(z);
  now += t[t[z].ch[1]].size * t[t[z].ch[1]].size;
  splay(x);
  t[t[x].ch[0]].f = 0, t[x].ch[0] = 0;
  update(x);
  splay(z);
  now -= t[t[z].ch[1]].size * t[t[z].ch[1]].size;
}
vector<pair<int, int> > q[400001];
struct pp {
  int to, ne;
} a[800001];
void addb(int x, int y) {
  a[++p].to = y;
  a[p].ne = h[x];
  h[x] = p;
}
void dfs(int x, int fa) {
  t[x].f = f[x] = fa;
  t[x].size = 1;
  for (int i = h[x]; i; i = a[i].ne) {
    if (a[i].to == fa) continue;
    dfs(a[i].to, x);
    t[x].size += t[a[i].to].size;
    t[x].si += t[a[i].to].size;
    t[x].si2 += t[a[i].to].size * t[a[i].to].size;
  }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++)
    scanf("%d", &c[i]), q[c[i]].push_back(make_pair(0, i));
  for (int i = 1; i < n; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    addb(x, y);
    addb(y, x);
  }
  for (int i = 1; i <= n + 1; i++) t[i].size = 1;
  t[n + 1].si = n, t[n + 1].si2 = 1ll * n * n, t[n + 1].size = n + 1;
  dfs(1, n + 1);
  for (int i = 1; i <= m; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    q[c[x]].push_back(make_pair(i, x));
    q[c[x] = y].push_back(make_pair(i, x));
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 0, l = q[i].size(); j < l; j++)
      (vis[q[i][j].second] ^= 1) ? del(q[i][j].second, ans[q[i][j].first])
                                 : add(q[i][j].second, ans[q[i][j].first]);
    for (int j = 0, l = q[i].size(); j < l; j++)
      if (vis[q[i][j].second]) vis[q[i][j].second] = 0, add(q[i][j].second);
  }
  for (int i = 1; i <= m; i++) ans[i] += ans[i - 1];
  for (int i = 0; i <= m; i++) printf("%lld\n", ans[i]);
  return 0;
}