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;
const int N = 4e5 + 9;
struct node {
  int p = 0, c[2] = {0, 0}, pp = 0;
  bool flip = 0;
  int sz = 0, ssz = 0, vsz = 0;
  long long val = 0;
  node() {}
  node(int x) {
    val = 0;
    sz = 1;
    ssz = 1;
    vsz = 0;
  }
};
struct LCT {
  vector<node> t;
  LCT() {}
  LCT(int n) : t(n + 1) {}
  int dir(int x, int y) { return t[x].c[1] == y; }
  void set(int x, int d, int y) {
    if (x) t[x].c[d] = y, pull(x);
    if (y) t[y].p = x;
  }
  void pull(int x) {
    if (!x) return;
    int &l = t[x].c[0], &r = t[x].c[1];
    t[x].sz = t[l].sz + t[r].sz + 1;
    t[x].ssz = t[l].ssz + t[r].ssz + t[x].vsz + 1;
  }
  void push(int x) {
    if (!x) return;
    int &l = t[x].c[0], &r = t[x].c[1];
    if (t[x].flip) {
      swap(l, r);
      if (l) t[l].flip ^= 1;
      if (r) t[r].flip ^= 1;
      t[x].flip = 0;
    }
  }
  void rotate(int x, int d) {
    int y = t[x].p, z = t[y].p, w = t[x].c[d];
    swap(t[x].pp, t[y].pp);
    set(y, !d, w);
    set(x, d, y);
    set(z, dir(z, y), x);
  }
  void splay(int x) {
    for (push(x); t[x].p;) {
      int y = t[x].p, z = t[y].p;
      push(z);
      push(y);
      push(x);
      int dx = dir(y, x), dy = dir(z, y);
      if (!z)
        rotate(x, !dx);
      else if (dx == dy)
        rotate(y, !dx), rotate(x, !dx);
      else
        rotate(x, dy), rotate(x, dx);
    }
  }
  int access(int _u) {
    int last = _u;
    for (int v = 0, u = _u; u; u = t[v = u].pp) {
      splay(u);
      splay(v);
      t[u].vsz -= t[v].ssz;
      t[u].val -= 1LL * t[v].ssz * t[v].ssz;
      int r = t[u].c[1];
      t[u].vsz += t[r].ssz;
      t[u].val += 1LL * t[r].ssz * t[r].ssz;
      t[v].pp = 0;
      swap(t[r].p, t[r].pp);
      set(u, 1, v);
      last = u;
    }
    splay(_u);
    return last;
  }
  int find_root(int u) {
    access(u);
    splay(u);
    push(u);
    while (t[u].c[0]) {
      u = t[u].c[0];
      push(u);
    }
    splay(u);
    return u;
  }
  long long yo(int u) {
    u = find_root(u);
    splay(u);
    return t[u].val + 1LL * t[t[u].c[1]].ssz * t[t[u].c[1]].ssz;
  }
  long long ans = 0;
  void link(int u, int v) {
    ans -= yo(u);
    ans -= yo(v);
    access(u);
    access(v);
    t[v].pp = u;
    t[u].vsz += t[v].ssz;
    t[u].val += 1LL * t[v].ssz * t[v].ssz;
    ans += yo(u);
  }
  void cut(int u) {
    ans -= yo(u);
    access(u);
    assert(t[u].c[0] != 0);
    t[t[u].c[0]].p = 0;
    int v = t[u].c[0];
    t[u].c[0] = 0;
    pull(u);
    ans += yo(u) + yo(v);
  }
};
int c[N], par[N], col[N];
long long ans[N];
vector<pair<int, int>> Q[N];
vector<int> g[N];
void dfs(int u = 1, int pre = 0) {
  par[u] = pre;
  for (auto v : g[u])
    if (v != pre) dfs(v, u);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, q;
  cin >> n >> q;
  for (int i = 1; i <= n; i++) cin >> c[i];
  for (int i = 1; i < n; i++) {
    int u, v;
    cin >> u >> v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  dfs(1, n + 1);
  for (int i = 1; i <= n; i++) Q[c[i]].push_back({i, 0});
  for (int i = 1; i <= q; i++) {
    int id, x;
    cin >> id >> x;
    Q[c[id]].push_back({id, i});
    c[id] = x;
    Q[c[id]].push_back({id, i});
  }
  LCT lct(n + 1);
  for (int i = 1; i <= n + 1; i++) col[i] = 1, lct.t[i] = node(i);
  for (int i = 1; i <= n; i++) lct.link(par[i], i);
  for (int c = 1; c <= n; c++) {
    long long last = 0;
    for (auto x : Q[c]) {
      int u = x.first, id = x.second;
      if (col[u])
        lct.cut(u);
      else
        lct.link(par[u], u);
      col[u] ^= 1;
      ans[id] += 1LL * n * n - lct.ans - last;
      last = 1LL * n * n - lct.ans;
    }
    for (auto x : Q[c]) {
      int u = x.first, id = x.second;
      if (!col[u]) lct.link(par[u], u), col[u] ^= 1;
    }
  }
  for (int i = 1; i <= q; i++) ans[i] += ans[i - 1];
  for (int i = 0; i <= q; i++) {
    cout << ans[i] << '\n';
  }
  return 0;
}