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 MAXN = 4e5 + 5;
int n, m;
int color[MAXN];
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch)) (ch == '-') && (f = -f), ch = getchar();
  while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
  return x * f;
}
int head[MAXN], trump;
struct Edge {
  int to, next;
  Edge(int u = 0, int v = 0) : to(v), next(head[u]){};
} e[MAXN << 1];
inline void addedge(int u, int v) {
  e[++trump] = Edge(u, v);
  head[u] = trump;
  e[++trump] = Edge(v, u);
  head[v] = trump;
}
int father[MAXN];
void dfs(int u, int fa) {
  father[u] = fa;
  for (register int i = head[u]; i; i = e[i].next) {
    int v = e[i].to;
    if (v == fa) continue;
    dfs(v, u);
  }
}
struct Node {
  int father, son[2];
  int size, isize;
  long long sum;
} t[MAXN];
inline bool isroot(int k) {
  return t[t[k].father].son[0] != k && t[t[k].father].son[1] != k;
}
inline int identify(int k) { return t[t[k].father].son[1] == k; }
inline void pushup(int k) {
  t[k].size = t[t[k].son[0]].size + t[t[k].son[1]].size + t[k].isize + 1;
}
inline void rotate(int k) {
  int f = t[k].father, a = t[f].father;
  int sk = identify(k), sf = identify(f);
  int d = t[k].son[sk ^ 1];
  if (!isroot(f)) t[a].son[sf] = k;
  t[k].son[sk ^ 1] = f;
  t[f].son[sk] = d;
  if (d) t[d].father = f;
  t[f].father = k;
  t[k].father = a;
  pushup(f);
  pushup(k);
}
inline void splay(int k) {
  int f;
  while (!isroot(k)) {
    f = t[k].father;
    if (!isroot(f)) {
      if (identify(k) == identify(f))
        rotate(f);
      else
        rotate(k);
    }
    rotate(k);
  }
  pushup(k);
}
inline void access(int k) {
  for (int d = 0; k; k = t[d = k].father) {
    splay(k);
    t[k].sum += 1ll * t[t[k].son[1]].size * t[t[k].son[1]].size;
    t[k].isize += t[t[k].son[1]].size;
    t[k].son[1] = d;
    t[k].sum -= 1ll * t[t[k].son[1]].size * t[t[k].son[1]].size;
    t[k].isize -= t[t[k].son[1]].size;
    pushup(k);
  }
}
inline int findroot(int k) {
  access(k);
  splay(k);
  for (; t[k].son[0]; k = t[k].son[0])
    ;
  return splay(k), k;
}
inline void link(int k) {
  access(k);
  splay(k);
  access(father[k]);
  splay(father[k]);
  t[k].father = father[k];
  t[father[k]].isize += t[k].size;
  t[father[k]].sum += 1ll * t[k].size * t[k].size;
  pushup(father[k]);
}
inline void cut(int k) {
  access(k);
  splay(k);
  t[k].son[0] = t[t[k].son[0]].father = 0;
  pushup(k);
}
inline long long query(int k) {
  k = findroot(k);
  return 1ll * t[t[k].son[1]].size * t[t[k].son[1]].size;
}
int tag[MAXN];
inline long long modify(int k) {
  tag[k] ^= 1;
  long long tmp = 0;
  if (!tag[k]) {
    tmp += t[k].sum + 1ll * t[t[k].son[1]].size * t[t[k].son[1]].size;
    if (!tag[father[k]]) tmp += query(father[k]);
    link(k);
    tmp -= query(k);
  } else {
    tmp += query(k);
    cut(k);
    tmp -= t[k].sum + 1ll * t[t[k].son[1]].size * t[t[k].son[1]].size;
    if (!tag[father[k]]) tmp -= query(father[k]);
  }
  return tmp;
}
vector<pair<int, int> > M[MAXN];
long long prt[MAXN];
int main() {
  register int i;
  n = read();
  m = read();
  for (i = 1; i <= n; ++i)
    M[color[i] = read()].push_back(make_pair(i, 0)), t[i].size = 1;
  for (i = 1; i < n; ++i) addedge(read(), read());
  dfs(1, n + 1);
  t[n + 1].size = 1;
  for (i = 1; i <= n; ++i) link(i);
  for (i = 1; i <= m; ++i) {
    int u = read(), c = read();
    M[color[u]].push_back(make_pair(u, i));
    M[color[u] = c].push_back(make_pair(u, i));
  }
  for (i = 1; i <= n; ++i) {
    for (unsigned int j = 0; j < M[i].size(); ++j)
      prt[M[i][j].second] += modify(M[i][j].first);
    for (unsigned int j = 0; j < M[i].size(); ++j) modify(M[i][j].first);
  }
  for (i = 1; i <= m; ++i) prt[i] += prt[i - 1];
  for (i = 0; i <= m; ++i) printf("%lld\n", prt[i]);
  return 0;
}