Problem: You are given a connected undirected graph with n vertices and m edges. The vertices are enumerated from 1 to n. 

You are given n integers c1, c2, ..., cn, each of them is between  - n and n, inclusive. It is also guaranteed that the parity of cv equals the parity of degree of vertex v. The degree of a vertex is the number of edges connected to it.

You are to write a weight between  - 2·n2 and 2·n2 (inclusive) on each edge in such a way, that for each vertex v the sum of weights on edges connected to this vertex is equal to cv, or determine that this is impossible.

Input

The first line contains two integers n and m (2 ≤ n ≤ 105, n - 1 ≤ m ≤ 105) — the number of vertices and the number of edges.

The next line contains n integers c1, c2, ..., cn ( - n ≤ ci ≤ n), where ci is the required sum of weights of edges connected to vertex i. It is guaranteed that the parity of ci equals the parity of degree of vertex i.

The next m lines describe edges of the graph. The i-th of these lines contains two integers ai and bi (1 ≤ ai, bi ≤ n; ai ≠ bi), meaning that the i-th edge connects vertices ai and bi.

It is guaranteed that the given graph is connected and does not contain loops and multiple edges.

Output

If there is no solution, print "NO".

Otherwise print "YES" and then m lines, the i-th of them is the weight of the i-th edge wi ( - 2·n2 ≤ wi ≤ 2·n2).

Examples

Input

3 3
2 2 2
1 2
2 3
1 3


Output

YES
1
1
1


Input

4 3
-1 0 2 1
1 2
2 3
3 4


Output

YES
-1
1
1


Input

6 6
3 5 5 5 1 5
1 4
3 2
4 3
4 5
3 5
5 6


Output

YES
3
5
3
-1
-3
5


Input

4 4
4 4 2 4
1 2
2 3
3 4
4 1


Output

NO

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
int n, m;
int c[100010];
int x[100010], y[100010];
vector<int> t[100010];
int f[100010];
int find(int x) { return (f[x] == -1 ? x : f[x] = find(f[x])); }
int fa[100010], dep[100010];
int dfn[100010], rnk[100010], totn = 0;
int siz[100010], son[100010], top[100010];
void dfs1(int k) {
  dep[k] = dep[fa[k]] + 1;
  siz[k] = 1;
  for (vector<int>::iterator it = t[k].begin(); it != t[k].end(); ++it) {
    if (*it == fa[k]) continue;
    fa[*it] = k;
    dfs1(*it);
    siz[k] += siz[*it];
    if (son[k] == 0 || siz[*it] > siz[son[k]]) son[k] = *it;
  }
  return;
}
void dfs2(int k, int tp) {
  dfn[k] = ++totn;
  rnk[totn] = k;
  top[k] = tp;
  if (son[k]) dfs2(son[k], tp);
  for (vector<int>::iterator it = t[k].begin(); it != t[k].end(); ++it) {
    if (*it == fa[k] || *it == son[k]) continue;
    dfs2(*it, *it);
  }
  return;
}
int LCA(int a, int b) {
  while (top[a] != top[b]) {
    if (dep[top[a]] < dep[top[b]]) swap(a, b);
    a = fa[top[a]];
  }
  return (dep[a] < dep[b] ? a : b);
}
long long v[100010];
void dfs3(int k) {
  v[k] = c[k];
  for (vector<int>::iterator it = t[k].begin(); it != t[k].end(); ++it) {
    if (*it == fa[k]) continue;
    dfs3(*it);
    v[k] -= v[*it];
  }
  return;
}
long long ve[100010];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i) scanf("%d", &c[i]);
  for (int i = 1; i <= m; ++i) scanf("%d%d", &x[i], &y[i]);
  memset(f, -1, sizeof(f));
  for (int i = 1; i <= m; ++i) {
    int p = find(x[i]), q = find(y[i]);
    if (p == q) continue;
    f[p] = q;
    t[x[i]].push_back(y[i]);
    t[y[i]].push_back(x[i]);
  }
  dfs1(1);
  dfs2(1, 1);
  dfs3(1);
  for (int i = 1; i <= m; ++i) {
    if (fa[x[i]] == y[i] || fa[y[i]] == x[i]) continue;
    if ((dep[x[i]] + dep[y[i]] - 2 * dep[LCA(x[i], y[i])]) % 2 == 0) {
      int val = v[1] / 2;
      val = val * (dep[x[i]] % 2 == 0 ? -1 : 1);
      ve[i] = val;
      c[x[i]] -= val;
      c[y[i]] -= val;
      break;
    }
  }
  dfs3(1);
  if (v[1] != 0) {
    puts("NO");
    return 0;
  }
  puts("YES");
  for (int i = 1; i <= m; ++i) {
    if (fa[x[i]] == y[i] || fa[y[i]] == x[i]) {
      if (dep[x[i]] < dep[y[i]]) swap(x[i], y[i]);
      ve[i] = v[x[i]];
    }
    printf("%lld\n", ve[i]);
  }
  return 0;
}