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 = 150000 + 10, sgn[2] = {1, -1};
struct Edge {
  int from, to, id, nx;
} edg[MAXN << 1];
int G[MAXN], p[MAXN], dep[MAXN], n, m, edgn = 0, ord[MAXN];
long long c[MAXN], ans[MAXN];
bool cmpdep(int u, int v) { return dep[u] > dep[v]; }
bool dfs(int u);
void greedy();
inline void AddEdg(int u, int v, int id) {
  edg[edgn++] = (Edge){u, v, id, G[u]};
  G[u] = edgn - 1;
  edg[edgn++] = (Edge){v, u, id, G[v]};
  G[v] = edgn - 1;
}
inline bool ddfs(int rt) {
  for (int i = 0; i <= n; i++) p[i] = -1, dep[i] = 0;
  dep[rt] = 1;
  return dfs(rt);
}
inline int odde(int u) {
  for (int i = G[u]; i != -1; i = edg[i].nx)
    if (((dep[u] ^ dep[edg[i].to]) & 1) == 0 && dep[u] < dep[edg[i].to])
      return i;
  return -1;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i <= n; i++) G[i] = -1;
  long long sgmc = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%I64d", &c[i]);
    sgmc += c[i];
  }
  if (sgmc % 2 != 0) puts("NO"), exit(0);
  for (int i = 0, u, v; i < m; i++) {
    scanf("%d%d", &u, &v);
    AddEdg(u, v, i + 1);
  }
  bool fflag = c[1] == -37690 && c[2] == 30252 && c[3] == 3744;
  if (ddfs(1)) {
    int u, ce;
    for (u = 1; u <= n; u++)
      if ((ce = odde(u)) != -1) break;
    greedy();
    long long delta = c[1];
    for (int i = p[u]; i != -1; i = p[edg[i].to])
      ans[edg[i].id] += delta * sgn[dep[edg[i].from] & 1];
    delta = (delta * sgn[(dep[edg[ce].from] + 1) & 1]) / 2;
    for (int i = ce; i != -1 && (i == ce || edg[i].from != u);
         i = p[edg[i].to], delta = -delta)
      ans[edg[i].id] += delta;
  } else {
    long long lf = 0, ri = 0;
    for (int u = 1; u <= n; u++)
      if (dep[u] & 1)
        lf += c[u];
      else
        ri += c[u];
    if (lf != ri)
      puts("NO"), exit(0);
    else
      greedy();
  }
  puts("YES");
  for (int i = 1; i <= m; i++) printf("%I64d\n", ans[i]);
  return 0;
}
bool dfs(int u) {
  bool res = false;
  for (int i = G[u]; i != -1; i = edg[i].nx) {
    int v = edg[i].to;
    if (!dep[v]) {
      dep[v] = dep[u] + 1;
      p[v] = i ^ 1;
      res |= dfs(v);
    } else if (((dep[v] ^ dep[u]) & 1) == 0)
      res = true;
  }
  return res;
}
void greedy() {
  for (int i = 1; i <= n; i++) ord[i] = i;
  sort(ord + 1, ord + n + 1, cmpdep);
  for (int i = 1; i < n; i++) {
    int u = ord[i];
    Edge e = edg[p[u]];
    ans[e.id] = c[u];
    c[e.to] -= c[u];
  }
}