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, a[400001], son[400001][2], fa[400001], prt[400001], rev[400001];
long long s[400001], vs[400001], vs2[400001], Ans, ans[400001];
struct Que {
  int x, pos;
};
vector<Que> v[400001];
vector<int> g[400001];
inline bool isroot(int x) { return x != *son[fa[x]] && x != son[fa[x]][1]; }
inline bool isr(int x) { return x == son[fa[x]][1]; }
inline void pushup(int x) { s[x] = vs[x] + s[*son[x]] + s[son[x][1]] + 1; }
inline void Rotate(int x) {
  int y = fa[x], z = fa[y], l = isr(x), r = l ^ 1;
  if (!isroot(y)) son[z][isr(y)] = x;
  fa[x] = z;
  fa[fa[son[y][l] = son[x][r]] = y] = x;
  pushup(son[x][r] = y), pushup(x);
}
inline void Splay(int x) {
  int y;
  while (!isroot(x)) {
    y = fa[x];
    if (!isroot(y)) Rotate((isr(x) ^ isr(y)) ? x : y);
    Rotate(x);
  }
}
inline void Access(int x) {
  int y = 0;
  while (x) {
    Splay(x), vs[x] += s[son[x][1]],
        vs2[x] += 1ll * s[son[x][1]] * s[son[x][1]];
    son[x][1] = y, vs[x] -= s[son[x][1]],
    vs2[x] -= 1ll * s[son[x][1]] * s[son[x][1]];
    pushup(x), y = x, x = fa[x];
  }
}
inline int Getrt(int x) {
  Access(x), Splay(x);
  while (*son[x]) x = *son[x];
  return x;
}
inline void fEvert(int x) { Access(x), Splay(x); }
inline void Add(int x, int v) {
  int rt;
  fEvert(rt = Getrt(x)), Ans += v * vs2[rt];
}
inline void Link(int x, int y) {
  Add(x, -1), Add(y, -1), fEvert(x), fEvert(y);
  fa[x] = y, vs[y] += s[x], vs2[y] += 1ll * s[x] * s[x];
  Add(y, 1);
}
inline void Cut(int x, int y) {
  Add(x, -1), fEvert(x), fa[*son[x]] = 0;
  *son[x] = 0;
  pushup(x), Add(x, 1), Add(y, 1);
}
inline void dfs(int x) {
  for (int y : g[x])
    if (y ^ prt[x]) prt[y] = x, dfs(y);
}
signed main(void) {
  int i, x, y;
  long long last;
  scanf("%d%d", &n, &m);
  for (i = 1; i <= n; ++i) scanf("%d", a + i), v[a[i]].push_back({i, 0});
  for (i = 1; i < n; ++i)
    scanf("%d%d", &x, &y), g[x].push_back(y), g[y].push_back(x);
  dfs(1), prt[1] = n + 1;
  for (i = 1; i <= m; ++i)
    scanf("%d%d", &x, &y), v[a[x]].push_back({x, i}),
        v[a[x] = y].push_back({x, i});
  for (i = 1; i <= n + 1; ++i) s[i] = 1;
  for (i = 1; i <= n; ++i) Link(i, prt[i]);
  for (i = 1; i <= n; ++i) {
    last = 0;
    for (auto t : v[i]) {
      rev[x = t.x] ? Link(x, prt[x]) : Cut(x, prt[x]);
      rev[x] ^= 1;
      ans[t.pos] += 1ll * n * n - Ans - last, last = 1ll * n * n - Ans;
    }
    for (auto t : v[i])
      if (rev[x = t.x]) rev[x] = 0, Link(x, prt[x]);
  }
  for (i = 1; i <= m; ++i) ans[i] += ans[i - 1];
  for (i = 0; i <= m; ++i) printf("%lld\n", ans[i]);
  return 0;
}