// ashish_arora
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF INT_MAX
#define ll long long
#define ld long double
#define pb push_back
#define all(c) c.begin() , c.end()
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
vector <int> lol;
int main(){
int n;
cin >> n;
int a[n];
int b[n];
for (int i = 0 ; i < n ; i ++){
cin >> a[i];
}
for (int i = 0 ; i < n ; i ++){
cin >> b[i];
}
int dp[1001][n+1][n+1][2];
for (int z = 0 ; z <= 1000 ; z ++){
for (int i = 0 ; i<= n ; i++){
for (int j = 0 ; j <=n ; j ++){
dp[z][i][j][1] = 0;
dp[z][i][j][0] = 0;
if (i == 0 || j == 0){
dp[z][i][j][1] = 0;
dp[z][i][j][0] = 0;
// continue;
}
else{
dp[z][i][j][1] = max(dp[z][i-1][j][1] , dp[z][i][j-1][1]);
dp[z][i][j][0] = max(dp[z][i-1][j][0] , dp[z][i][j-1][0]);
if (a[i-1] + z == b[j-1]){
dp[z][i][j][1] = max(dp[z][i][j][1] , 1 + dp[z][i-1][j-1][1]);
}
if (a[i-1] == b[j-1] + z){
dp[z][i][j][0] = max(dp[z][i][j][0] , 1 + dp[z][i-1][j-1][0]);
}
}
}
}
}
int mx = -INF;
int diff = 0;
bool cond = 0;
for (int i = 0 ; i<= 1001 ; i ++){
if (mx < dp[i][n][n][0]){
mx = dp[i][n][n][0];
diff = i;
cond = 0;
}
if (mx < dp[i][n][n][1]){
mx = dp[i][n][n][1];
diff = i;
cond = 1;
}
}
for (int i = 0 ; i <=n ; i ++){
for (int j = 0 ; j<=n; j ++){
cout << dp[diff][i][j][cond] << " ";
}
cout << endl;
}
int itr = n;
int it = n;
while(itr > 0 && it > 0){
if (dp[diff][itr][it][cond] == dp[diff][itr-1][it][cond]){
itr --;
}else if (dp[diff][itr][it][cond] == dp[diff][itr][it-1][cond]){
it --;
}else if (dp[diff][itr][it][cond] > dp[diff][itr-1][it-1][cond]){
lol.pb(a[itr-1]);
itr -- ;
it --;
}
}
// reverse(lol.begin() , lol.end());
// cout << lol.size() << endl;
// if (cond){
// for (int i = 0 ; i < lol.size() ; i++){
// cout << lol[i] - diff << " ";
// }
// cout << endl;
// for (int i = 0 ; i < lol.size() ; i++){
// cout << lol[i] << " ";
// }
// cout << endl;
// }
// else{
// for (auto u: lol){
// cout << u << " " ;
// }
// cout << endl;
// for (auto u : lol){
// cout << u - diff << " ";
// }
// cout << endl;
// }
return 0;
}