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 ll = long long;
int lson[400005], rson[400005], fa[400005], sz[400005], val[400005];
ll sqr[400005];
bool rev[400005];
inline bool isrt(int u) { return lson[fa[u]] != u && rson[fa[u]] != u; }
inline void push_down(int u) {
  if (u && rev[u]) {
    std::swap(lson[u], rson[u]);
    rev[lson[u]] ^= 1;
    rev[rson[u]] ^= 1;
    rev[u] = false;
  }
}
inline void push_up(int u) {
  sz[u] = val[u] + 1;
  if (lson[u]) sz[u] += sz[lson[u]];
  if (rson[u]) sz[u] += sz[rson[u]];
}
inline void rotate(int u) {
  int v = fa[u];
  int *same = lson[v] == u ? lson : rson, *ano = lson[v] == u ? rson : lson;
  fa[u] = fa[v];
  if (!isrt(v)) (lson[fa[v]] == v ? lson : rson)[fa[v]] = u;
  same[v] = ano[u];
  fa[ano[u]] = v;
  ano[u] = v;
  fa[v] = u;
  push_up(v);
  push_up(u);
}
inline void splay(int u) {
  static int st[400005];
  int tp = 0;
  st[tp++] = u;
  for (int i = u; !isrt(i); i = fa[i]) st[tp++] = fa[i];
  while (tp--) push_down(st[tp]);
  while (!isrt(u)) {
    int v = fa[u];
    if (!isrt(v)) {
      if ((lson[fa[v]] == v) ^ (lson[v] == u))
        rotate(u);
      else
        rotate(v);
    }
    rotate(u);
  }
}
inline void access(int u) {
  for (int v = 0; u; v = u, u = fa[u]) {
    splay(u);
    if (rson[u]) {
      val[u] += sz[rson[u]];
      sqr[u] += (ll)sz[rson[u]] * (ll)sz[rson[u]];
    }
    rson[u] = v;
    if (v) {
      val[u] -= sz[v];
      sqr[u] -= (ll)sz[v] * (ll)sz[v];
    }
    push_up(u);
  }
}
inline int get_rt(int u) {
  access(u);
  splay(u);
  while (lson[u]) u = lson[u];
  splay(u);
  return u;
}
int par[400005], col[400005];
std::vector<int> adj[400005];
std::vector<std::pair<int, int> > vec[400005];
ll lazy[400005], ans;
bool vis[400005];
void add(int u) {
  int v = par[u++] + 1;
  splay(u);
  ans -= sqr[u] + (ll)sz[rson[u]] * sz[rson[u]];
  int w = get_rt(v);
  access(u);
  splay(w);
  ans -= (ll)sz[rson[w]] * sz[rson[w]];
  fa[u] = v;
  splay(v);
  val[v] += sz[u];
  sqr[v] += (ll)sz[u] * sz[u];
  push_up(v);
  access(u);
  splay(w);
  ans += (ll)sz[rson[w]] * sz[rson[w]];
}
void del(int u) {
  int v = par[u++] + 1;
  access(u);
  ans += sqr[u];
  int w = get_rt(v);
  access(u);
  splay(w);
  ans -= (ll)sz[rson[w]] * sz[rson[w]];
  splay(u);
  lson[u] = fa[lson[u]] = 0;
  push_up(u);
  splay(w);
  ans += (ll)sz[rson[w]] * sz[rson[w]];
}
void dfs(int u, int f) {
  par[u] = f;
  for (int v : adj[u]) {
    if (v != f) dfs(v, u);
  }
}
int main() {
  int n, q;
  scanf("%d%d", &n, &q);
  for (int i = 0; i < n; i++) {
    scanf("%d", col + i);
    vec[--col[i]].emplace_back(i, 0);
  }
  for (int i = 1; i < n; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    adj[--u].push_back(--v);
    adj[v].push_back(u);
  }
  for (int i = 0; i < q; i++) {
    int u, c;
    scanf("%d%d", &u, &c);
    u--;
    vec[col[u]].emplace_back(u, i + 1);
    col[u] = --c;
    vec[col[u]].emplace_back(u, i + 1);
  }
  dfs(0, n);
  for (int i = 1; i <= n + 1; i++) sz[i] = 1;
  for (int i = 0; i < n; i++) add(i);
  for (int i = 0; i < n; i++) {
    if (vec[i].empty()) {
      lazy[0] += (ll)n * n;
      continue;
    }
    ll lst = 0;
    if (vec[i][0].second) {
      lazy[0] += (ll)n * n;
      lst = (ll)n * n;
    }
    for (int j = 0; j < vec[i].size(); j++) {
      int u = vec[i][j].first;
      vis[u] ^= 1;
      (vis[u] ? del : add)(u);
      if (j + 1 == vec[i].size() || vec[i][j].second != vec[i][j + 1].second) {
        lazy[vec[i][j].second] += ans - lst;
        lst = ans;
      }
    }
    for (int j = vec[i].size() - 1; j >= 0; j--) {
      int u = vec[i][j].first;
      vis[u] ^= 1;
      (vis[u] ? del : add)(u);
    }
  }
  ans = (ll)n * n * n;
  for (int i = 0; i <= q; i++) {
    ans -= lazy[i];
    printf("%lld\n", ans);
  }
  return 0;
}