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 N = 1 << 17;
int n, m;
vector<int> e[N];
int c[N];
int u1[N], u2[N];
int col[N];
long long ans[N];
long long a[N];
void dfs1(int v, int pr) {
  col[v] = 1;
  a[v] = 0;
  for (int id : e[v]) {
    if (id == pr) continue;
    int to = u1[id] ^ u2[id] ^ v;
    if (col[to] == 0) {
      dfs1(to, id);
      ans[id] = c[to] - a[to];
      a[to] += ans[id];
      a[v] += ans[id];
    } else if (col[to] == 1) {
      ans[id] = 0;
    } else {
      continue;
    }
  }
  col[v] = 2;
}
vector<int> cycle;
int col2[N];
int part[N];
vector<int> st;
void dfs2(int v, int pr, int cc) {
  col2[v] = 1;
  a[v] = 0;
  part[v] = cc;
  st.push_back(pr);
  for (int id : e[v]) {
    if (id == pr) continue;
    int to = u1[id] ^ u2[id] ^ v;
    if (col2[to] == 0) {
      dfs2(to, id, cc ^ 1);
    } else if (col2[to] == 1) {
      if (part[v] == part[to] && cycle.empty()) {
        cycle.push_back(id);
        for (int i = (int)st.size() - 1;; i--) {
          if (st[i] == -1) break;
          cycle.push_back(st[i]);
          if (u1[st[i]] == to || u2[st[i]] == to) break;
        }
      }
    } else {
      continue;
    }
  }
  st.pop_back();
  col2[v] = 2;
}
int main() {
  while (scanf("%d%d", &n, &m) == 2) {
    for (int i = 0; i < n; i++) {
      e[i].clear();
    }
    for (int i = 0; i < n; i++) scanf("%d", &c[i]);
    for (int i = 0; i < m; i++) {
      scanf("%d%d", &u1[i], &u2[i]);
      u1[i]--;
      u2[i]--;
      e[u1[i]].push_back(i);
      e[u2[i]].push_back(i);
    }
    for (int i = 0; i < n; i++) {
      col[i] = 0;
      col2[i] = 0;
      part[i] = -1;
    }
    bool ok = 1;
    for (int i = 0; i < n; i++) {
      if (col[i] != 0) continue;
      assert(i == 0);
      cycle.clear();
      dfs2(i, -1, 0);
      int v = i;
      if (!cycle.empty()) {
        v = u1[cycle[0]];
        assert(cycle.size() % 2 == 1);
        int iid = cycle.back();
        if (!(u1[iid] == v || u2[iid] == v)) {
          rotate(cycle.begin(), cycle.begin() + 1, cycle.end());
        }
      }
      dfs1(v, -1);
      if (a[v] != c[v]) {
        if (cycle.empty()) {
          ok = 0;
        } else {
          assert((a[v] - c[v]) % 2 == 0);
          long long o = (c[v] - a[v]) / 2;
          int iid = cycle.back();
          bool f = u1[iid] == v || u2[iid] == v;
          for (int j = 0; j < (int)cycle.size(); j++) {
            ans[cycle[j]] += o * ((j % 2) ? -1 : 1);
          }
        }
      }
    }
    if (ok) {
      vector<long long> d(n);
      for (int i = 0; i < m; i++) {
        d[u1[i]] += ans[i];
        d[u2[i]] += ans[i];
      }
      for (int i = 0; i < n; i++) {
        assert(d[i] == c[i]);
      }
      printf("YES\n");
      for (int i = 0; i < m; i++) printf("%lld\n", ans[i]);
    } else {
      printf("NO\n");
    }
  }
  return 0;
}