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 maxn = 100005;
const int LG = 20;
int n, m;
long long a[maxn];
int visited[maxn];
long long weight[maxn];
vector<pair<int, int>> g[maxn];
vector<int> odd, even;
long long sumodd, sumeven;
int depth[maxn];
int parEdge[maxn];
int jump[maxn][LG];
vector<int> oddcycle;
pair<int, int> edges[maxn];
void dfs_prepare(int v, int color) {
  if (!v) {
    fill(visited, visited + maxn, -1);
  }
  visited[v] = color;
  if (color) {
    sumodd += a[v];
    odd.emplace_back(v);
  } else {
    sumeven += a[v];
    even.emplace_back(v);
  }
  for (auto &e : g[v]) {
    if (visited[e.first] != -1) {
      if (visited[e.first] != visited[v] || oddcycle.size() > 0) continue;
      oddcycle.emplace_back(color);
      oddcycle.emplace_back(e.second);
      for (int x = v; x != e.first; x = jump[x][0]) {
        oddcycle.emplace_back(parEdge[x]);
      }
      continue;
    }
    int s = e.first;
    parEdge[s] = e.second;
    jump[s][0] = v;
    depth[s] = depth[v] + 1;
    for (int j = 1; j < LG; ++j) jump[s][j] = jump[jump[s][j - 1]][j - 1];
    dfs_prepare(s, 1 - color);
  }
}
int LCA(int u, int v) {
  if (depth[u] < depth[v]) swap(u, v);
  for (int j = LG - 1; j >= 0; --j) {
    if (depth[jump[u][j]] >= depth[v]) u = jump[u][j];
  }
  if (u == v) return v;
  for (int j = LG - 1; j >= 0; --j) {
    if (jump[u][j] != jump[v][j]) {
      u = jump[u][j];
      v = jump[v][j];
    }
  }
  return jump[v][0];
}
long long fs[maxn];
int same(int x, int y) { return x / abs(x) == y / abs(y); }
void upd(int x, int w, int sign = 1) {
  if (a[x] < 0) {
    a[x] += w;
    fs[x] += sign * w;
  } else {
    a[x] -= w;
    fs[x] -= sign * w;
  }
}
void normalize(vector<int> ids) {
  vector<int> stac;
  for (int x : ids) {
    if (a[x] == 0) continue;
    if (stac.empty() || same(a[x], a[stac.back()])) {
      stac.push_back(x);
    } else {
      while (abs(a[x]) > 0) {
        if (stac.empty()) break;
        int y = stac.back();
        int w = min(abs(a[x]), abs(a[y]));
        upd(x, w);
        upd(y, w);
        if (a[y] == 0) stac.pop_back();
      }
      if (abs(a[x]) > 0) stac.push_back(x);
    }
  }
}
void dfs_solve(int v) {
  if (!v) {
    fill(visited, visited + maxn, -1);
  }
  visited[v] = 1;
  for (auto &e : g[v]) {
    int s = e.first, w = e.second;
    if (visited[s] != -1) continue;
    dfs_solve(s);
    weight[w] += fs[s];
    fs[v] -= fs[s];
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> m;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  for (int i = 0; i < m; ++i) {
    int u, v;
    cin >> u >> v;
    g[--u].emplace_back(--v, i);
    g[v].emplace_back(u, i);
    weight[i]++;
    a[v]++;
    a[u]++;
    edges[i] = make_pair(u, v);
  }
  dfs_prepare(0, 0);
  if (sumodd != sumeven) {
    if (oddcycle.empty()) {
      cout << "NO" << endl;
      return 0;
    }
    long long need = sumodd - sumeven;
    need /= 2;
    int sign = 1;
    if (oddcycle.front() == 0) sign *= -1;
    for (int i = 1; i < oddcycle.size(); ++i) {
      auto [u, v] = edges[oddcycle[i]];
      a[v] -= sign * need;
      a[u] -= sign * need;
      weight[oddcycle[i]] -= sign * need;
      sign *= -1;
    }
  }
  normalize(even);
  normalize(odd);
  for (int i = 0, j = 0;;) {
    if (i == even.size() || j == odd.size()) break;
    if (a[even[i]] == 0) {
      ++i;
      continue;
    }
    if (a[odd[j]] == 0) {
      ++j;
      continue;
    }
    int x = even[i], y = odd[j];
    int w = min(abs(a[x]), abs(a[y]));
    upd(x, w);
    upd(y, w);
  }
  dfs_solve(0);
  cout << "YES\n";
  for (int i = 0; i < m; ++i) cout << -weight[i] << "\n";
  return 0;
}