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>
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
using namespace std;
inline long long get() {
  long long n = 0;
  char c;
  while ((c = getchar()) || 23333) {
    if (c >= '0' && c <= '9') break;
    if (c == '-') goto s;
  }
  n = c - '0';
  while ((c = getchar()) || 23333) {
    if (c >= '0' && c <= '9')
      n = n * 10 + c - '0';
    else
      return (n);
  }
s:
  while ((c = getchar()) || 23333) {
    if (c >= '0' && c <= '9')
      n = n * 10 - c + '0';
    else
      return (n);
  }
}
typedef struct _b {
  long long dest;
  long long nxt;
  long long num;
} bian;
bian memchi[200001];
long long gn = 1;
long long heads[200001], ints[100001], anss[100001], ss[100001], ts[100001],
    v[100001];
inline void add(long long s, long long t, long long num) {
  memchi[gn].dest = t;
  memchi[gn].nxt = heads[s];
  memchi[gn].num = num;
  heads[s] = gn;
  gn++;
}
unsigned char col[100001];
long long que[100001];
unsigned char istree[100001];
void print(long long num) {
  if (num < 0) putchar('-'), num = -num;
  if (num >= 10) print(num / 10);
  putchar(num % 10 + '0');
}
long long find(long long n) {
  if (ints[n] == n) return (n);
  return (ints[n] = find(ints[n]));
}
void dfs(long long pt, long long baba) {
  for (register long long i = heads[pt]; i; i = memchi[i].nxt) {
    if (memchi[i].dest == baba) continue;
    dfs(memchi[i].dest, pt);
    anss[memchi[i].num] += v[memchi[i].dest];
    v[pt] -= v[memchi[i].dest];
    v[memchi[i].dest] = 0;
  }
}
long long tmp[100001];
void efs(long long pt, long long baba) {
  for (register long long i = heads[pt]; i; i = memchi[i].nxt) {
    if (memchi[i].dest == baba) continue;
    efs(memchi[i].dest, pt);
    tmp[pt] -= tmp[memchi[i].dest];
  }
}
signed main() {
  long long n = get(), m = get();
  for (register long long i = 1; i <= n; i++)
    v[i] = get(), ints[i] = i, col[i] = 2;
  for (register long long i = 1; i <= m; i++) {
    ss[i] = get(), ts[i] = get();
    long long aa = find(ss[i]), ab = find(ts[i]);
    if (aa != ab) {
      ints[aa] = ab;
      add(ss[i], ts[i], i);
      add(ts[i], ss[i], i);
      istree[i] = 1;
    }
  }
  register long long head = 0, tail = 1;
  que[0] = 1;
  col[1] = 0;
  do {
    long long me = que[head];
    head++;
    for (register long long i = heads[me]; i; i = memchi[i].nxt) {
      if (col[memchi[i].dest] != 2) continue;
      col[memchi[i].dest] = col[me] ^ 1;
      que[tail] = memchi[i].dest;
      tail++;
    }
  } while (head < tail);
  dfs(1, 0);
  if (((v[1] < 0) ? -(v[1]) : v[1]) & 1) {
    printf("NO\n");
    return (0);
  }
  if (v[1] == 0) {
    printf("YES\n");
    for (register long long i = 1; i <= m; i++) print(anss[i]), putchar('\n');
    return (0);
  }
  for (register long long a = 1; a <= m; a++) {
    if (istree[a]) continue;
    if (col[ss[a]] != col[ts[a]]) continue;
    printf("YES\n");
    long long val = v[1] / 2;
    tmp[ss[a]]++;
    tmp[ts[a]]++;
    efs(1, 0);
    if (tmp[1] == 2) {
      v[ss[a]] -= val;
      v[ts[a]] -= val;
      anss[a] = val;
    } else {
      v[ss[a]] += val;
      v[ts[a]] += val;
      anss[a] = -val;
    }
    dfs(1, 0);
    for (register long long i = 1; i <= m; i++) print(anss[i]), putchar('\n');
    return (0);
  }
  printf("NO\n");
  return (0);
}