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;
namespace FGF {
int n, m;
const int N = 4e5 + 5;
int col[N], f[N];
long long ans[N];
struct LCT {
  int fa[N], c[N][2], siz[N], sz[N];
  long long s[N];
  void pushup(int x) { siz[x] = siz[c[x][0]] + siz[c[x][1]] + sz[x] + 1; }
  bool isrt(int x) { return c[fa[x]][0] != x && c[fa[x]][1] != x; }
  void rotat(int x) {
    int y = fa[x], z = fa[y], k = (c[y][1] == x);
    if (!isrt(y)) c[z][c[z][1] == y] = x;
    fa[x] = z, fa[y] = x, fa[c[x][k ^ 1]] = y;
    c[y][k] = c[x][k ^ 1], c[x][k ^ 1] = y;
    pushup(y);
  }
  void splay(int x) {
    while (!isrt(x)) {
      if (!isrt(fa[x]))
        rotat((c[fa[x]][1] == x) ^ (c[fa[fa[x]]][1] == fa[x]) ? x : fa[x]);
      rotat(x);
    }
    pushup(x);
  }
  void access(int x) {
    for (int y = 0; x; y = x, x = fa[x])
      splay(x), sz[x] += siz[c[x][1]] - siz[y],
          s[x] += 1ll * siz[c[x][1]] * siz[c[x][1]] - 1ll * siz[y] * siz[y],
          c[x][1] = y, pushup(x);
  }
  int findrt(int x) {
    access(x), splay(x);
    while (c[x][0]) x = c[x][0];
    splay(x);
    return x;
  }
  void link(int x, int y) {
    splay(x), fa[x] = y, access(y), splay(y), sz[y] += siz[x],
              s[y] += 1ll * siz[x] * siz[x], pushup(x);
  }
  void cut(int x) { access(x), splay(x), c[x][0] = fa[c[x][0]] = 0, pushup(x); }
} T;
struct ques {
  int op, x, id;
  ques(){};
  ques(int _op, int _x, int _id) : op(_op), x(_x), id(_id){};
};
vector<ques> q[N];
vector<int> g[N];
void dfs(int u, int fa) {
  f[u] = fa;
  T.link(u, fa);
  for (auto v : g[u])
    if (v != fa) dfs(v, u);
}
void work() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++)
    scanf("%d", &col[i]), q[col[i]].push_back(ques(1, i, 0));
  for (int i = 1, u, v; i < n; i++)
    scanf("%d%d", &u, &v), g[u].push_back(v), g[v].push_back(u);
  for (int i = 1, x, y; i <= m; i++)
    scanf("%d%d", &x, &y), q[col[x]].push_back(ques(0, x, i)),
        q[col[x] = y].push_back(ques(1, x, i));
  dfs(1, n + 1);
  memset(col, 0, sizeof(col));
  for (int i = 1; i <= n; i++) {
    long long sum = 0;
    for (auto a : q[i]) {
      ans[a.id] -= sum;
      if (a.op) {
        int tmp = T.siz[T.c[T.findrt(a.x)][1]];
        sum += 1ll * tmp * tmp;
        col[a.x] ^= 1;
        col[a.x] ? T.cut(a.x) : T.link(a.x, f[a.x]);
        tmp = T.siz[T.c[T.findrt(f[a.x])][1]];
        T.access(a.x);
        sum -= 1ll * tmp * tmp + T.s[a.x];
      } else {
        int tmp = T.siz[T.c[T.findrt(f[a.x])][1]];
        T.access(a.x);
        sum += 1ll * tmp * tmp + T.s[a.x];
        col[a.x] ^= 1;
        col[a.x] ? T.cut(a.x) : T.link(a.x, f[a.x]);
        tmp = T.siz[T.c[T.findrt(a.x)][1]];
        sum -= 1ll * tmp * tmp;
      }
      ans[a.id] += sum;
    }
    for (auto a : q[i]) {
      col[a.x] ^= 1;
      col[a.x] ? T.cut(a.x) : T.link(a.x, f[a.x]);
    }
  }
  for (int i = 1; i <= m; i++) ans[i] += ans[i - 1];
  for (int i = 0; i <= m; i++) printf("%lld\n", ans[i]);
}
}  // namespace FGF
int main() {
  FGF::work();
  return 0;
}