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 read() {
  int x = 0;
  bool flg = false;
  char ch = getchar();
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-') flg = true;
  for (; isdigit(ch); ch = getchar()) x = (x << 3) + (x << 1) + (ch ^ 48);
  return flg ? -x : x;
}
int n, m;
long long w[100010], cw[100010];
struct Rec {
  int u, v;
  bool mrk;
  long long ans;
} rec[100010];
struct Edge {
  int to, nxt, id;
} edge[200010];
int cnt = 1, last[100010];
inline void addedge(int x, int y, int id) {
  edge[++cnt] = (Edge){y, last[x], id}, last[x] = cnt;
  edge[++cnt] = (Edge){x, last[y], id}, last[y] = cnt;
}
namespace B {
int f[100010];
int find(int x) { return f[x] ? f[x] = find(f[x]) : x; }
}  // namespace B
int fat[100010], son[100010], dep[100010], siz[100010];
int top[100010];
void dfs1(int cur, int fat, int dep) {
  ::fat[cur] = fat;
  ::dep[cur] = dep;
  siz[cur] = 1;
  for (int i = last[cur]; i; i = edge[i].nxt)
    if (edge[i].to ^ fat) {
      dfs1(edge[i].to, cur, dep + 1);
      rec[edge[i].id].ans = w[edge[i].to] - cw[edge[i].to];
      cw[cur] += rec[edge[i].id].ans;
      siz[cur] += siz[edge[i].to];
      if (!son[cur] || siz[edge[i].to] > siz[son[cur]]) son[cur] = edge[i].to;
    }
}
void dfs2(int cur, int top) {
  ::top[cur] = top;
  if (siz[cur] == 1) return;
  dfs2(son[cur], top);
  for (int i = last[cur]; i; i = edge[i].nxt)
    if ((edge[i].to ^ fat[cur]) && (edge[i].to ^ son[cur]))
      dfs2(edge[i].to, edge[i].to);
}
void dfs3(int cur) {
  for (int i = last[cur]; i; i = edge[i].nxt)
    if (edge[i].to ^ fat[cur]) {
      dfs3(edge[i].to);
      rec[edge[i].id].ans = w[edge[i].to] - cw[edge[i].to];
      cw[cur] += rec[edge[i].id].ans;
    }
}
int getlca(int x, int y) {
  while (top[x] ^ top[y])
    if (dep[top[x]] < dep[top[y]])
      y = fat[top[y]];
    else
      x = fat[top[x]];
  if (dep[x] < dep[y]) return x;
  return y;
}
int getdis(int x, int y) { return dep[x] + dep[y] - (dep[getlca(x, y)] << 1); }
int main() {
  n = read(), m = read();
  for (int i = 1; i <= n; i++) w[i] = read();
  for (int i = 1, x, y; i <= m; i++) {
    rec[i].u = read(), rec[i].v = read();
    x = B::find(rec[i].u), y = B::find(rec[i].v);
    if (x ^ y) rec[i].mrk = true, addedge(rec[i].u, rec[i].v, i), B::f[y] = x;
  }
  dfs1(1, 0, 1);
  if (w[1] == cw[1]) {
    puts("YES");
    for (int i = 1; i <= m; i++) printf("%lld\n", rec[i].ans);
    return 0;
  }
  dfs2(1, 1);
  long long tmp = w[1] - cw[1];
  for (int i = 1; i <= m; i++) rec[i].ans = 0;
  for (int i = 1; i <= n; i++) cw[i] = 0;
  bool flg = false;
  for (int i = 1; i <= m; i++) {
    if (rec[i].mrk) continue;
    if (!(getdis(rec[i].u, rec[i].v) & 1)) {
      if (dep[rec[i].u] & 1)
        cw[rec[i].u] = cw[rec[i].v] = rec[i].ans = tmp / 2;
      else
        cw[rec[i].u] = cw[rec[i].v] = rec[i].ans = -tmp / 2;
      flg = true;
      break;
    }
  }
  if (!flg) return puts("NO"), 0;
  puts("YES");
  dfs3(1);
  for (int i = 1; i <= m; i++) printf("%lld\n", rec[i].ans);
  return 0;
}