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 N = 1e5 + 10, K = 20;
long long W[N], tmp[N], w[N];
struct edge {
  int x, y;
} a[N];
int to[N << 1], fs[N], nx[N << 1], e = 1;
int fr[N];
int vis[N], c[N];
int dep[N], fa[N][K];
inline void add(int x, int y) {
  to[++e] = y;
  nx[e] = fs[x];
  fs[x] = e;
}
void dfs(int x, int f) {
  dep[x] = dep[f] + 1;
  fa[x][0] = f;
  for (int i = 1; i <= 16; ++i) fa[x][i] = fa[fa[x][i - 1]][i - 1];
  for (int i = fs[x]; i; i = nx[i]) {
    int k = to[i];
    if (k == f || vis[k]) continue;
    fr[k] = i >> 1;
    vis[k] = c[i >> 1] = 1;
    dfs(k, x);
    w[i >> 1] = W[k];
    W[x] -= w[i >> 1], W[k] -= w[i >> 1];
  }
}
inline int lca(int x, int y) {
  if (dep[x] < dep[y]) swap(x, y);
  for (int i = 16; ~i; --i)
    if (dep[fa[x][i]] >= dep[y]) x = fa[x][i];
  if (x == y) return x;
  for (int i = 16; ~i; --i)
    if (fa[x][i] ^ fa[y][i]) x = fa[x][i], y = fa[y][i];
  return fa[x][0];
}
inline void climb(int x, int t, int val) {
  for (int tp = -1; x ^ t; x = fa[x][0], tp = -tp) w[fr[x]] += tp * val;
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int x = 1; x <= n; ++x) scanf("%lld", &W[x]), tmp[x] = W[x];
  for (int i = 1; i <= m; ++i) {
    int x, y;
    scanf("%d%d", &x, &y);
    a[i] = (edge){x, y};
    add(x, y), add(y, x);
  }
  vis[1] = 1, dfs(1, 0);
  if (!W[1]) {
    puts("YES");
    for (int x = 1; x <= m; ++x) printf("%lld\n", w[x]);
    return 0;
  }
  if (W[1] & 1) return puts("NO"), 0;
  for (int i = 1; i <= m; ++i) {
    if (c[i]) continue;
    int x = a[i].x, y = a[i].y;
    int t = lca(x, y);
    if ((dep[x] + dep[y] - dep[t] - dep[fa[t][0]]) & 1) {
      int val = W[1] / 2;
      tmp[x] -= val, tmp[y] -= val;
      for (int k = 1; k <= n; ++k) W[k] = tmp[k];
      memset(w, 0, sizeof w);
      memset(vis, 0, sizeof vis);
      vis[1] = 1, dfs(1, 0);
      if (!W[1]) {
        puts("YES");
        w[i] += val;
        for (int k = 1; k <= m; ++k) printf("%lld\n", w[k]);
        return 0;
      }
      tmp[x] += val * 2, tmp[y] += val * 2;
      for (int k = 1; k <= n; ++k) W[k] = tmp[k];
      memset(w, 0, sizeof w);
      memset(vis, 0, sizeof vis);
      vis[1] = 1, dfs(1, 0);
      puts("YES");
      w[i] -= val;
      for (int k = 1; k <= m; ++k) printf("%lld\n", w[k]);
      return 0;
    }
  }
  puts("NO");
  return 0;
}