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 N = 4e5 + 7;
inline int read() {
  int sum = 0;
  char c = getchar();
  while (c < '0' || c > '9') c = getchar();
  while (c >= '0' && c <= '9') {
    sum = sum * 10 + c - '0';
    c = getchar();
  }
  return sum;
}
inline void write(long long x) {
  if (x > 9) write(x / 10);
  putchar(x % 10 + '0');
}
struct miaow {
  int ys;
  int siz, lh, rh;
  long long ssum;
  long long xsum, xsum2;
  int fz;
  int son[2], sfa, xfa;
  miaow(int ls = 0, int rs = 0, int sfa = 0, int xfa = 0, int ys = 0,
        int siz = 1, int lh = 1, int rh = 1, long long ssum = 1,
        long long xsum = 0, long long xsum2 = 0, int fz = 0)
      : sfa(sfa),
        xfa(xfa),
        ys(ys),
        siz(siz),
        lh(lh),
        rh(rh),
        ssum(ssum),
        xsum(xsum),
        xsum2(xsum2),
        fz(fz) {
    son[0] = ls, son[1] = rs;
  }
} t[N];
inline int fx(int x) {
  if (!t[x].sfa) return -1;
  return t[t[x].sfa].son[1] == x;
}
inline void upd(int x) {
  if (t[x].fz) return;
  t[x].siz = t[t[x].son[0]].siz + t[t[x].son[1]].siz + 1 + t[x].xsum;
  t[x].lh =
      t[t[x].son[0]].lh + ((t[t[x].son[0]].lh != t[t[x].son[0]].siz || t[x].ys)
                               ? 0
                               : (1 + t[x].xsum + t[t[x].son[1]].lh));
  t[x].rh =
      t[t[x].son[1]].rh + ((t[t[x].son[1]].rh != t[t[x].son[1]].siz || t[x].ys)
                               ? 0
                               : (1 + t[x].xsum + t[t[x].son[0]].rh));
  t[x].ssum = t[x].lh;
}
inline void pdfz(int x) {
  if (!t[x].fz) return;
  t[x].fz = 0;
  swap(t[x].son[0], t[x].son[1]);
  if (t[x].son[0]) {
    swap(t[t[x].son[0]].lh, t[t[x].son[0]].rh);
    t[t[x].son[0]].ssum = t[t[x].son[0]].lh;
    t[t[x].son[0]].fz ^= 1;
  }
  if (t[x].son[1]) {
    swap(t[t[x].son[1]].lh, t[t[x].son[1]].rh);
    t[t[x].son[1]].ssum = t[t[x].son[1]].lh;
    t[t[x].son[1]].fz ^= 1;
  }
  upd(x);
}
inline void rotate(int x) {
  if (!t[x].sfa) return;
  int y = t[x].sfa, k = fx(x), z = t[y].sfa;
  swap(t[x].xfa, t[y].xfa);
  t[y].son[k] = t[x].son[k ^ 1];
  if (t[x].son[k ^ 1]) t[t[x].son[k ^ 1]].sfa = y;
  if (t[y].sfa) {
    int y2 = t[y].sfa, k2 = fx(y);
    t[y2].son[k2] = x;
  }
  t[x].son[k ^ 1] = y;
  t[x].sfa = t[y].sfa;
  t[y].sfa = x;
  upd(y);
  upd(x);
}
inline void pd2(int x) {
  if (t[x].sfa) pd2(t[x].sfa);
  pdfz(x);
}
inline void splay(int x) {
  pd2(x);
  if (!t[x].sfa) return;
  int y = t[x].sfa, k = fx(x);
  while (y) {
    int z = t[y].sfa;
    if (!z) {
      rotate(x);
      return;
    }
    if (fx(y) == k)
      rotate(y);
    else
      rotate(x);
    rotate(x);
    y = t[x].sfa, k = fx(x);
  }
}
inline void access(int x) {
  splay(x);
  if (t[x].son[1]) {
    t[t[x].son[1]].sfa = 0;
    t[t[x].son[1]].xfa = x;
    t[x].xsum += t[t[x].son[1]].ssum;
    t[x].xsum2 += t[t[x].son[1]].ssum * t[t[x].son[1]].ssum;
    t[x].son[1] = 0;
    upd(x);
  }
  int x2 = x;
  while (t[x].xfa) {
    int y = t[x].xfa;
    splay(y);
    if (t[y].son[1]) {
      t[t[y].son[1]].sfa = 0;
      t[t[y].son[1]].xfa = y;
      t[y].xsum += t[t[y].son[1]].ssum;
      t[y].xsum2 += t[t[y].son[1]].ssum * t[t[y].son[1]].ssum;
    }
    t[y].xsum -= t[x].ssum;
    t[y].xsum2 -= t[x].ssum * t[x].ssum;
    t[y].son[1] = x;
    t[x].sfa = y;
    upd(y);
    t[x].xfa = 0;
    x = y;
  }
}
inline void hg(int x) {
  access(x);
  splay(x);
  swap(t[x].lh, t[x].rh);
  t[x].ssum = t[x].lh;
  t[x].fz ^= 1;
}
inline long long cx(int x, int y) {
  hg(x);
  pdfz(x);
  if (t[x].son[1]) {
    upd(t[x].son[1]);
    t[t[x].son[1]].sfa = 0;
    t[t[x].son[1]].xfa = x;
    t[x].xsum += t[t[x].son[1]].ssum;
    t[x].xsum2 += t[t[x].son[1]].ssum * t[t[x].son[1]].ssum;
    t[x].son[1] = 0;
    upd(x);
  }
  t[x].ys = y;
  upd(x);
  long long sum = (t[x].xsum * t[x].xsum - t[x].xsum2),
            sum2 = t[x].xsum * 2 + 1;
  return sum + sum2;
}
inline long long cz(int x, int y) {
  long long sum = cx(x, y);
  return sum;
}
struct meow {
  int a, b, c, d;
  inline bool operator<(const meow& qwe) const {
    return c == qwe.c ? (a == qwe.a ? d < qwe.d : a < qwe.a) : c < qwe.c;
  }
  meow(int a = 0, int b = 0, int c = 0, int d = 0) : a(a), b(b), c(c), d(d) {}
} q[N * 5];
int js = 1;
struct nya {
  int f, t, l;
  nya(int f = 0, int t = 0, int l = 0) : f(f), t(t), l(l) {}
} imap[N * 2 + 1];
int str[N] = {0}, cou = 1;
inline void jb(int f, int t) {
  imap[cou] = nya(f, t, str[f]);
  str[f] = cou++;
  imap[cou] = nya(t, f, str[t]);
  str[t] = cou++;
}
inline void dfs(int o, int fa) {
  for (int i = str[o]; i; i = imap[i].l) {
    int tt = imap[i].t;
    if (tt == fa) continue;
    dfs(tt, o);
    t[o].xsum += t[tt].ssum;
    t[o].xsum2 += t[tt].ssum * t[tt].ssum;
    t[tt].xfa = o;
  }
  upd(o);
}
int cs[N] = {0}, n, m;
long long ans[N] = {0};
int main() {
  n = read(), m = read();
  int zs = m + 1;
  for (int i = 1; i <= n; ++i) {
    int x = read();
    cs[i] = x;
    q[js] = meow(0, i, x, 1);
    ++js;
  }
  for (int i = 1; i < n; ++i) {
    int x = read(), y = read();
    jb(x, y);
  }
  for (int i = 1; i <= m; ++i) {
    int x = read(), y = read();
    q[js] = meow(i, x, cs[x], 0);
    ++js;
    q[js] = meow(i, x, y, 1);
    ++js;
    cs[x] = y;
  }
  for (int i = 1; i <= n; ++i) {
    q[js] = meow(zs, i, cs[i], 0);
    ++js;
  }
  t[0].siz = 0, t[0].lh = 0, t[0].rh = 0, t[0].ssum = 0;
  dfs(1, 0);
  sort(q + 1, q + js);
  int col = 0;
  for (int i = 1; i < js; ++i) {
    int a = q[i].a, b = q[i].b, c = q[i].c, d = q[i].d;
    if (c != col) {
      col = c;
    }
    long long sum = cz(b, d);
    if (d == 0)
      ans[a] -= sum;
    else
      ans[a] += sum;
  }
  write(ans[0]), putchar('\n');
  for (int i = 1; i <= m; ++i) {
    ans[i] += ans[i - 1];
    write(ans[i]);
    putchar('\n');
  }
}