#include <iostream>
#include <stdio.h>

using namespace std;

int main(){
	int n,all=0;
	int data[256];
	int tdata[256] = { 0 };
	
	cin >> n;

	for (int i = 0; i < n; i++,all=0){
		for (int j = 0; j < n; j++){
			cin >> data[j];
			printf(" %d",data[j]);
			all += data[j];
			tdata[j] += data[j];
		}
		printf(" %d\n", all);
	}

	all = 0;
	for (int i = 0; i < n; i++){
		printf(" %d", tdata[i]);
		all += tdata[i];
	}
	printf(" %d\n", all);

	return 0;
}