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;
template <typename T1, typename T2>
inline void chkmin(T1 &x, T2 y) {
  if (x > y) x = y;
}
template <typename T1, typename T2>
inline void chkmax(T1 &x, T2 y) {
  if (x < y) x = y;
}
inline int readChar();
template <class T = int>
inline T readInt();
template <class T>
inline void writeInt(T x, char end = 0);
inline void writeChar(int x);
inline void writeWord(const char *s);
static const int buf_size = 4096;
inline int getChar() {
  static char buf[buf_size];
  static int len = 0, pos = 0;
  if (pos == len) {
    pos = 0, len = fread(buf, 1, buf_size, stdin);
  }
  if (pos == len) {
    return -1;
  }
  return buf[pos++];
}
inline int readChar() {
  int c = getChar();
  while (c <= 32) {
    c = getChar();
  }
  return c;
}
template <class T>
inline T readInt() {
  int s = 1, c = readChar();
  T x = 0;
  if (c == '-') s = -1, c = getChar();
  while ('0' <= c && c <= '9') x = x * 10 + c - '0', c = getChar();
  return s == 1 ? x : -x;
}
static int write_pos = 0;
static char write_buf[buf_size];
inline void writeChar(int x) {
  if (write_pos == buf_size)
    fwrite(write_buf, 1, buf_size, stdout), write_pos = 0;
  write_buf[write_pos++] = x;
}
template <class T>
inline void writeInt(T x, char end) {
  if (x < 0) writeChar('-'), x = -x;
  char s[24];
  int n = 0;
  while (x || !n) s[n++] = '0' + x % 10, x /= 10;
  while (n--) writeChar(s[n]);
  if (end) writeChar(end);
}
inline void writeWord(const char *s) {
  while (*s) writeChar(*s++);
}
struct Flusher {
  ~Flusher() {
    if (write_pos) fwrite(write_buf, 1, write_pos, stdout), write_pos = 0;
  }
} flusher;
const string FILENAME = "input";
const int MAXN = 100001;
int n, m;
vector<int> g[MAXN];
long long c[MAXN];
int used[MAXN];
int pr[MAXN];
int edge[MAXN][2];
long long ans[MAXN];
vector<int> cycle;
int inv(int id, int u) { return u ^ edge[id][0] ^ edge[id][1]; }
int dfs1(int v) {
  for (auto h : g[v]) {
    int u = inv(h, v);
    if (used[u] != -1) {
      if (used[v] == used[u]) {
        cycle.push_back(h);
        int w = v;
        while (w != u) {
          cycle.push_back(pr[w]);
          w = inv(pr[w], w);
        }
        return u;
      }
      continue;
    }
    used[u] = used[v] ^ 1;
    pr[u] = h;
    int w = dfs1(u);
    if (w != -1) {
      return w;
    }
  }
  return -1;
}
void dfs2(int v) {
  for (auto h : g[v]) {
    int u = inv(h, v);
    if (pr[u] != -1) {
      continue;
    }
    pr[u] = h;
    dfs2(u);
    ans[h] += c[u];
    c[v] -= c[u];
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> c[i];
  }
  for (int i = 0; i < m; i++) {
    cin >> edge[i][0] >> edge[i][1];
    edge[i][0]--;
    edge[i][1]--;
    g[edge[i][0]].push_back(i);
    g[edge[i][1]].push_back(i);
  }
  for (int i = 0; i < n; i++) {
    used[i] = -1;
  }
  used[0] = 0;
  int s = dfs1(0);
  for (int i = 0; i < n; i++) {
    pr[i] = -1;
  }
  if (s == -1) {
    pr[0] = -2;
    dfs2(0);
  } else {
    pr[s] = -2;
    dfs2(s);
  }
  if (s == -1 && c[0] != 0) {
    cout << "NO\n";
    return 0;
  }
  chkmax(s, 0);
  for (int i = 0; i < (int)(cycle).size(); i++) {
    if (i & 1) {
      ans[cycle[i]] -= c[s] / 2;
    } else {
      ans[cycle[i]] += c[s] / 2;
    }
  }
  cout << "YES\n";
  for (int i = 0; i < m; i++) {
    cout << ans[i] << '\n';
  }
  return 0;
}