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 = (long long)1e6 + 3;
const long long infint = (long long)1e9 + 3;
const long long MOD = (long long)1e9 + 7;
const long long inf = (long long)1e18 + 3;
long long n, m, c[MAXN], par[MAXN], visited[MAXN], h[MAXN], edge_1[MAXN],
    edge_2[MAXN];
map<pair<long long, long long>, long long> M;
vector<long long> G[MAXN];
void bfs(long long u) {
  queue<long long> q;
  q.push(u);
  visited[u] = 1;
  while (!q.empty()) {
    long long st = q.front();
    q.pop();
    for (auto v : G[st])
      if (!visited[v]) par[v] = st, visited[v] = 1, h[v] = h[st] + 1, q.push(v);
  }
}
long long dfs(long long u) {
  long long ans = 0;
  for (auto v : G[u])
    if (!visited[v]) visited[v] = 1, M[{u, v}] = dfs(v), ans += M[{u, v}];
  return c[u] - ans;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (long long i = 1; i <= n; i++) cin >> c[i];
  for (long long i = 0; i < m; i++) {
    long long u, v;
    cin >> u >> v;
    edge_1[i] = u, edge_2[i] = v;
    G[u].push_back(v);
    G[v].push_back(u);
  }
  bfs(1);
  long long a = -1, b = -1;
  for (long long i = 1; i <= n; i++)
    for (auto u : G[i])
      if (h[i] == h[u]) a = i, b = u;
  if (a != -1) {
    vector<long long> cyc;
    long long lca = -1, tmp_a = a, tmp_b = b;
    while (a != b) {
      if (h[a] > h[b])
        a = par[a];
      else
        b = par[b];
    }
    lca = a;
    a = tmp_a, b = tmp_b;
    while (a != lca) {
      cyc.push_back(a);
      a = par[a];
    }
    vector<long long> sec;
    while (b != lca) {
      sec.push_back(b);
      b = par[b];
    }
    reverse(sec.begin(), sec.end());
    cyc.push_back(lca);
    for (auto u : sec) cyc.push_back(u);
    memset(visited, 0, sizeof visited);
    for (auto u : cyc) visited[u] = 1;
    for (auto u : cyc) c[u] = dfs(u);
    long long ans = 0;
    for (long long i = 0; i < (long long)cyc.size(); i++)
      if (i <= 1)
        ans += c[cyc[i]];
      else if (i % 2 == 0)
        ans -= c[cyc[i]];
      else
        ans += c[cyc[i]];
    M[{cyc[0], cyc[1]}] = ans / 2;
    for (long long i = 1; i < (long long)cyc.size(); i++)
      ans = ans * -1 + 2 * c[cyc[i]],
      M[{cyc[i], cyc[(i + 1) % (long long)cyc.size()]}] = ans / 2;
    cout << "YES\n";
    for (long long i = 0; i < m; i++)
      cout << M[{edge_1[i], edge_2[i]}] + M[{edge_2[i], edge_1[i]}] << "\n";
    return 0;
  }
  memset(visited, 0, sizeof visited);
  visited[1] = 1;
  long long x = dfs(1);
  if (x) return cout << "NO", 0;
  cout << "YES\n";
  for (long long i = 0; i < m; i++)
    cout << M[{edge_1[i], edge_2[i]}] + M[{edge_2[i], edge_1[i]}] << "\n";
}