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;
const int MAXN = 1e5 + 7;
const int LogN = 18;
template <typename T>
inline T read() {
  T res = 0, flag = 1;
  char in = getchar();
  while (!isdigit(in)) {
    if (in == '-') flag = -1;
    in = getchar();
  }
  while (isdigit(in)) {
    res = (res << 1) + (res << 3) + in - '0';
    in = getchar();
  }
  return res * flag;
}
template <typename T>
inline void chkmax(T &a, T b) {
  if (a < b) a = b;
}
template <typename T>
inline void chkmin(T &a, T b) {
  if (a > b) a = b;
}
namespace DSU {
int f[MAXN];
inline void init() {
  for (int i = 1; i < MAXN; ++i) f[i] = i;
}
inline int find(int first) {
  if (f[first] == first) return first;
  return f[first] = find(f[first]);
}
inline bool inter(int first, int second) { return find(first) == find(second); }
inline void merge(int first, int second) {
  first = find(first);
  second = find(second);
  f[first] = second;
}
}  // namespace DSU
int n, m;
int C[MAXN], dep[MAXN], fa[MAXN];
int f[LogN][MAXN];
pair<int, int> edge[MAXN];
int dex, head[MAXN], nxt[MAXN << 1], to[MAXN << 1], w[MAXN << 1];
bool vis[MAXN];
long long val[MAXN], Req;
inline void Link(int first, int second, int val) {
  nxt[++dex] = head[first];
  to[dex] = second;
  w[dex] = val;
  head[first] = dex;
}
inline long long dfs(int u, int Fa) {
  for (int i = 1; i < LogN; ++i) f[i][u] = f[i - 1][f[i - 1][u]];
  dep[u] = dep[Fa] + 1;
  long long res = C[u];
  for (int i = head[u]; i; i = nxt[i]) {
    int v = to[i];
    if (v == Fa) continue;
    f[0][v] = u;
    fa[v] = w[i];
    val[w[i]] = dfs(v, u);
    res -= val[w[i]];
  }
  return res;
}
inline int check(int first, int second) {
  int res = dep[first] + dep[second];
  int sx = first, sy = second;
  int A;
  if (dep[first] < dep[second]) swap(first, second);
  for (int i = LogN - 1; i >= 0; --i)
    if (dep[f[i][first]] >= dep[second]) first = f[i][first];
  if (first == second)
    A = first;
  else {
    for (int i = LogN - 1; i >= 0; --i)
      if (f[i][first] != f[i][second]) {
        first = f[i][first];
        second = f[i][second];
      }
    A = f[0][first];
  }
  res = res - dep[A] - dep[f[0][A]];
  if (!(res & 1)) return 0;
  return (dep[sx] & 1) ? 1 : -1;
}
inline void Adapt(int first, int second, long long Val) {
  int sav = Val;
  while (first) {
    val[fa[first]] += sav;
    sav = -sav;
    first = f[0][first];
  }
  sav = Val;
  while (second) {
    val[fa[second]] += sav;
    sav = -sav;
    second = f[0][second];
  }
}
inline void init() {
  n = read<int>();
  m = read<int>();
  DSU::init();
  for (int i = 1; i <= n; ++i) C[i] = read<int>();
  for (int i = 1; i <= m; ++i) {
    edge[i].first = read<int>();
    edge[i].second = read<int>();
  }
  for (int i = 1; i <= m; ++i) {
    if (!DSU::inter(edge[i].first, edge[i].second)) {
      DSU::merge(edge[i].first, edge[i].second);
      Link(edge[i].first, edge[i].second, i);
      Link(edge[i].second, edge[i].first, i);
      vis[i] = true;
    }
  }
  Req = dfs(1, 0);
}
inline void solve() {
  if (!Req) {
    printf("YES\n");
    for (int i = 1; i <= m; ++i) printf("%lld\n", val[i]);
    return;
  }
  if (abs(Req) & 1) printf("NO"), exit(0);
  long long tmp;
  for (int i = 1; i <= m; ++i) {
    if (!vis[i]) {
      if (tmp = check(edge[i].first, edge[i].second)) {
        printf("YES\n");
        tmp = tmp * Req / 2;
        val[i] = tmp;
        Adapt(edge[i].first, edge[i].second, -tmp);
        for (int j = 1; j <= m; ++j) {
          printf("%lld\n", val[j]);
        }
        return;
      }
    }
  }
  printf("NO");
}
int main() {
  init();
  solve();
  return 0;
}