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;
vector<vector<int> > adj;
vector<int> U, V;
vector<long long> C, W;
vector<int> tin, tout, dep, par, cycle, edge, del, vis;
int timer;
bool dfs(int u, int fe) {
  tin[u] = timer++;
  for (int i = 0; i < adj[u].size(); i++) {
    int e = adj[u][i];
    int v = U[e] + V[e] - u;
    if (e == fe) continue;
    if (tin[v] != -1) {
      if (tout[v] == -1 && (dep[u] - dep[v]) % 2 == 0) {
        int t = u;
        while (1) {
          cycle.push_back(t);
          if (t == v) break;
          int pe = par[t];
          t = U[pe] + V[pe] - t;
          edge.push_back(pe);
        }
        edge.push_back(e);
        return true;
      }
      continue;
    }
    par[v] = e;
    dep[v] = dep[u] + 1;
    if (dfs(v, e)) return true;
  }
  tout[u] = timer;
  return false;
}
void dfs2(int u, int fe) {
  vis[u] = 1;
  for (int i = 0; i < adj[u].size(); i++) {
    int e = adj[u][i];
    int v = U[e] + V[e] - u;
    if (vis[v]) continue;
    if (del[v]) continue;
    dfs2(v, e);
    W[e] = C[v];
    C[u] -= C[v];
  }
}
vector<pair<long long, long long> > sol;
void solve() {
  sol.resize(M);
  sol[edge[0]] = pair<long long, long long>(1, 0);
  for (int i = 1; i < cycle.size(); i++) {
    int u = cycle[i];
    int v = cycle[(i + 1) % cycle.size()];
    int e = edge[i];
    int pe = edge[i - 1];
    sol[e] = pair<long long, long long>(-sol[pe].first, C[u] - sol[pe].second);
  }
  W[edge[0]] = (C[cycle[0]] - sol[edge[0]].second - sol[edge.back()].second) /
               (sol[edge[0]].first + sol[edge.back()].first);
  for (int i = 0; i < cycle.size(); i++) {
    W[edge[i]] = W[edge[0]] * sol[edge[i]].first + sol[edge[i]].second;
  }
}
int main() {
  scanf("%d %d", &N, &M);
  C.resize(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &C[i]);
  }
  adj.resize(N);
  for (int i = 0; i < M; i++) {
    int u, v;
    scanf("%d %d", &u, &v);
    u--;
    v--;
    adj[u].push_back(U.size());
    adj[v].push_back(U.size());
    U.push_back(u);
    V.push_back(v);
  }
  tin = tout = par = vector<int>(N, -1);
  dep = vector<int>(N, 0);
  timer = 0;
  W = vector<long long>(M, 0);
  if (!dfs(0, -1)) {
    vis = vector<int>(N, 0);
    del = vector<int>(N, 0);
    dfs2(0, -1);
    if (C[0]) {
      printf("NO");
    } else {
      printf("YES\n");
      for (int i = 0; i < M; i++) {
        printf("%lld\n", W[i]);
      }
    }
    return 0;
  }
  del = vector<int>(N, 0);
  vis = vector<int>(N, 0);
  for (int i = 0; i < cycle.size(); i++) del[cycle[i]] = 1;
  for (int i = 0; i < cycle.size(); i++) {
    dfs2(cycle[i], -1);
  }
  solve();
  printf("YES\n");
  for (int i = 0; i < M; i++) {
    printf("%lld\n", W[i]);
  }
}