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 = 5e5 + 10;
int n, timer = 0, m;
int x[N], y[N], V[N], sz[N], p[N], head[N], a[N], col[N];
vector<int> adj[N], child[N];
vector<pair<int, int> > flip[N];
long long light[N], light_sqr[N], ans[N];
struct FenwickTree {
  int n;
  int fw[N];
  void Init(int _n = 0) {
    n = _n;
    for (int i = 1; i <= n; ++i) fw[i] = 0;
  }
  void Update(int i, int v) {
    for (i; i <= n; i += i & -i) fw[i] += v;
  }
  void Update(int l, int r, int v) {
    if (l <= r) {
      Update(l, +v);
      Update(r + 1, -v);
    }
  }
  int Query(int i) {
    int ans = 0;
    for (i; i > 0; i -= i & -i) ans += fw[i];
    return ans;
  }
} blackNode, subtreeSize;
void DFS(int u) {
  sz[u] = 1;
  for (auto v : adj[u])
    if (v != p[u]) {
      p[v] = u;
      child[u].push_back(v);
      DFS(v);
      sz[u] += sz[v];
    }
}
void HLD(int u) {
  x[u] = ++timer;
  V[timer] = u;
  for (int i = 1; i < child[u].size(); ++i)
    if (sz[child[u][i]] > sz[child[u][0]]) swap(child[u][i], child[u][0]);
  subtreeSize.Update(x[u], x[u], sz[u]);
  for (int i = 0; i < child[u].size(); ++i) {
    int v = child[u][i];
    head[v] = (i == 0 ? head[u] : v);
    if (i > 0) {
      light[u] += sz[v];
      light_sqr[u] += 1LL * sz[v] * sz[v];
    }
    HLD(v);
  }
  y[u] = timer;
}
int Anc(int u) {
  int v = u, black = blackNode.Query(x[u]);
  while (true) {
    int w = p[head[v]];
    if (w == -1 || blackNode.Query(x[w]) != black) break;
    v = w;
  }
  int l = x[head[v]], r = x[v], f = x[v];
  while (l <= r) {
    int m = (l + r) >> 1;
    if (blackNode.Query(m) == black) {
      r = m - 1;
      f = m;
    } else
      l = m + 1;
  }
  return V[f];
}
long long getAns(int u) {
  if (child[u].size()) {
    long long k = subtreeSize.Query(x[child[u][0]]);
    return k * k + light_sqr[u];
  } else
    return 0;
}
long long turnBlack(int u) {
  int a = Anc(u);
  long long result = -getAns(a) + getAns(u);
  int v = u, subsize = subtreeSize.Query(x[u]);
  while (true) {
    if (head[v] == head[a]) break;
    int w = p[head[v]];
    int h = subtreeSize.Query(x[head[v]]);
    subtreeSize.Update(x[head[v]], x[v], -subsize);
    light[w] -= subsize;
    light_sqr[w] -= 1LL * (2 * h - subsize) * subsize;
    v = w;
  }
  subtreeSize.Update(x[a] + 1, x[v], -subsize);
  result += getAns(a);
  col[u] ^= 1;
  blackNode.Update(x[u], y[u], +1);
  return result;
}
long long turnWhite(int u) {
  col[u] ^= 1;
  blackNode.Update(x[u], y[u], -1);
  int a = Anc(u);
  long long result = -getAns(a) + -getAns(u);
  int v = u, subsize = 1 + light[u];
  if (child[u].size()) subsize += subtreeSize.Query(x[child[u][0]]);
  while (true) {
    if (head[v] == head[a]) break;
    int w = p[head[v]];
    int h = subtreeSize.Query(x[head[v]]);
    subtreeSize.Update(x[head[v]], x[v], +subsize);
    light[w] += subsize;
    light_sqr[w] += 1LL * (2 * h + subsize) * subsize;
    v = w;
  }
  subtreeSize.Update(x[a] + 1, x[v], +subsize);
  result += getAns(a);
  return result;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) cin >> col[i];
  for (int i = 1; i < n; ++i) {
    int u, v;
    cin >> u >> v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  adj[0].push_back(1);
  adj[1].push_back(0);
  blackNode.Init(n + 3);
  subtreeSize.Init(n + 3);
  p[0] = -1;
  DFS(0);
  HLD(0);
  subtreeSize.Update(x[0], x[0], -sz[0]);
  blackNode.Update(x[0], y[0], +1);
  for (int i = 1; i <= n; ++i) flip[col[i]].push_back(pair<int, int>(0, i));
  for (int i = 1; i <= m; ++i) {
    int u, x;
    cin >> u >> x;
    if (x != col[u]) {
      flip[col[u]].push_back(pair<int, int>(i, u));
      col[u] = x;
      flip[col[u]].push_back(pair<int, int>(i, u));
    }
  }
  for (int i = 1; i <= n; ++i) col[i] = 0;
  for (int i = 1; i <= n; ++i) {
    for (auto x : flip[i]) {
      int idx = x.first, u = x.second;
      ans[idx] -= (col[u] == 0 ? turnBlack(u) : turnWhite(u));
    }
    for (auto x : flip[i]) {
      int idx = x.first, u = x.second;
      if (col[u] == 1) {
        turnWhite(u);
      }
    }
  }
  for (int i = 0; i <= m; ++i) {
    if (i > 0) ans[i] += ans[i - 1];
    cout << ans[i] << '\n';
  }
  return 0;
}