#include<bits/stdc++.h>
using namespace std ;
#define g0 get<0>
#define g1 get<1>
#define g2 get<2>
#define g3 get<3>
const int N = 505 ;
const int W = 1e6+5 ;
int n , w , arr[N][N][2] ;
vector<tuple<int,int,int>> ans ;
int main(){
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0) ;
cin >> n >> w ;
for(int i=1 ; i<n ; i++){
for(int j=0 ; j<i ; j++) cin >> arr[i][j][1] , ans.push_back({i,j,w-arr[i][j][1]}) ;
}
for(int i=1 ; i<n ; i++){
for(int j=0 ; j<i ; j++) cin >> arr[i][j][0] , ans.push_back({i,j,arr[i][j][0]}) ;
}
for(int i=0 ; i<ans.size() ; i++){
if(g2(ans[i])<0){
cout << "NO\n" ;
return 0 ;
}
}
cout << ans.size() << '\n' ;
for(int i=0 ; i<ans.size() ; i++) cout << g0(ans[i]) << ' ' << g1(ans[i]) << ' ' << g2(ans[i]) << '\n' ;
return 0 ;
}