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;
vector<int> edges[110000];
long long c[110000];
pair<int, int> r[110000];
map<pair<int, int>, long long> wgt;
int color[110000];
vector<int> oddcyc;
int done = 0;
int dfs(int a, int col) {
  if (done) return -1;
  if (color[a] == 1 - col) {
    return a;
  }
  if (color[a] == col) return -1;
  color[a] = col;
  for (int j = 0; j < edges[a].size(); j++) {
    int k = dfs(edges[a][j], 1 - col);
    if (done) return -1;
    if (k != -1) {
      oddcyc.push_back(a);
      if (k == a) done = 1;
      return k;
    }
  }
  return -1;
}
int vis[110000];
int cyc[110000];
void setwgt(int a, int b, long long w) {
  wgt[make_pair(a, b)] = w;
  wgt[make_pair(b, a)] = w;
}
void dfs2(int par, int a) {
  if (vis[a]) return;
  vis[a] = 1;
  for (int j = 0; j < edges[a].size(); j++) {
    dfs2(a, edges[a][j]);
  }
  if (par != -1) {
    setwgt(a, par, c[a]);
    c[par] -= c[a];
    c[a] -= c[a];
  }
}
void dfs3(int par, int a) {
  if (vis[a]) return;
  if (par != -1 && cyc[a]) return;
  vis[a] = 1;
  for (int j = 0; j < edges[a].size(); j++) {
    dfs3(a, edges[a][j]);
  }
  if (par != -1) {
    setwgt(a, par, c[a]);
    c[par] -= c[a];
    c[a] -= c[a];
  }
}
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> c[i];
  }
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    r[i].first = a;
    r[i].second = b;
    edges[a].push_back(b);
    edges[b].push_back(a);
  }
  for (int i = 0; i < n; i++) {
    color[i] = -1;
    vis[i] = cyc[i] = 0;
  }
  dfs(0, 0);
  if (oddcyc.size() == 0) {
    long long sums[2];
    sums[0] = sums[1] = 0;
    for (int j = 0; j < n; j++) {
      sums[color[j]] += c[j];
    }
    if (sums[0] != sums[1]) {
      cout << "NO" << endl;
      return 0;
    }
    dfs2(-1, 0);
    cout << "YES" << endl;
    for (int j = 0; j < m; j++) {
      cout << wgt[r[j]] << endl;
    }
    return 0;
  }
  for (int i = 0; i < oddcyc.size(); i++) {
    cyc[oddcyc[i]] = 1;
  }
  for (int i = 0; i < oddcyc.size(); i++) {
    dfs3(-1, oddcyc[i]);
  }
  long long lastedge = 0;
  for (int i = 0; i < oddcyc.size(); i++) {
    if (i % 2 == 0) {
      lastedge += c[oddcyc[i]];
    } else {
      lastedge -= c[oddcyc[i]];
    }
  }
  lastedge /= 2;
  setwgt(oddcyc[0], oddcyc[oddcyc.size() - 1], lastedge);
  for (int i = 0; i < oddcyc.size() - 1; i++) {
    lastedge = c[oddcyc[i]] - lastedge;
    setwgt(oddcyc[i], oddcyc[i + 1], lastedge);
  }
  cout << "YES" << endl;
  for (int j = 0; j < m; j++) {
    cout << wgt[r[j]] << endl;
  }
  return 0;
}