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 = 400001;
struct op {
  int t, u;
  op() {}
  op(int t, int u) : t(t), u(u) {}
};
struct node {
  node *prt, *path;
  union {
    struct {
      node *ls, *rs;
    };
    node *ch[2];
  };
  int u;
  bool b, sb;
  int f, sf;
  long long g;
} N[maxn];
void update(node *u);
void rotate(node *u);
void splay(node *u);
node *find_first(node *u);
void expose(node *u);
bool splice(node *u);
void access(node *u);
int getf(node *u);
long long getg(node *u);
long long change(int tu);
long long ans[maxn];
vector<op> ord[maxn];
vector<int> init[maxn];
int cur[maxn];
vector<int> adj[maxn];
int prt[maxn];
int f[maxn];
long long g[maxn];
int n, m;
void dfs(int u);
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i <= n; i++) {
    N[i].prt = N[i].path = NULL;
    N[i].ls = N[i].rs = NULL;
    N[i].b = N[i].sb = 0;
    N[i].u = i;
  }
  N[0].b = N[0].sb = 1;
  for (int i = 1; i <= n; i++) {
    int x;
    scanf("%d", &x);
    init[x].push_back(i);
    cur[i] = x;
  }
  for (int i = 1; i < n; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  dfs(1);
  for (int i = 1; i <= n; i++) {
    N[i].path = &N[prt[i]];
    N[i].sf = N[i].f = f[i];
    N[i].g = g[i];
  }
  N[0].sf = N[0].f = n + 1;
  N[0].g = (long long)n * n;
  for (int i = 1; i <= m; i++) {
    int u, x;
    scanf("%d%d", &u, &x);
    ord[cur[u]].push_back(op(i, u));
    cur[u] = x;
    ord[cur[u]].push_back(op(i, u));
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < init[i].size(); j++) {
      int u = init[i][j];
      ans[0] += change(u);
    }
    for (int j = 0; j < ord[i].size(); j++) {
      ans[ord[i][j].t] += change(ord[i][j].u);
    }
    for (int j = ord[i].size() - 1; j >= 0; j--) {
      change(ord[i][j].u);
    }
    for (int j = init[i].size() - 1; j >= 0; j--) {
      change(init[i][j]);
    }
  }
  printf("%lld\n", ans[0]);
  for (int i = 1; i <= m; i++) {
    ans[i] += ans[i - 1];
    printf("%lld\n", ans[i]);
  }
  return 0;
}
void dfs(int u) {
  f[u] = 1;
  for (int i = 0; i < adj[u].size(); i++) {
    int v = adj[u][i];
    if (v == prt[u]) continue;
    prt[v] = u;
    dfs(v);
    f[u] += f[v];
    g[u] += (long long)f[v] * f[v];
  }
}
void update(node *u) {
  u->sb = u->b;
  u->sf = u->f;
  if (u->ls) u->sb |= u->ls->sb, u->sf += u->ls->sf;
  if (u->rs) u->sb |= u->rs->sb, u->sf += u->rs->sf;
}
bool relation(node *u) { return u == u->prt->rs; }
void rotate(node *u) {
  swap(u->path, u->prt->path);
  bool rel = relation(u);
  if (u->prt->prt) u->prt->prt->ch[relation(u->prt)] = u;
  u->prt->ch[rel] = u->ch[!rel];
  if (u->ch[!rel]) u->ch[!rel]->prt = u->prt;
  u->ch[!rel] = u->prt;
  u->prt = u->prt->prt;
  u->ch[!rel]->prt = u;
  update(u->ch[!rel]);
  update(u);
}
void splay(node *u) {
  while (u->prt) {
    if (!u->prt->prt) {
      rotate(u);
      break;
    }
    if (relation(u) == relation(u->prt)) {
      rotate(u->prt);
      rotate(u);
    } else {
      rotate(u);
      rotate(u);
    }
  }
}
void expose(node *u) {
  splay(u);
  if (!u->rs) return;
  swap(u->rs->prt, u->rs->path);
  u->rs = find_first(u->rs);
  splay(u->rs);
  if (u->rs->b == 0) {
    int f = getf(u->rs);
    u->f += f;
    u->g += (long long)f * f;
  }
  u->rs = NULL;
  update(u);
}
bool splice(node *u) {
  splay(u);
  if (!u->path) return 0;
  u = find_first(u);
  splay(u);
  expose(u->path);
  if (u->b == 0) {
    int f = getf(u);
    u->path->f -= f;
    u->path->g -= (long long)f * f;
  }
  u->path->rs = u;
  swap(u->path, u->prt);
  update(u->prt);
  return 1;
}
void access(node *u) {
  expose(u);
  while (splice(u))
    ;
}
int bwl(node *u) { return u ? u->sb : 0; }
int fwl(node *u) { return u ? u->sf : 0; }
int getf(node *u) {
  splay(u);
  int ans = u->f;
  if (!u->rs) return ans;
  u = u->rs;
  while (u) {
    if (bwl(u->ls) || u->b)
      u = u->ls;
    else {
      ans += fwl(u->ls) + u->f;
      u = u->rs;
    }
  }
  return ans;
}
node *find_first(node *u) {
  while (u->ls) u = u->ls;
  return u;
}
long long getg(node *u) {
  splay(u);
  long long ans = u->g;
  if (!u->rs) return ans;
  node *mch = find_first(u->rs);
  int f = 0;
  if (mch->b == 0) f = getf(mch);
  ans = ans + (long long)f * f;
  return ans;
}
node *find_p(node *u) {
  access(u);
  splay(u);
  u = u->ls;
  while (1) {
    if (bwl(u->rs))
      u = u->rs;
    else if (!u->b)
      u = u->ls;
    else
      break;
  }
  return u;
}
long long change(int tu) {
  node *u = &N[tu];
  node *p = find_p(u);
  long long ans = -getg(p);
  if (u->b == 0) {
    ans += getg(u);
    splay(u);
    u->b = 1;
    update(u);
  } else {
    ans -= getg(u);
    splay(u);
    u->b = 0;
    update(u);
  }
  ans += getg(p);
  return -ans;
}