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>
namespace in {
char buf[1 << 21], *p1 = buf, *p2 = buf;
inline int getc() {
  return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2)
             ? EOF
             : *p1++;
}
template <typename T>
inline void read(T& t) {
  t = 0;
  int f = 0;
  char ch = getc();
  while (!isdigit(ch)) {
    if (ch == '-') f = 1;
    ch = getc();
  }
  while (isdigit(ch)) {
    t = t * 10 + ch - 48;
    ch = getc();
  }
  if (f) t = -t;
}
template <typename T, typename... Args>
inline void read(T& t, Args&... args) {
  read(t);
  read(args...);
}
char getC() {
  char c = getc();
  while (!isalpha(c)) c = getc();
  return c;
}
}  // namespace in
namespace out {
char buffer[1 << 21];
int p1 = -1;
const int p2 = (1 << 21) - 1;
inline void flush() { fwrite(buffer, 1, p1 + 1, stdout), p1 = -1; }
inline void putc(const char& x) {
  if (p1 == p2) flush();
  buffer[++p1] = x;
}
template <typename T>
void write(T x) {
  static char buf[25];
  static int len = -1;
  if (x >= 0) {
    do {
      buf[++len] = x % 10 + 48, x /= 10;
    } while (x);
  } else {
    putc('-');
    do {
      buf[++len] = -(x % 10) + 48, x /= 10;
    } while (x);
  }
  while (len >= 0) putc(buf[len]), --len;
}
inline void puts(char* s) {
  int now = 0;
  while (s[now] != '\0') putc(s[now]), now++;
  putc('\n');
}
}  // namespace out
using namespace std;
const int N = 4e5 + 100;
int pa[N], f[N], c[N][2], sz[N], szi[N];
long long sz2i[N];
int n, m, col[N];
long long ans, delta[N];
bool flag[N];
vector<pair<int, int>> upd[N];
void pushup(int x) { sz[x] = sz[c[x][0]] + 1 + sz[c[x][1]] + szi[x]; }
void rotate(int x) {
  int fa = f[x], ffa = f[fa], k = (c[f[(x)]][1] == (x)), w = c[x][!k];
  if ((c[f[(fa)]][0] == (fa) || c[f[(fa)]][1] == (fa)))
    c[ffa][(c[f[(fa)]][1] == (fa))] = x;
  c[x][!k] = fa;
  c[fa][k] = w;
  if (w) f[w] = fa;
  f[fa] = x;
  f[x] = ffa;
  pushup(fa);
  pushup(x);
}
void splay(int x) {
  while ((c[f[(x)]][0] == (x) || c[f[(x)]][1] == (x))) {
    int fa = f[x];
    if ((c[f[(fa)]][0] == (fa) || c[f[(fa)]][1] == (fa)))
      rotate((c[f[(x)]][1] == (x)) == (c[f[(fa)]][1] == (fa)) ? fa : x);
    rotate(x);
  }
  pushup(x);
}
void access(int x) {
  for (int y = 0; x; x = f[y = x]) {
    splay(x);
    szi[x] += sz[c[x][1]];
    szi[x] -= sz[y];
    sz2i[x] += (1ll * sz[c[x][1]] * sz[c[x][1]]);
    sz2i[x] -= (1ll * sz[y] * sz[y]);
    c[x][1] = y;
    pushup(x);
  }
}
int findroot(int x) {
  access(x);
  splay(x);
  while (c[x][0]) x = c[x][0];
  splay(x);
  return x;
}
void add(int x) {
  int fa = pa[x];
  splay(x);
  ans -= sz2i[x] + (1ll * sz[c[x][1]] * sz[c[x][1]]);
  int z = findroot(fa);
  access(x);
  splay(z);
  ans -= (1ll * sz[c[z][1]] * sz[c[z][1]]);
  f[x] = fa;
  splay(fa);
  szi[fa] += sz[x];
  sz2i[fa] += (1ll * sz[x] * sz[x]);
  pushup(fa);
  access(x);
  splay(z);
  ans += (1ll * sz[c[z][1]] * sz[c[z][1]]);
}
void del(int x) {
  int fa = pa[x];
  access(x);
  ans += sz2i[x];
  int z = findroot(fa);
  access(x);
  splay(z);
  ans -= (1ll * sz[c[z][1]] * sz[c[z][1]]);
  splay(x);
  c[x][0] = f[c[x][0]] = 0;
  pushup(x);
  splay(z);
  ans += (1ll * sz[c[z][1]] * sz[c[z][1]]);
}
vector<int> e[N];
void dfs(int u) {
  for (auto v : e[u])
    if (v != pa[u]) pa[v] = u, dfs(v);
}
signed main() {
  long long lst = 0;
  in::read(n, m);
  for (int i = 1; i <= n; i++) in::read(col[i]), upd[col[i]].push_back({i, 0});
  for (int i = 1; i <= n + 1; i++) sz[i] = 1;
  for (int i = 1, u, v; i < n; i++)
    in::read(u, v), e[u].push_back(v), e[v].push_back(u);
  for (int i = 1, u, x; i <= m; i++) {
    in::read(u, x);
    upd[col[u]].push_back({u, i});
    col[u] = x;
    upd[col[u]].push_back({u, i});
  }
  pa[1] = n + 1;
  dfs(1);
  for (int i = 1; i <= n; i++) add(i);
  for (int i = 1; i <= n; i++) {
    if (upd[i].size() == 0) {
      delta[0] += 1ll * n * n;
      continue;
    }
    if (upd[i][0].second) {
      delta[0] += 1ll * n * n;
      lst = 1ll * n * n;
    } else
      lst = 0;
    for (int j = 0; j < upd[i].size(); j++) {
      int u = upd[i][j].first;
      if (flag[u] ^= 1)
        del(u);
      else
        add(u);
      if (j == upd[i].size() - 1 || upd[i][j + 1].second != upd[i][j].second) {
        delta[upd[i][j].second] += ans - lst;
        lst = ans;
      }
    }
    for (int j = upd[i].size() - 1; j >= 0; j--) {
      int u = upd[i][j].first;
      if (flag[u] ^= 1)
        del(u);
      else
        add(u);
    }
  }
  ans = 1ll * n * n * n;
  for (int i = 0; i <= m; i++) {
    ans -= delta[i];
    out::write(ans);
    out::putc('\n');
  }
  out::flush();
  return 0;
}