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;
int n, m, dep[100010], st[100010][17];
long long c[100010], tc[100010], ans[100010];
vector<pair<int, int> > v[100010];
bool vis[100010];
void dfs1(int np, int fath) {
  vis[np] = 1;
  dep[np] = dep[fath] + 1;
  st[np][0] = fath;
  for (int i = 1; i < 17; i++) st[np][i] = st[st[np][i - 1]][i - 1];
  for (auto &x : v[np]) {
    if (x.first == fath || vis[x.first]) continue;
    dfs1(x.first, np);
    ans[x.second] = tc[x.first];
    tc[np] -= tc[x.first];
    tc[x.first] = 0;
  }
}
inline int lca(int x, int y) {
  if (dep[x] < dep[y]) swap(x, y);
  for (int i = 16; i >= 0; i--)
    if (dep[st[x][i]] >= dep[y]) x = st[x][i];
  if (x == y) return x;
  for (int i = 16; i >= 0; i--)
    if (st[x][i] != st[y][i]) x = st[x][i], y = st[y][i];
  return st[x][0];
}
int s[100010], e[100010];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%lld", &c[i]), tc[i] = c[i];
  for (int i = 1, ti, tj; i <= m; i++) {
    scanf("%d%d", &ti, &tj);
    s[i] = ti;
    e[i] = tj;
    v[ti].push_back(make_pair(tj, i));
    v[tj].push_back(make_pair(ti, i));
  }
  dfs1(1, 0);
  if (tc[1] == 0) {
    puts("YES");
    for (int i = 1; i <= m; i++) printf("%lld\n", ans[i]);
    return 0;
  }
  bool flag = 1;
  int pos = -1, pv = 0;
  for (int i = 1; i <= m; i++) {
    if ((dep[s[i]] + dep[e[i]] - 2 * dep[lca(s[i], e[i])]) % 2 == 0) {
      flag = 0;
      int vl = tc[1] / 2;
      ans[i] = vl;
      pos = i;
      pv = vl;
      c[s[i]] -= vl;
      c[e[i]] -= vl;
      break;
    }
  }
  if (flag) {
    puts("NO");
    return 0;
  }
  puts("YES");
  memset(vis, 0, sizeof(vis));
  copy(c + 1, c + n + 1, tc + 1);
  dfs1(1, 0);
  if (tc[1]) {
    c[s[pos]] += pv * 2;
    c[e[pos]] += pv * 2;
    ans[pos] = -pv;
    memset(vis, 0, sizeof(vis));
    copy(c + 1, c + n + 1, tc + 1);
    dfs1(1, 0);
  }
  for (int i = 1; i <= m; i++) printf("%lld\n", ans[i]);
  return 0;
}