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;
int c[400001];
vector<int> adjList[400001];
vector<pair<int, int> > events[400001];
long long int diff[400002], ans = 0;
int parent[400001];
int doDFS(int u, int p) {
  int i;
  parent[u] = p;
  for (i = 0; i < adjList[u].size(); i++) {
    int v = adjList[u][i];
    if (v != p) doDFS(v, u);
  }
  return 0;
}
struct node {
  node *l, *r, *p;
  int k, s, v;
  long long int sq;
};
node *nodes[400001];
int size(node *r) {
  if (r == NULL)
    return 0;
  else
    return r->s;
}
int update(node *r) {
  if (r != NULL) r->s = size(r->l) + size(r->r) + r->v + 1;
  return 0;
}
int isRoot(node *r) {
  return (r->p == NULL) || ((r->p->l != r) && (r->p->r != r));
}
int rotL(node *r) {
  node *n = r->r;
  r->r = n->l;
  if (n->l != NULL) n->l->p = r;
  n->p = r->p;
  if (r->p != NULL) {
    if (r->p->l == r)
      r->p->l = n;
    else if (r->p->r == r)
      r->p->r = n;
  }
  n->l = r, r->p = n;
  update(r), update(n);
  return 0;
}
int rotR(node *r) {
  node *n = r->l;
  r->l = n->r;
  if (n->r != NULL) n->r->p = r;
  n->p = r->p;
  if (r->p != NULL) {
    if (r->p->l == r)
      r->p->l = n;
    else if (r->p->r == r)
      r->p->r = n;
  }
  n->r = r, r->p = n;
  update(r), update(n);
  return 0;
}
int splay(node *n) {
  if (n == NULL) return 0;
  while (!isRoot(n)) {
    if (isRoot(n->p)) {
      if (n == n->p->l)
        rotR(n->p);
      else
        rotL(n->p);
    } else if ((n->p->l == n) && (n->p->p->l == n->p))
      rotR(n->p->p), rotR(n->p);
    else if ((n->p->r == n) && (n->p->p->r == n->p))
      rotL(n->p->p), rotL(n->p);
    else if ((n->p->l == n) && (n->p->p->r == n->p))
      rotR(n->p), rotL(n->p);
    else
      rotL(n->p), rotR(n->p);
  }
  return 0;
}
int access(node *n) {
  node *p = NULL, *o = n;
  while (n != NULL) {
    splay(n);
    n->v += size(n->r), n->sq += (long long int)size(n->r) * size(n->r);
    n->r = p, n->v -= size(p), n->sq -= (long long int)size(p) * size(p);
    update(n), p = n, n = n->p;
  }
  splay(o);
  return 0;
}
int find(int k) {
  node *n = nodes[k];
  access(n);
  while (n->l != NULL) n = n->l;
  splay(n);
  return n->k;
}
int link(int a, int b) {
  int ra = find(a), rb = find(b);
  ans -= nodes[ra]->sq + (long long int)(nodes[ra]->s - nodes[ra]->v - 1) *
                             (nodes[ra]->s - nodes[ra]->v - 1);
  ans -= nodes[rb]->sq + (long long int)(nodes[rb]->s - nodes[rb]->v - 1) *
                             (nodes[rb]->s - nodes[rb]->v - 1);
  access(nodes[a]);
  nodes[a]->p = nodes[b];
  nodes[b]->v += nodes[a]->s,
      nodes[b]->sq += (long long int)nodes[a]->s * nodes[a]->s;
  access(nodes[a]);
  rb = find(b);
  ans += nodes[rb]->sq + (long long int)(nodes[rb]->s - nodes[rb]->v - 1) *
                             (nodes[rb]->s - nodes[rb]->v - 1);
  return 0;
}
int cut(int k) {
  node *n = nodes[k];
  int r = find(k);
  ans -= nodes[r]->sq + (long long int)(nodes[r]->s - nodes[r]->v - 1) *
                            (nodes[r]->s - nodes[r]->v - 1);
  access(n);
  n->l->p = NULL;
  r = n->l->k;
  n->l = NULL;
  update(n), access(n);
  r = find(r);
  ans += nodes[r]->sq + (long long int)(nodes[r]->s - nodes[r]->v - 1) *
                            (nodes[r]->s - nodes[r]->v - 1);
  ans += nodes[k]->sq + (long long int)(nodes[k]->s - nodes[k]->v - 1) *
                            (nodes[k]->s - nodes[k]->v - 1);
  return 0;
}
int main() {
  int i;
  int n, m, u, v;
  scanf("%d %d", &n, &m);
  for (i = 1; i <= n; i++)
    scanf("%d", &c[i]), events[c[i]].push_back(make_pair(0, i));
  for (i = 0; i < n - 1; i++) {
    scanf("%d %d", &u, &v);
    adjList[u].push_back(v);
    adjList[v].push_back(u);
  }
  for (i = 1; i <= m; i++) {
    scanf("%d %d", &u, &v);
    events[c[u]].push_back(make_pair(i, -u));
    c[u] = v;
    events[c[u]].push_back(make_pair(i, u));
  }
  for (i = 1; i <= n; i++) events[c[i]].push_back(make_pair(m + 1, -i));
  int j;
  doDFS(1, 0);
  for (i = 0; i <= n; i++) {
    nodes[i] = new node;
    nodes[i]->l = nodes[i]->r = nodes[i]->p = NULL;
    nodes[i]->k = i, nodes[i]->s = 1, nodes[i]->v = nodes[i]->sq = 0;
  }
  for (i = 1; i <= n; i++) link(i, parent[i]);
  for (i = 1; i <= n; i++) {
    for (j = 0; j < events[i].size(); j++) {
      diff[(j == 0) ? 0 : events[i][j - 1].first] += ans;
      diff[events[i][j].first] -= ans;
      if (events[i][j].second > 0)
        cut(events[i][j].second);
      else
        link(-events[i][j].second, parent[-events[i][j].second]);
    }
    if (!events[i].empty())
      diff[events[i].back().first] += ans;
    else
      diff[0] += (long long int)n * n;
  }
  for (i = 1; i <= m; i++) diff[i] += diff[i - 1];
  for (i = 0; i <= m; i++)
    printf("%I64d\n", (long long int)n * n * n - diff[i]);
  return 0;
}