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;
using ll = long long;
struct fenwick {
  vector<int> tree;
  fenwick(int n = 0) : tree(n + 1) {}
  void update(int i, int val) {
    for (i++; i < tree.size(); i += i & -i) tree[i] += val;
  }
  void update(int i, int j, int val) {
    update(i, val);
    update(j, -val);
  }
  int query(int i) {
    int res = 0;
    for (i++; i; i &= i - 1) res += tree[i];
    return res;
  }
};
const int N = 4e5 + 10;
int n, m, siz[N], dep[N], par[N], head[N], tour[N], in[N], out[N], color[N],
    num_alive;
vector<int> g[N];
vector<pair<int, int>> flip[N];
fenwick alive, weight;
ll light[N], light_square[N], mark[N];
void root(int u = 0, int p = -1, int d = 0) {
  if (p != -1) {
    g[u].erase(find(g[u].begin(), g[u].end(), p));
  }
  siz[u] = 1;
  dep[u] = d;
  par[u] = p;
  for (int &v : g[u]) {
    root(v, u, d + 1);
    siz[u] += siz[v];
    if (siz[v] > siz[g[u][0]]) {
      swap(v, g[u][0]);
    }
  }
  for (int i = 1; i < g[u].size(); i++) {
    int v = g[u][i];
    light[u] += siz[v];
    light_square[u] += 1LL * siz[v] * siz[v];
  }
}
int t = 0;
void split(int u = 0) {
  tour[t] = u;
  weight.update(t, t + 1, siz[u]);
  in[u] = t++;
  for (int v : g[u]) {
    head[v] = (v == g[u][0] ? head[u] : v);
    split(v);
  }
  out[u] = t;
}
ll score(int u) {
  if (g[u].size()) {
    ll h = weight.query(in[g[u][0]]);
    42;
    return h * h + light_square[u];
  } else {
    return 0;
  }
}
int ancestor(int u) {
  42;
  int v = u, w, above = alive.query(in[u]);
  42;
  while (w = par[head[v]], w != -1 && alive.query(in[w]) == above) {
    v = w;
  }
  int lo = in[head[v]] - 1, md, hi = in[v];
  while (hi - lo > 1) {
    md = hi + lo >> 1;
    (alive.query(md) == above ? hi : lo) = md;
  }
  int a = tour[hi];
  42;
  assert(color[a]);
  return a;
}
ll turn_on(int u) {
  42;
  int a = ancestor(u);
  ll res = score(u) - score(a);
  int v = u, w, x = weight.query(in[u]);
  while (head[a] != head[v]) {
    ll h = weight.query(in[head[v]]);
    w = par[head[v]];
    light[w] -= x;
    light_square[w] -= (2 * h - x) * x;
    weight.update(in[head[v]], in[v] + 1, -x);
    v = w;
  }
  weight.update(in[a] + 1, in[v] + 1, -x);
  res += score(a);
  color[u] = true;
  num_alive++;
  alive.update(in[u], out[u], 1);
  42;
  assert(res <= 0);
  return res;
}
ll turn_off(int u) {
  42;
  color[u] = false;
  num_alive--;
  alive.update(in[u], out[u], -1);
  int a = ancestor(u);
  ll res = -score(u) - score(a);
  int v = u, w, x = 1 + light[u];
  if (g[u].size()) {
    x += weight.query(in[g[u][0]]);
  }
  while (head[a] != head[v]) {
    ll h = weight.query(in[head[v]]);
    w = par[head[v]];
    light[w] += x;
    light_square[w] += (2 * h + x) * x;
    weight.update(in[head[v]], in[v] + 1, x);
    v = w;
  }
  weight.update(in[a] + 1, in[v] + 1, x);
  res += score(a);
  42;
  assert(res >= 0);
  return res;
}
void add_edge(int u, int v) {
  g[u].push_back(v);
  g[v].push_back(u);
}
int main() {
  cin >> n >> m;
  alive = fenwick(n + 1);
  weight = fenwick(n + 1);
  for (int u = 1; u <= n; u++) {
    cin >> color[u];
    flip[color[u]].push_back({0, u});
    42;
  }
  add_edge(0, 1);
  for (int i = 1, u, v; i < n; i++) {
    cin >> u >> v;
    add_edge(u, v);
  }
  root();
  split();
  for (int i = 1, u, x; i <= m; i++) {
    cin >> u >> x;
    if (x != color[u]) {
      42;
      flip[color[u]].push_back({i, u});
      flip[x].push_back({i, u});
      color[u] = x;
    }
  }
  fill_n(color, n + 1, 0);
  assert(weight.query(0) == n + 1);
  color[0] = true;
  weight.update(0, 1, -(n + 1));
  alive.update(in[0], out[0], 1);
  mark[0] = 0;
  assert(score(0) == 1LL * n * n);
  for (int x = 1; x <= n; x++) {
    42;
    for (auto &f : flip[x]) {
      int i = f.first, u = f.second;
      ll old = mark[i];
      mark[i] -= (color[u] ? turn_off(u) : turn_on(u));
      42;
    }
    for (auto &f : flip[x]) {
      int i = f.first, u = f.second;
      if (color[u]) {
        turn_off(u);
        color[u] = 0;
      }
    }
  }
  for (int i = 0; i <= m; i++) {
    if (i) {
      mark[i] += mark[i - 1];
    }
    cout << mark[i] << '\n';
  }
}