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;
long long readi() {
  long long input = 0;
  char c = ' ';
  while (c < '-') {
    c = getchar();
  }
  bool negative = false;
  if (c == '-') {
    negative = true;
    c = getchar();
  }
  while (c >= '0') {
    input = 10 * input + (c - '0');
    c = getchar();
  }
  if (negative) {
    input = -input;
  }
  return input;
}
void printi(long long output) {
  if (output == 0) {
    putchar('0');
    return;
  }
  if (output < 0) {
    putchar('-');
    output = -output;
  }
  int aout[20];
  int ilen = 0;
  while (output) {
    aout[ilen] = ((output % 10));
    output /= 10;
    ilen++;
  }
  for (int i = ilen - 1; i >= 0; i--) {
    putchar(aout[i] + '0');
  }
  return;
}
string reads() {
  string input = "";
  char c = ' ';
  while (c <= ' ') {
    c = getchar();
  }
  while (c > ' ') {
    input += c;
    c = getchar();
  }
  return input;
}
int sgn(long long x) {
  if (x < 0) {
    return -1;
  }
  if (x > 0) {
    return 1;
  }
  return 0;
}
long long randomize(long long mod) {
  return ((1 << 30) * rand() + (1 << 15) * rand() + rand()) % mod;
}
const long double PI = 4.0 * atan(1.0);
const long double EPS = 1e-30;
long long normalize(long long x, long long mod) {
  return (((x % mod) + mod) % mod);
}
int N, M;
map<int, int> mp[100010];
vector<int> edge[100010];
long long arr[100010];
long long ans[100010];
bool bipartite = true;
bool seen[100010], color[100010], in[100010];
int parent[100010];
long long pref[100010], suf[100010];
vector<int> cyc, nodes;
long long tot;
void dfs(int u, int par, bool col) {
  if (seen[u]) {
    if (col != color[u]) {
      bipartite = false;
      while (nodes.back() != u) {
        cyc.push_back(nodes.back());
        in[nodes.back()] = true;
        nodes.pop_back();
      }
      in[u] = true;
      cyc.push_back(u);
    }
    return;
  }
  nodes.push_back(u);
  seen[u] = true;
  color[u] = col;
  for (int v : edge[u]) {
    if (v == par) {
      continue;
    }
    dfs(v, u, !col);
    if (!bipartite) {
      return;
    }
  }
  nodes.pop_back();
  return;
}
void solve(int u, int par) {
  if (seen[u]) {
    return;
  }
  seen[u] = true;
  for (int v : edge[u]) {
    if (seen[v]) {
      continue;
    }
    if (v == par) {
      continue;
    }
    solve(v, u);
  }
  if (par == -1) {
    return;
  }
  ans[mp[u][par]] = arr[u];
  arr[par] -= arr[u];
  arr[u] = 0;
  return;
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  srand(time(0));
  if (fopen("cf901d.in", "r")) {
    freopen("cf901d.in", "r", stdin);
    freopen("cf901d.out", "w", stdout);
  }
  cin >> N >> M;
  for (int i = 0; i < N; i++) {
    cin >> arr[i];
  }
  for (int i = 0; i < M; i++) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    if (u > v) {
      swap(u, v);
    }
    mp[u][v] = i;
    mp[v][u] = i;
    edge[u].push_back(v);
    edge[v].push_back(u);
  }
  dfs(0, -1, 0);
  for (int i = 0; i < N; i++) {
    seen[i] = false;
  }
  if (bipartite) {
    int net = 0;
    for (int i = 0; i < N; i++) {
      if (color[i]) {
        net += arr[i];
      } else {
        net -= arr[i];
      }
    }
    if (net) {
      cout << "NO\n";
      return 0;
    }
    cout << "YES\n";
    solve(0, -1);
    for (int i = 0; i < M; i++) {
      cout << ans[i] << '\n';
    }
    return 0;
  }
  cout << "YES\n";
  for (int u : cyc) {
    for (int v : edge[u]) {
      if (in[v]) {
        continue;
      }
      solve(v, u);
    }
  }
  pref[0] = 0;
  pref[1] = 0;
  for (int i = 0; i < cyc.size(); i++) {
    int u = cyc[i];
    pref[i + 2] = pref[i] + arr[u];
    tot += arr[u];
  }
  suf[cyc.size() + 1] = 0;
  suf[cyc.size()] = 0;
  for (int i = cyc.size() - 1; i >= 0; i--) {
    int u = cyc[i];
    suf[i] = suf[i + 2] + arr[u];
  }
  tot /= 2;
  cyc.push_back(cyc[0]);
  for (int i = 0; i < cyc.size() - 1; i++) {
    int u = cyc[i], v = cyc[i + 1];
    long long res = tot;
    res -= pref[i + 1];
    res -= suf[i + 2];
    ans[mp[u][v]] += res;
  }
  for (int i = 0; i < M; i++) {
    cout << ans[i] << '\n';
  }
  return 0;
}