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<pair<int, int> > G[100005];
int Colour[100005], Stack[100005], P[100005], top;
pair<int, int> E[100005];
bool bipartite = 1;
long long Res[100005], C[100005];
vector<int> Cycle;
int Level[100005];
bool Use[100005];
map<pair<int, int>, int> Map;
void Read() {
  cin >> N >> M;
  for (int i = 1; i <= N; i++) cin >> C[i];
  for (int i = 1; i <= M; i++) {
    int x, y;
    cin >> x >> y;
    Map[make_pair(min(x, y), max(x, y))] = i;
    E[i] = make_pair(x, y);
    G[x].push_back(make_pair(y, i));
    G[y].push_back(make_pair(x, i));
  }
}
void DFS(int node, int colour) {
  Colour[node] = colour;
  for (int i = 0; i < G[node].size(); i++) {
    int neighb = G[node][i].first;
    if (Colour[neighb] == 0)
      DFS(neighb, 3 - colour);
    else {
      if (Colour[neighb] == Colour[node]) bipartite = 0;
    }
  }
}
void SolveCase1(int node, int father, int edge) {
  long long sum = 0;
  Use[node] = 1;
  for (int i = 0; i < G[node].size(); i++) {
    int neighb = G[node][i].first, e = G[node][i].second;
    if (neighb == father) continue;
    if (Use[neighb] == 1) continue;
    SolveCase1(neighb, node, e);
    sum += Res[e];
  }
  Res[edge] = C[node] - sum;
}
void findCycle(int node, int father) {
  Use[node] = 1;
  Level[node] = Level[father] + 1;
  Stack[++top] = node;
  P[node] = top;
  for (int i = 0; i < G[node].size(); i++) {
    int neighb = G[node][i].first, e = G[node][i].second;
    if (neighb == father) continue;
    if (Cycle.size() == 0 && Use[neighb] == 1 && Level[neighb] < Level[node] &&
        (Level[node] - Level[neighb] + 1) % 2 == 1) {
      for (int j = P[neighb]; j <= top; j++) Cycle.push_back(Stack[j]);
    }
    if (Use[neighb] == 0) findCycle(neighb, node);
  }
  --top;
}
void SolveCase2(int node, int father, int edge) {
  long long sum = 0;
  Use[node] = 1;
  for (int i = 0; i < G[node].size(); i++) {
    int neighb = G[node][i].first, e = G[node][i].second;
    if (neighb == father) continue;
    if (Use[neighb] == 1) continue;
    SolveCase2(neighb, node, e);
    sum += Res[e];
  }
  Res[edge] = C[node] - sum;
}
void Solve() {
  for (int i = 1; i <= N; i++) Use[i] = 0;
  SolveCase2(Cycle[0], 0, 0);
  int edge =
      Map[make_pair(min(Cycle[0], Cycle.back()), max(Cycle[0], Cycle.back()))];
  Res[edge] += Res[0] / 2;
  int sign = 1;
  for (int i = 0; i < Cycle.size() - 1; i++) {
    int e = Map[make_pair(min(Cycle[i], Cycle[i + 1]),
                          max(Cycle[i], Cycle[i + 1]))];
    Res[e] += sign * Res[0] / 2;
    sign *= -1;
  }
}
int main() {
  Read();
  DFS(1, 1);
  if (bipartite == 1) {
    SolveCase1(1, 0, 0);
    if (Res[0] != 0) {
      cout << "NO\n";
      return 0;
    }
  } else {
    findCycle(1, 0);
    Solve();
  }
  cout << "YES\n";
  for (int i = 1; i <= M; i++) cout << Res[i] << "\n";
  return 0;
}