Problem: A system of n vessels with water is given. Several pairs of vessels are connected by tubes with transfusion mechanisms. One may transfer an integer amount of liters of water between two vessels connected by such tube (tube works in both directions). There might be multiple tubes between two vessels. Total number of tubes equals e. Volume of each vessel equals v liters. Of course, the amount of the water in any vessel cannot exceed v liters in the process of transfusions.

Given the initial amounts ai of water in the vessels and the desired amounts bi find a sequence of transfusions that deals with the task. Total number of transfusions must not exceed 2·n2.

Input

First line of the input contains integers n, v, e (1 ≤ n ≤ 300, 1 ≤ v ≤ 109, 0 ≤ e ≤ 50000).

Next two lines contain n integers each: initial ai and the desired amounts bi of water in corresponding vessels (0 ≤ ai, bi ≤ v).

Next e lines describe one tube each in the format x y (1 ≤ x, y ≤ n, x ≠ y) for a tube between vessels number x and y. There might be multiple tubes between two vessels. You may assume that vessels are numbered from 1 to n in some way.

Output

Print "NO" (without quotes), if such sequence of transfusions does not exist.

Otherwise print any suitable sequence in the following format. On the first line print the total number of transfusions k (k should not exceed 2·n2). In the following k lines print transfusions in the format x y d (transfusion of d liters from the vessel number x to the vessel number y, x and y must be distinct). For all transfusions d must be a non-negative integer.

Examples

Input

2 10 1
1 9
5 5
1 2


Output

1
2 1 4


Input

2 10 0
5 2
4 2


Output

NO


Input

2 10 0
4 2
4 2


Output

0

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
const int M = 300 + 5;
long long int mod = 1000000000 + 7;
int adj[M][M];
int a[M];
int b[M];
vector<pair<pair<int, int>, int> > ans;
int vis[M];
vector<int> s;
int main() {
  time_t t_start, t_end;
  t_start = clock();
  int n, v, e;
  cin >> n >> v >> e;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (int i = 1; i <= n; i++) {
    cin >> b[i];
  }
  for (int i = 0; i < e; i++) {
    int x, y;
    cin >> x >> y;
    adj[x][y] = 1;
    adj[y][x] = 1;
  }
  int k = 0;
  bool ok = true;
  for (int i = 1; i <= n; i++) {
    if (!vis[i]) {
      queue<int> q;
      s.clear();
      q.push(i);
      vis[i] = 1;
      while (!q.empty()) {
        int u = q.front();
        s.push_back(u);
        q.pop();
        for (int j = 1; j <= n; j++) {
          if (adj[u][j] == 1 && !vis[j]) {
            int nxt = j;
            q.push(nxt);
            vis[nxt] = 1;
          }
        }
      }
      stack<pair<int, int> > pos;
      stack<pair<int, int> > neg;
      int sz = s.size();
      long long int sd = 0;
      for (int j = 0; j < sz; j++) {
        int d = a[s[j]] - b[s[j]];
        sd = sd + d;
        if (d > 0) {
          pos.push(make_pair(s[j], d));
        }
        if (d < 0) {
          neg.push(make_pair(s[j], -d));
        }
      }
      if (sd == 0) {
        while (!pos.empty() && !neg.empty()) {
          int pidx = pos.top().first;
          int pval = pos.top().second;
          int nidx = neg.top().first;
          int nval = neg.top().second;
          int dd = min(pval, nval);
          pos.pop();
          neg.pop();
          queue<int> qq;
          int father[M];
          vector<pair<int, int> > path;
          int visited[M];
          for (int j = 0; j < sz; j++) {
            visited[s[j]] = 0;
          }
          for (int j = 0; j < M; j++) {
            father[j] = 0;
          }
          qq.push(pidx);
          visited[pidx] = 1;
          while (!qq.empty()) {
            int u = qq.front();
            qq.pop();
            if (u == nidx) {
              break;
            }
            for (int j = 1; j <= n; j++) {
              if (adj[u][j] == 1 && !visited[j]) {
                qq.push(j);
                visited[j] = 1;
                father[j] = u;
              }
            }
          }
          int tmp = nidx;
          while (tmp != 0) {
            path.push_back(make_pair(tmp, a[tmp]));
            tmp = father[tmp];
          }
          stack<pair<pair<int, int>, int> > res;
          int sz = path.size();
          for (int j = 0; j + 1 < sz; j++) {
            int cur = path[j].first;
            int curval = path[j].second;
            int far = path[j + 1].first;
            int farval = path[j + 1].second;
            if (farval >= dd) {
              ans.push_back(make_pair(make_pair(far, cur), dd));
            } else {
              ans.push_back(make_pair(make_pair(far, cur), farval));
              res.push(make_pair(make_pair(far, cur), dd - farval));
            }
          }
          while (!res.empty()) {
            ans.push_back(res.top());
            res.pop();
          }
          if (pval > dd) {
            pos.push(make_pair(pidx, pval - dd));
          }
          if (nval > dd) {
            neg.push(make_pair(nidx, nval - dd));
          }
          a[pidx] = a[pidx] - dd;
          a[nidx] = a[nidx] + dd;
        }
      } else {
        ok = false;
        break;
      }
    }
  }
  if (!ok) {
    cout << "NO" << endl;
  } else {
    int sz = ans.size();
    cout << sz << endl;
    for (int i = 0; i < sz; i++) {
      cout << ans[i].first.first << " " << ans[i].first.second << " "
           << ans[i].second << endl;
    }
  }
  t_end = clock();
  return 0;
}