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>
const int N = 400005;
long long sqr(int x) { return (long long)x * x; }
int n, m, col[N];
int head[N], tot;
struct edge {
  int to, nxt;
} e[N << 1];
void link(int x, int y) {
  e[++tot] = (edge){y, head[x]}, head[x] = tot;
  e[++tot] = (edge){x, head[y]}, head[y] = tot;
}
int fa[N];
int isum[N], sum[N], f[N], ch[N][2];
long long isum2[N], ans[N];
bool rev[N];
void pushup(int x) { sum[x] = sum[ch[x][0]] + sum[ch[x][1]] + 1 + isum[x]; }
bool get(int x) { return ch[f[x]][1] == x; }
bool isroot(int x) { return ch[f[x]][0] != x && ch[f[x]][1] != x; }
void rotate(int x) {
  int y = f[x], z = f[y];
  bool b = get(x);
  if (!isroot(y)) ch[z][get(y)] = x;
  ch[y][b] = ch[x][!b], ch[x][!b] = y;
  f[y] = x, f[x] = z;
  if (ch[y][b]) f[ch[y][b]] = y;
  pushup(y);
}
void splay(int x) {
  for (; !isroot(x); rotate(x))
    if (!isroot(f[x])) rotate(get(x) ^ get(f[x]) ? x : f[x]);
  pushup(x);
}
void add(int x, int t) { isum[x] += t, isum2[x] += sqr(t); }
void del(int x, int t) { isum[x] -= t, isum2[x] -= sqr(t); }
void access(int x) {
  for (int t = 0; x; ch[x][1] = t, t = x, x = f[x])
    splay(x), add(x, sum[ch[x][1]]), del(x, sum[t]);
}
void link(int x) {
  access(x), splay(x), access(fa[x]), splay(fa[x]);
  f[x] = fa[x], add(f[x], sum[x]), pushup(f[x]);
}
void cut(int x) {
  access(x), splay(x);
  f[ch[x][0]] = 0, ch[x][0] = 0, pushup(x);
}
int find_root(int x) {
  access(x), splay(x);
  while (ch[x][0]) x = ch[x][0];
  return splay(x), x;
}
void dfs(int x) {
  for (int i = head[x]; i; i = e[i].nxt)
    if (e[i].to != fa[x]) {
      f[e[i].to] = fa[e[i].to] = x, dfs(e[i].to);
      isum[x] += sum[e[i].to], isum2[x] += sqr(sum[e[i].to]);
    }
  pushup(x);
}
std::vector<std::tuple<int, int, bool>> events[N];
void deal(std::tuple<int, int, bool> e) {
  int x, y;
  bool c;
  std::tie(x, y, c) = e;
  if (col[x] == c) return;
  long long &ret = ans[y];
  if (c) {
    int z = find_root(x);
    long long s1 = sum[ch[z][1]];
    cut(x), access(x), splay(x);
    long long s2 = isum2[x] + sqr(s1 - isum[x] - 1);
    ret += sqr(s1) - s2;
  } else {
    access(x), splay(x);
    long long s2 = isum2[x], q = isum[x] + 1;
    link(x);
    int z = find_root(x);
    long long s1 = sum[ch[z][1]];
    s2 += sqr(s1 - q);
    ret -= sqr(s1) - s2;
  }
  col[x] = c;
}
int main() {
  std::ios::sync_with_stdio(0), std::cin.tie(0);
  std::cin >> n >> m;
  for (int i = 1; i <= n; ++i)
    std::cin >> col[i], events[col[i]].emplace_back(i, 0, 1);
  for (int i = 1, x, y; i < n; ++i) std::cin >> x >> y, link(x, y);
  link(1, n + 1), dfs(n + 1);
  for (int i = 1; i <= m; ++i) {
    int x, y;
    std::cin >> x >> y;
    if (col[x] != y) {
      events[col[x]].emplace_back(x, i, 0);
      events[col[x] = y].emplace_back(x, i, 1);
    }
  }
  std::memset(col, 0, sizeof col);
  for (int i = 1; i <= n; ++i) {
    for (std::tuple<int, int, bool> e : events[i]) deal(e);
    for (std::tuple<int, int, bool> e : events[i])
      deal(std::tuple<int, int, bool>(std::get<0>(e), m + 1, 0));
  }
  std::cout << ans[0] << '\n';
  for (int i = 1; i <= m; ++i) std::cout << (ans[i] += ans[i - 1]) << '\n';
  return 0;
}