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 long long Maxn = 100010;
const long long inf = 2147483647;
long long read() {
  long long x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9')
    x = (x << 3) + (x << 1) + (ch ^ 48), ch = getchar();
  return x * f;
}
long long n, m, t, a[Maxn], dep[Maxn];
bool vis[Maxn], mark[Maxn << 1];
struct Edge {
  long long x, y, d, next;
} e[Maxn << 1];
long long last[Maxn], len = 1;
void ins(long long x, long long y) {
  long long t = ++len;
  e[t].x = x;
  e[t].y = y;
  e[t].next = last[x];
  last[x] = t;
}
void dfs(long long x, long long fa, long long id) {
  dep[x] = dep[fa] + 1;
  vis[x] = true;
  long long s = 0;
  for (long long i = last[x]; i; i = e[i].next) {
    long long y = e[i].y;
    if (vis[y]) continue;
    mark[i] = mark[i ^ 1] = true;
    dfs(y, x, i);
    s += e[i].d;
  }
  if (id)
    e[id].d = e[id ^ 1].d = a[x] - s;
  else
    t = s;
}
void DFS(long long x, long long id) {
  vis[x] = true;
  long long s = 0;
  for (long long i = last[x]; i; i = e[i].next) {
    long long y = e[i].y;
    if (vis[y]) {
      if (i != (id ^ 1)) s += e[i].d;
      continue;
    }
    DFS(y, i);
    s += e[i].d;
  }
  if (id) e[id].d = e[id ^ 1].d = a[x] - s;
}
int main() {
  n = read(), m = read();
  for (long long i = 1; i <= n; i++) a[i] = read();
  for (long long i = 1; i <= m; i++) {
    long long x = read(), y = read();
    ins(x, y), ins(y, x);
  }
  dep[0] = -1;
  dfs(1, 0, 0);
  long long cnt = 0;
  for (long long i = 2; i <= len; i += 2)
    if (mark[i])
      continue;
    else if (!(abs(dep[e[i].x] - dep[e[i].y]) & 1)) {
      cnt++;
      break;
    }
  if (abs(t - a[1]) % 2) return puts("NO"), 0;
  if (!cnt && a[1] != t) return puts("NO"), 0;
  puts("YES");
  if (a[1] == t) {
    for (long long i = 2; i <= len; i += 2) {
      if (mark[i])
        printf("%lld\n", e[i].d);
      else
        puts("0");
    }
    return 0;
  }
  for (long long i = 2; i <= len; i += 2)
    if (!(abs(dep[e[i].x] - dep[e[i].y]) & 1)) {
      long long x = e[i].x, y = e[i].y;
      if (a[1] > t) {
        if (dep[x] > dep[y]) swap(x, y);
        if (dep[x] & 1)
          e[i].d = e[i ^ 1].d = -abs(t - a[1]) / 2;
        else
          e[i].d = e[i ^ 1].d = abs(t - a[1]) / 2;
      } else {
        if (dep[x] > dep[y]) swap(x, y);
        if (dep[x] & 1)
          e[i].d = e[i ^ 1].d = abs(t - a[1]) / 2;
        else
          e[i].d = e[i ^ 1].d = -abs(t - a[1]) / 2;
      }
      break;
    }
  memset(vis, false, sizeof(vis));
  DFS(1, 0);
  for (long long i = 2; i <= len; i += 2) printf("%lld\n", e[i].d);
}