import java.io.IOException;
import java.util.Scanner;
class Main{
	public static void main(String[] args)throws NumberFormatException, IOException{
		//System.out.print(" ");
		Scanner scan = new Scanner(System.in);
		int r =scan.nextInt();
		int c =scan.nextInt();
		int num[][] = new int[100][101]; //num[???][?¨?]
		int sumsum[] = new int [101];
		int sum = 0;
		
		for(int i =0; i<r; i++){
			sum = 0;
			for(int ii=0;ii<c;ii++){
				num[ii][i] = scan.nextInt();
				sum += num[ii][i];
				System.out.print(num[ii][i]+" ");
			}
			System.out.println(sum);
		}
		
		for(int i =0; i<r; i++){
			for(int ii=0;ii<c;ii++){
				sumsum[ii] += num[ii][i];
			}
		}
		
		sum = 0;
		for(int i=0; i<c; i++){
			sum += sumsum[i];
			System.out.print(sumsum[i]+" ");
		}
		System.out.println(sum);
	}
} import java.io.IOException; IOException java.io import java.util.Scanner; Scanner java.util class Main{
	public static void main(String[] args)throws NumberFormatException, IOException{
		//System.out.print(" ");
		Scanner scan = new Scanner(System.in);
		int r =scan.nextInt();
		int c =scan.nextInt();
		int num[][] = new int[100][101]; //num[???][?¨?]
		int sumsum[] = new int [101];
		int sum = 0;
		
		for(int i =0; i<r; i++){
			sum = 0;
			for(int ii=0;ii<c;ii++){
				num[ii][i] = scan.nextInt();
				sum += num[ii][i];
				System.out.print(num[ii][i]+" ");
			}
			System.out.println(sum);
		}
		
		for(int i =0; i<r; i++){
			for(int ii=0;ii<c;ii++){
				sumsum[ii] += num[ii][i];
			}
		}
		
		sum = 0;
		for(int i=0; i<c; i++){
			sum += sumsum[i];
			System.out.print(sumsum[i]+" ");
		}
		System.out.println(sum);
	}
} Main public static void main(String[] args)throws NumberFormatException, IOException{
		//System.out.print(" ");
		Scanner scan = new Scanner(System.in);
		int r =scan.nextInt();
		int c =scan.nextInt();
		int num[][] = new int[100][101]; //num[???][?¨?]
		int sumsum[] = new int [101];
		int sum = 0;
		
		for(int i =0; i<r; i++){
			sum = 0;
			for(int ii=0;ii<c;ii++){
				num[ii][i] = scan.nextInt();
				sum += num[ii][i];
				System.out.print(num[ii][i]+" ");
			}
			System.out.println(sum);
		}
		
		for(int i =0; i<r; i++){
			for(int ii=0;ii<c;ii++){
				sumsum[ii] += num[ii][i];
			}
		}
		
		sum = 0;
		for(int i=0; i<c; i++){
			sum += sumsum[i];
			System.out.print(sumsum[i]+" ");
		}
		System.out.println(sum);
	} main {
		//System.out.print(" ");
		Scanner scan = new Scanner(System.in);
		int r =scan.nextInt();
		int c =scan.nextInt();
		int num[][] = new int[100][101]; //num[???][?¨?]
		int sumsum[] = new int [101];
		int sum = 0;
		
		for(int i =0; i<r; i++){
			sum = 0;
			for(int ii=0;ii<c;ii++){
				num[ii][i] = scan.nextInt();
				sum += num[ii][i];
				System.out.print(num[ii][i]+" ");
			}
			System.out.println(sum);
		}
		
		for(int i =0; i<r; i++){
			for(int ii=0;ii<c;ii++){
				sumsum[ii] += num[ii][i];
			}
		}
		
		sum = 0;
		for(int i=0; i<c; i++){
			sum += sumsum[i];
			System.out.print(sumsum[i]+" ");
		}
		System.out.println(sum);
	} Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int r =scan.nextInt(); r scan.nextInt() scan.nextInt scan int c =scan.nextInt(); c scan.nextInt() scan.nextInt scan int num[][] = new int[100][101]; num new int[100][101] 100 101 int sumsum[] = new int [101]; sumsum new int [101] 101 int sum = 0; sum 0 for(int i =0; i<r; i++){
			sum = 0;
			for(int ii=0;ii<c;ii++){
				num[ii][i] = scan.nextInt();
				sum += num[ii][i];
				System.out.print(num[ii][i]+" ");
			}
			System.out.println(sum);
		} int i =0; int i =0; i 0 i<r i r i++ i++ i {
			sum = 0;
			for(int ii=0;ii<c;ii++){
				num[ii][i] = scan.nextInt();
				sum += num[ii][i];
				System.out.print(num[ii][i]+" ");
			}
			System.out.println(sum);
		} {
			sum = 0;
			for(int ii=0;ii<c;ii++){
				num[ii][i] = scan.nextInt();
				sum += num[ii][i];
				System.out.print(num[ii][i]+" ");
			}
			System.out.println(sum);
		} sum = 0 sum 0 for(int ii=0;ii<c;ii++){
				num[ii][i] = scan.nextInt();
				sum += num[ii][i];
				System.out.print(num[ii][i]+" ");
			} int ii=0; int ii=0; ii 0 ii<c ii c ii++ ii++ ii {
				num[ii][i] = scan.nextInt();
				sum += num[ii][i];
				System.out.print(num[ii][i]+" ");
			} {
				num[ii][i] = scan.nextInt();
				sum += num[ii][i];
				System.out.print(num[ii][i]+" ");
			} num[ii][i] = scan.nextInt() num[ii][i] num[ii] num ii i scan.nextInt() scan.nextInt scan sum += num[ii][i] sum num[ii][i] num[ii] num ii i System.out.print(num[ii][i]+" ") System.out.print System.out System System.out num[ii][i]+" " num[ii][i] num[ii] num ii i " " System.out.println(sum) System.out.println System.out System System.out sum for(int i =0; i<r; i++){
			for(int ii=0;ii<c;ii++){
				sumsum[ii] += num[ii][i];
			}
		} int i =0; int i =0; i 0 i<r i r i++ i++ i {
			for(int ii=0;ii<c;ii++){
				sumsum[ii] += num[ii][i];
			}
		} {
			for(int ii=0;ii<c;ii++){
				sumsum[ii] += num[ii][i];
			}
		} for(int ii=0;ii<c;ii++){
				sumsum[ii] += num[ii][i];
			} int ii=0; int ii=0; ii 0 ii<c ii c ii++ ii++ ii {
				sumsum[ii] += num[ii][i];
			} {
				sumsum[ii] += num[ii][i];
			} sumsum[ii] += num[ii][i] sumsum[ii] sumsum ii num[ii][i] num[ii] num ii i sum = 0 sum 0 for(int i=0; i<c; i++){
			sum += sumsum[i];
			System.out.print(sumsum[i]+" ");
		} int i=0; int i=0; i 0 i<c i c i++ i++ i {
			sum += sumsum[i];
			System.out.print(sumsum[i]+" ");
		} {
			sum += sumsum[i];
			System.out.print(sumsum[i]+" ");
		} sum += sumsum[i] sum sumsum[i] sumsum i System.out.print(sumsum[i]+" ") System.out.print System.out System System.out sumsum[i]+" " sumsum[i] sumsum i " " System.out.println(sum) System.out.println System.out System System.out sum String[] args args
import java.io.IOException;
import java.util.Scanner;
class Main{
	public static void main(String[] args)throws NumberFormatException, IOException{
		//System.out.print(" ");
		Scanner scan = new Scanner(System.in);
		int r =scan.nextInt();
		int c =scan.nextInt();
		int num[][] = new int[100][101]; //num[???][?¨?]
		int sumsum[] = new int [101];
		int sum = 0;
		
		for(int i =0; i<r; i++){
			sum = 0;
			for(int ii=0;ii<c;ii++){
				num[ii][i] = scan.nextInt();
				sum += num[ii][i];
				System.out.print(num[ii][i]+" ");
			}
			System.out.println(sum);
		}
		
		for(int i =0; i<r; i++){
			for(int ii=0;ii<c;ii++){
				sumsum[ii] += num[ii][i];
			}
		}
		
		sum = 0;
		for(int i=0; i<c; i++){
			sum += sumsum[i];
			System.out.print(sumsum[i]+" ");
		}
		System.out.println(sum);
	}
}