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 read() {
  int s = 0, w = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') w = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9')
    s = (s << 3) + (s << 1) + (ch ^ 48), ch = getchar();
  return s * w;
}
int n, m;
int c[400005], col[400005];
vector<pair<pair<int, int>, int>> tol[400005];
vector<int> e[400005];
struct Ele {
  long long s1;
  int s2;
  Ele(long long r_s1 = 0, int r_s2 = 0) { s1 = r_s1, s2 = r_s2; }
} In;
Ele operator+(Ele a1, Ele a2) {
  return Ele(a1.s1 + a2.s1 + 2ll * a1.s2 * a2.s2, a1.s2 + a2.s2);
}
Ele operator-(Ele a1, Ele a2) {
  return Ele(a1.s1 - a2.s1 - 2ll * (a1.s2 - a2.s2) * a2.s2, a1.s2 - a2.s2);
}
struct LCT {
  long long now;
  int Id;
  struct splay {
    int fa, son[2];
    Ele p, v;
    long long s;
  } a[400005];
  int id(int x) { return a[a[x].fa].son[1] == x; }
  int isrt(int x) { return a[a[x].fa].son[0] != x && a[a[x].fa].son[1] != x; }
  void connect(int x, int y, int k) {
    a[y].son[k] = x;
    if (x) a[x].fa = y;
  }
  void pushup(int x) { a[x].v = a[x].p + a[a[x].son[0]].v + a[a[x].son[1]].v; }
  void rotate(int x) {
    int y = a[x].fa, z = a[y].fa;
    int k1 = id(x), k2 = id(y);
    if (!isrt(y))
      connect(x, z, k2);
    else
      a[x].fa = z;
    connect(a[x].son[k1 ^ 1], y, k1);
    connect(y, x, k1 ^ 1);
    pushup(y), pushup(x);
  }
  void splay(int x) {
    while (!isrt(x)) {
      if (isrt(a[x].fa))
        rotate(x);
      else if (id(x) == id(a[x].fa))
        rotate(a[x].fa), rotate(x);
      else
        rotate(x), rotate(x);
    }
    pushup(x);
  }
  void access(int x) {
    int s = x, y = 0;
    while (x) {
      splay(x);
      a[x].p = a[x].p - a[y].v;
      a[x].p = a[x].p + a[a[x].son[1]].v;
      a[x].s = a[x].s - a[y].v.s1 + a[a[x].son[1]].v.s1;
      a[x].son[1] = y, pushup(x);
      y = x, x = a[x].fa;
    }
    splay(s);
  }
  int find_rt(int x) {
    access(x);
    while (a[x].son[0]) x = a[x].son[0];
    splay(x);
    return x;
  }
  void link(int x, int y) {
    if (!y) {
      access(x);
      now -= a[x].s;
      now += a[x].v.s1;
      return;
    }
    int z = find_rt(y);
    if (c[z] == Id)
      now -= a[z].v.s1;
    else if (a[z].son[1])
      now -= a[a[z].son[1]].v.s1;
    access(x), now -= a[x].s;
    access(y), splay(x);
    a[y].son[1] = x, a[x].fa = y;
    pushup(y);
    z = find_rt(x);
    if (c[z] == Id)
      now += a[z].v.s1;
    else if (a[z].son[1])
      now += a[a[z].son[1]].v.s1;
  }
  void cut(int x, int y) {
    if (!y) {
      access(x);
      now -= a[x].v.s1;
      now += a[x].s;
      return;
    }
    int z = find_rt(x);
    if (c[z] == Id)
      now -= a[z].v.s1;
    else if (a[z].son[1])
      now -= a[a[z].son[1]].v.s1;
    access(x), splay(y);
    a[y].son[1] = a[x].fa = 0;
    pushup(y);
    z = find_rt(y);
    access(x);
    now += a[x].s;
    if (c[z] == Id)
      now += a[z].v.s1;
    else if (a[z].son[1])
      now += a[a[z].son[1]].v.s1;
  }
} T[2];
long long g[400005 * 4], tag[400005 * 4];
void Do(int p, int l, int r, long long k) {
  g[p] += 1ll * (r - l + 1) * k, tag[p] += k;
}
void pushdown(int p, int l, int r) {
  int mid = (l + r) >> 1;
  Do((p << 1), l, mid, tag[p]);
  Do((p << 1 | 1), mid + 1, r, tag[p]);
  tag[p] = 0;
}
void update(int p) { g[p] = g[(p << 1)] + g[(p << 1 | 1)]; }
void modify(int p, int l, int r, int x, int y, long long k) {
  if (x <= l && r <= y) return Do(p, l, r, k);
  pushdown(p, l, r);
  int mid = (l + r) >> 1;
  if (x <= mid) modify((p << 1), l, mid, x, y, k);
  if (y > mid) modify((p << 1 | 1), mid + 1, r, x, y, k);
  update(p);
}
void out_ans(int p, int l, int r) {
  if (l == r) return cout << g[p] << '\n', void();
  pushdown(p, l, r);
  int mid = (l + r) >> 1;
  out_ans((p << 1), l, mid);
  out_ans((p << 1 | 1), mid + 1, r);
  update(p);
}
int F[400005];
void dfs0(int x, int fa) {
  F[x] = T[1].a[x].fa = fa;
  T[1].a[x].p = T[0].a[x].p = In;
  for (int i = 0; i < e[x].size(); i++) {
    int to = e[x][i];
    if (to == fa) continue;
    dfs0(to, x);
  }
  T[1].pushup(x);
  T[1].a[T[1].a[x].fa].p = T[1].a[T[1].a[x].fa].p + T[1].a[x].v;
  T[1].a[T[1].a[x].fa].s += T[1].a[x].v.s1;
}
set<int> S;
int main() {
  T[0].Id = 0, T[1].Id = 1;
  In = Ele(1, 1);
  cin >> n >> m;
  for (int i = 1, x; i <= n; i++) {
    x = read();
    c[i] = 1, col[i] = x;
    tol[x].push_back(make_pair(make_pair(i, 0), 1));
  }
  for (int i = 1, x, y; i < n; i++) {
    x = read();
    y = read();
    e[x].push_back(y);
    e[y].push_back(x);
  }
  dfs0(1, 0);
  T[0].now = n, T[1].now = 1ll * n * n;
  for (int i = 1, p, x; i <= m; i++) {
    p = read();
    x = read();
    if (col[p] == x) continue;
    tol[x].push_back(make_pair(make_pair(p, i), 1));
    tol[col[p]].push_back(make_pair(make_pair(p, i), -1));
    col[p] = x;
  }
  for (int i = 1; i <= n; i++) {
    if (!tol[i].size()) continue;
    int las = -1;
    long long lans;
    for (int j = 0; j < tol[i].size();) {
      int t = tol[i][j].first.second;
      while (t == tol[i][j].first.second && j < tol[i].size()) {
        int p = tol[i][j].first.first;
        if (tol[i][j].second == 1 && c[p]) {
          c[p] = 0;
          S.insert(p);
          T[0].link(p, F[p]);
          T[1].cut(p, F[p]);
        }
        if (tol[i][j].second == -1 && !c[p]) {
          c[p] = 1;
          S.erase(p);
          T[0].cut(p, F[p]);
          T[1].link(p, F[p]);
        }
        j++;
      }
      if (las != -1) modify(1, 0, m, las, t - 1, 1ll * n * n - lans);
      las = t, lans = T[1].now;
    }
    modify(1, 0, m, las, m, 1ll * n * n - lans);
    while (S.size()) {
      int p = *S.begin();
      c[p] = 1;
      S.erase(p);
      T[0].cut(p, F[p]);
      T[1].link(p, F[p]);
    }
  }
  out_ans(1, 0, m);
  return 0;
}