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 = 4e5 + 5;
int n, m, u, v, x;
int head[N], p[N], c[N];
long long ans[N];
bool tag[N];
vector<pair<int, int> > q[N];
struct edge {
  int v, next;
} e[N << 1];
struct node {
  int fa, ch[2];
  int size1, size2;
  long long size3;
} t[N];
inline char gc(void) {
  static char s[131072], *p1 = s, *p2 = s + 131072;
  if (p1 == p2) p1 = s, p2 = s + fread(s, 1, 131072, stdin);
  return p2 == s ? EOF : *p1++;
}
inline int read(void) {
  int x = 0;
  char c = gc(), f = 1;
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = gc();
  }
  while (c <= '9' && c >= '0') x = x * 10 + c - '0', c = gc();
  return f * x;
}
inline void pc(char c) {
  static char s[131072], *p1 = s, *p2 = s + 131072;
  if (c == -1) fwrite(s, 1, p1 - s, stdout);
  if (p1 == p2) fwrite(s, 1, 131072, stdout), p1 = s;
  *p1++ = c;
}
inline void print(long long x) {
  static char s[20], t;
  if (x < 0) pc('-'), x = -x;
  if (!x) pc('0');
  while (x) s[++t] = x % 10, x /= 10;
  while (t) pc(s[t--] + '0');
}
inline void add(int u, int v) {
  static int k = 0;
  e[++k] = (edge){v, head[u]};
  head[u] = k;
}
inline bool root(int x) {
  return t[t[x].fa].ch[0] != x && t[t[x].fa].ch[1] != x;
}
inline void pushup(int u) {
  t[u].size1 = t[t[u].ch[0]].size1 + t[t[u].ch[1]].size1 + t[u].size2 + 1;
}
inline void rotate(int x) {
  int y = t[x].fa, z = t[y].fa, k = (x == t[y].ch[1]);
  if (!root(y)) t[z].ch[y == t[z].ch[1]] = x;
  t[x].fa = z;
  t[y].ch[k] = t[x].ch[!k], t[t[x].ch[!k]].fa = y;
  t[x].ch[!k] = y, t[y].fa = x;
  pushup(y), pushup(x);
}
inline void splay(int x) {
  while (!root(x)) {
    int y = t[x].fa, z = t[y].fa;
    if (!root(y)) (x == t[y].ch[0]) ^ (y == t[z].ch[0]) ? rotate(x) : rotate(y);
    rotate(x);
  }
  pushup(x);
}
inline void access(int x) {
  for (register int y = 0; x; y = x, x = t[x].fa) {
    splay(x);
    t[x].size2 += t[t[x].ch[1]].size1;
    t[x].size3 += 1ll * t[t[x].ch[1]].size1 * t[t[x].ch[1]].size1;
    t[x].size2 -= t[t[x].ch[1] = y].size1;
    t[x].size3 -= 1ll * t[y].size1 * t[y].size1;
  }
}
inline int findroot(int x) {
  access(x);
  splay(x);
  while (t[x].ch[0]) x = t[x].ch[0];
  splay(x);
  return x;
}
inline void link(int x) {
  splay(x);
  int y = t[x].fa = p[x];
  access(y);
  splay(y);
  t[y].size1 += t[x].size1, t[y].size2 += t[x].size1,
      t[y].size3 += 1ll * t[x].size1 * t[x].size1;
}
inline void cut(int x) {
  access(x);
  splay(x);
  t[x].ch[0] = t[t[x].ch[0]].fa = 0;
  pushup(x);
}
inline long long query(int x) {
  int y = findroot(x);
  return tag[y] ? 1ll * t[t[y].ch[1]].size1 * t[t[y].ch[1]].size1
                : 1ll * t[y].size1 * t[y].size1;
}
inline long long update(int x) {
  tag[x] ^= 1;
  if (!tag[x]) {
    access(x);
    if (x == 1) return t[1].size3 - 1ll * t[1].size1 * t[1].size1;
    long long res = t[x].size3;
    if (!tag[p[x]]) res += query(p[x]);
    link(x);
    return res - query(x);
  } else {
    access(x);
    if (x == 1) return 1ll * t[1].size1 * t[1].size1 - t[1].size3;
    long long res = query(x);
    cut(x), access(x);
    res -= t[x].size3;
    if (!tag[p[x]]) res -= query(p[x]);
    return res;
  }
}
void DFS(int u, int fa) {
  p[u] = fa;
  for (register int i = head[u]; i; i = e[i].next)
    if (e[i].v != fa) DFS(e[i].v, u);
}
int main(void) {
  n = read(), m = read();
  for (register int i = 1; i <= n; ++i)
    q[c[i] = read()].push_back(make_pair(0, i));
  for (register int i = 1; i < n; ++i) {
    u = read(), v = read();
    add(u, v), add(v, u);
  }
  DFS(1, 0);
  for (register int i = 2; i <= n; ++i) link(i);
  for (register int i = 1; i <= m; ++i) {
    u = read(), x = read();
    q[c[u]].push_back(make_pair(i, u));
    q[c[u] = x].push_back(make_pair(i, u));
  }
  for (register int i = 1; i <= n; ++i) {
    for (register int j = 0; j < q[i].size(); ++j)
      ans[q[i][j].first] += update(q[i][j].second);
    for (register int j = 0; j < q[i].size(); ++j) update(q[i][j].second);
  }
  for (register int i = 0; i <= m; ++i) print(ans[i] += ans[i - 1]), pc('\n');
  pc(-1);
  return 0;
}