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 = 400000;
int n, m, c[MAXN + 10];
long long s[MAXN + 10], tot;
class node {
 public:
  int ch[2], siz, fa, vsiz, tsiz;
  long long s2;
} t[MAXN + 10];
bool chosen[MAXN + 10];
void pushup(int x) {
  t[x].siz = t[t[x].ch[0]].siz + t[t[x].ch[1]].siz + 1;
  t[x].tsiz = t[t[x].ch[0]].tsiz + t[t[x].ch[1]].tsiz + 1 + t[x].vsiz;
}
bool isroot(int x) { return t[t[x].fa].ch[0] != x && t[t[x].fa].ch[1] != x; }
int son(int x) { return t[t[x].fa].ch[1] == x; }
void rotate(int x) {
  int y = t[x].fa, z = t[y].fa, ts1 = son(y), ts2 = son(x),
      b = t[x].ch[ts2 ^ 1];
  if (z && !isroot(y)) t[z].ch[ts1] = x;
  if (b) t[b].fa = y;
  t[x].fa = z;
  t[y].fa = x;
  t[x].ch[ts2 ^ 1] = y;
  t[y].ch[ts2] = b;
  pushup(y);
  pushup(x);
}
void splay(int x) {
  while (!isroot(x)) {
    if (!isroot(t[x].fa)) rotate(son(x) == son(t[x].fa) ? t[x].fa : x);
    rotate(x);
  }
}
void access(int x) {
  for (int y = 0; x; y = x, x = t[x].fa) {
    splay(x);
    t[x].vsiz += t[t[x].ch[1]].tsiz;
    t[x].s2 += (long long)t[t[x].ch[1]].tsiz * t[t[x].ch[1]].tsiz;
    t[x].ch[1] = y;
    t[x].vsiz -= t[y].tsiz;
    t[x].s2 -= (long long)t[y].tsiz * t[y].tsiz;
    if (y) t[y].fa = x;
    pushup(x);
  }
}
int findroot(int x) {
  access(x);
  splay(x);
  while (t[x].ch[0]) x = t[x].ch[0];
  splay(x);
  return x;
}
vector<int> v[MAXN + 10];
int fa[MAXN + 10];
void dfs(int np, int fath) {
  fa[np] = fath;
  for (int &x : v[np]) {
    if (x == fath) continue;
    dfs(x, np);
  }
}
void link(int x) {
  int fr = findroot(fa[x]);
  access(fr);
  splay(fr);
  tot -= t[fr].s2 + t[x].s2;
  access(fa[x]);
  splay(fa[x]);
  t[x].fa = fa[x];
  t[fa[x]].ch[1] = x;
  pushup(fa[x]);
  access(fr);
  splay(fr);
  tot += t[fr].s2;
}
void cut(int x) {
  int f = findroot(x);
  access(f);
  tot -= t[f].s2;
  access(x);
  splay(x);
  t[t[x].ch[0]].fa = 0;
  t[x].ch[0] = 0;
  pushup(x);
  access(x);
  access(f);
  tot += t[f].s2 + t[x].s2;
}
set<int> used;
void flip(int x) {
  if (chosen[x])
    cut(x);
  else
    link(x);
  chosen[x] ^= 1;
}
vector<int> st[MAXN + 10];
vector<pair<int, int> > opt[MAXN + 10];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%d", &c[i]), st[c[i]].push_back(i);
  for (int i = 1; i <= n + 1; i++) t[i].siz = 1, t[i].tsiz = 1;
  for (int i = 1, a, b; i < n; i++) {
    scanf("%d%d", &a, &b);
    v[a].push_back(b);
    v[b].push_back(a);
  }
  dfs(1, n + 1);
  for (int i = 1, x, y; i <= m; i++) {
    scanf("%d%d", &x, &y);
    if (c[x] == y) continue;
    opt[c[x]].push_back(make_pair(i, x));
    opt[y].push_back(make_pair(i, x));
    c[x] = y;
  }
  for (int i = 1; i <= n; i++) flip(i);
  for (int i = 1; i <= n; i++) {
    for (int &x : st[i]) {
      used.insert(x);
      flip(x);
    }
    int lstt = 0;
    long long S = (long long)n * n;
    for (auto &x : opt[i]) {
      s[lstt] += S - tot;
      s[x.first] -= S - tot;
      if (!chosen[x.second])
        used.erase(x.second);
      else
        used.insert(x.second);
      flip(x.second);
      lstt = x.first;
    }
    s[lstt] += S - tot;
    for (auto &x : used) flip(x);
    used.clear();
  }
  for (int i = 1; i <= m; i++) s[i] += s[i - 1];
  for (int i = 0; i <= m; i++) printf("%lld\n", s[i]);
  return 0;
}