
import java.util.*;

class Main {
	public static void main(String args[]){
		
		Scanner sc = new Scanner(System.in);
		
		//表の行数rと列数cを読み取る
		String s1 = sc.next();
		int r = Integer.parseInt(s1);
		String s2 = sc.next();
		int c = Integer.parseInt(s2);
		//表を値を配列に受け取る
		int a[][] = new int[r][c];
		
		//cとrが条件範囲内か確認
		if(1 <= r && r <= 100){
			if(1 <= c && c <= 100){
				
				//配列に格納していく
				for(int i = 0; i < r; i++ ){
					for(int j = 0; j < c; j++){
						String s3 = sc.next();
						int k = Integer.parseInt(s3);
						a[i][j] = k;
					}
				}
				
				int total = 0;
				//入力された表の値と行ごとの合計値の表示
				for(int i = 0; i < r; i++ ){
					int sum = 0;
					for(int j = 0; j < c; j++){
						System.out.print(a[i][j] + " ");
						sum += a[i][j];
					}
					total += sum;
					System.out.println( sum );
				}
				
				//入力された表の値の列ごとの合計値の表示
				for(int j = 0; j < c; j++ ){
					int sum = 0;
					for(int i = 0; i < r; i++){
						sum += a[i][j];
					}
					System.out.print( sum + " ");
				}
				System.out.println( total );
			}
		}
	}

} import java.util.*; util.* java class Main {
	public static void main(String args[]){
		
		Scanner sc = new Scanner(System.in);
		
		//表の行数rと列数cを読み取る
		String s1 = sc.next();
		int r = Integer.parseInt(s1);
		String s2 = sc.next();
		int c = Integer.parseInt(s2);
		//表を値を配列に受け取る
		int a[][] = new int[r][c];
		
		//cとrが条件範囲内か確認
		if(1 <= r && r <= 100){
			if(1 <= c && c <= 100){
				
				//配列に格納していく
				for(int i = 0; i < r; i++ ){
					for(int j = 0; j < c; j++){
						String s3 = sc.next();
						int k = Integer.parseInt(s3);
						a[i][j] = k;
					}
				}
				
				int total = 0;
				//入力された表の値と行ごとの合計値の表示
				for(int i = 0; i < r; i++ ){
					int sum = 0;
					for(int j = 0; j < c; j++){
						System.out.print(a[i][j] + " ");
						sum += a[i][j];
					}
					total += sum;
					System.out.println( sum );
				}
				
				//入力された表の値の列ごとの合計値の表示
				for(int j = 0; j < c; j++ ){
					int sum = 0;
					for(int i = 0; i < r; i++){
						sum += a[i][j];
					}
					System.out.print( sum + " ");
				}
				System.out.println( total );
			}
		}
	}

} Main public static void main(String args[]){
		
		Scanner sc = new Scanner(System.in);
		
		//表の行数rと列数cを読み取る
		String s1 = sc.next();
		int r = Integer.parseInt(s1);
		String s2 = sc.next();
		int c = Integer.parseInt(s2);
		//表を値を配列に受け取る
		int a[][] = new int[r][c];
		
		//cとrが条件範囲内か確認
		if(1 <= r && r <= 100){
			if(1 <= c && c <= 100){
				
				//配列に格納していく
				for(int i = 0; i < r; i++ ){
					for(int j = 0; j < c; j++){
						String s3 = sc.next();
						int k = Integer.parseInt(s3);
						a[i][j] = k;
					}
				}
				
				int total = 0;
				//入力された表の値と行ごとの合計値の表示
				for(int i = 0; i < r; i++ ){
					int sum = 0;
					for(int j = 0; j < c; j++){
						System.out.print(a[i][j] + " ");
						sum += a[i][j];
					}
					total += sum;
					System.out.println( sum );
				}
				
				//入力された表の値の列ごとの合計値の表示
				for(int j = 0; j < c; j++ ){
					int sum = 0;
					for(int i = 0; i < r; i++){
						sum += a[i][j];
					}
					System.out.print( sum + " ");
				}
				System.out.println( total );
			}
		}
	} main {
		
		Scanner sc = new Scanner(System.in);
		
		//表の行数rと列数cを読み取る
		String s1 = sc.next();
		int r = Integer.parseInt(s1);
		String s2 = sc.next();
		int c = Integer.parseInt(s2);
		//表を値を配列に受け取る
		int a[][] = new int[r][c];
		
		//cとrが条件範囲内か確認
		if(1 <= r && r <= 100){
			if(1 <= c && c <= 100){
				
				//配列に格納していく
				for(int i = 0; i < r; i++ ){
					for(int j = 0; j < c; j++){
						String s3 = sc.next();
						int k = Integer.parseInt(s3);
						a[i][j] = k;
					}
				}
				
				int total = 0;
				//入力された表の値と行ごとの合計値の表示
				for(int i = 0; i < r; i++ ){
					int sum = 0;
					for(int j = 0; j < c; j++){
						System.out.print(a[i][j] + " ");
						sum += a[i][j];
					}
					total += sum;
					System.out.println( sum );
				}
				
				//入力された表の値の列ごとの合計値の表示
				for(int j = 0; j < c; j++ ){
					int sum = 0;
					for(int i = 0; i < r; i++){
						sum += a[i][j];
					}
					System.out.print( sum + " ");
				}
				System.out.println( total );
			}
		}
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) String s1 = sc.next(); s1 sc.next() sc.next sc int r = Integer.parseInt(s1); r Integer.parseInt(s1) Integer.parseInt Integer s1 String s2 = sc.next(); s2 sc.next() sc.next sc int c = Integer.parseInt(s2); c Integer.parseInt(s2) Integer.parseInt Integer s2 int a[][] = new int[r][c]; a new int[r][c] r c if(1 <= r && r <= 100){
			if(1 <= c && c <= 100){
				
				//配列に格納していく
				for(int i = 0; i < r; i++ ){
					for(int j = 0; j < c; j++){
						String s3 = sc.next();
						int k = Integer.parseInt(s3);
						a[i][j] = k;
					}
				}
				
				int total = 0;
				//入力された表の値と行ごとの合計値の表示
				for(int i = 0; i < r; i++ ){
					int sum = 0;
					for(int j = 0; j < c; j++){
						System.out.print(a[i][j] + " ");
						sum += a[i][j];
					}
					total += sum;
					System.out.println( sum );
				}
				
				//入力された表の値の列ごとの合計値の表示
				for(int j = 0; j < c; j++ ){
					int sum = 0;
					for(int i = 0; i < r; i++){
						sum += a[i][j];
					}
					System.out.print( sum + " ");
				}
				System.out.println( total );
			}
		} 1 <= r && r <= 100 1 <= r 1 r r <= 100 r 100 {
			if(1 <= c && c <= 100){
				
				//配列に格納していく
				for(int i = 0; i < r; i++ ){
					for(int j = 0; j < c; j++){
						String s3 = sc.next();
						int k = Integer.parseInt(s3);
						a[i][j] = k;
					}
				}
				
				int total = 0;
				//入力された表の値と行ごとの合計値の表示
				for(int i = 0; i < r; i++ ){
					int sum = 0;
					for(int j = 0; j < c; j++){
						System.out.print(a[i][j] + " ");
						sum += a[i][j];
					}
					total += sum;
					System.out.println( sum );
				}
				
				//入力された表の値の列ごとの合計値の表示
				for(int j = 0; j < c; j++ ){
					int sum = 0;
					for(int i = 0; i < r; i++){
						sum += a[i][j];
					}
					System.out.print( sum + " ");
				}
				System.out.println( total );
			}
		} if(1 <= c && c <= 100){
				
				//配列に格納していく
				for(int i = 0; i < r; i++ ){
					for(int j = 0; j < c; j++){
						String s3 = sc.next();
						int k = Integer.parseInt(s3);
						a[i][j] = k;
					}
				}
				
				int total = 0;
				//入力された表の値と行ごとの合計値の表示
				for(int i = 0; i < r; i++ ){
					int sum = 0;
					for(int j = 0; j < c; j++){
						System.out.print(a[i][j] + " ");
						sum += a[i][j];
					}
					total += sum;
					System.out.println( sum );
				}
				
				//入力された表の値の列ごとの合計値の表示
				for(int j = 0; j < c; j++ ){
					int sum = 0;
					for(int i = 0; i < r; i++){
						sum += a[i][j];
					}
					System.out.print( sum + " ");
				}
				System.out.println( total );
			} 1 <= c && c <= 100 1 <= c 1 c c <= 100 c 100 {
				
				//配列に格納していく
				for(int i = 0; i < r; i++ ){
					for(int j = 0; j < c; j++){
						String s3 = sc.next();
						int k = Integer.parseInt(s3);
						a[i][j] = k;
					}
				}
				
				int total = 0;
				//入力された表の値と行ごとの合計値の表示
				for(int i = 0; i < r; i++ ){
					int sum = 0;
					for(int j = 0; j < c; j++){
						System.out.print(a[i][j] + " ");
						sum += a[i][j];
					}
					total += sum;
					System.out.println( sum );
				}
				
				//入力された表の値の列ごとの合計値の表示
				for(int j = 0; j < c; j++ ){
					int sum = 0;
					for(int i = 0; i < r; i++){
						sum += a[i][j];
					}
					System.out.print( sum + " ");
				}
				System.out.println( total );
			} for(int i = 0; i < r; i++ ){
					for(int j = 0; j < c; j++){
						String s3 = sc.next();
						int k = Integer.parseInt(s3);
						a[i][j] = k;
					}
				} int i = 0; int i = 0; i 0 i < r i r i++ i++ i {
					for(int j = 0; j < c; j++){
						String s3 = sc.next();
						int k = Integer.parseInt(s3);
						a[i][j] = k;
					}
				} {
					for(int j = 0; j < c; j++){
						String s3 = sc.next();
						int k = Integer.parseInt(s3);
						a[i][j] = k;
					}
				} for(int j = 0; j < c; j++){
						String s3 = sc.next();
						int k = Integer.parseInt(s3);
						a[i][j] = k;
					} int j = 0; int j = 0; j 0 j < c j c j++ j++ j {
						String s3 = sc.next();
						int k = Integer.parseInt(s3);
						a[i][j] = k;
					} {
						String s3 = sc.next();
						int k = Integer.parseInt(s3);
						a[i][j] = k;
					} String s3 = sc.next(); s3 sc.next() sc.next sc int k = Integer.parseInt(s3); k Integer.parseInt(s3) Integer.parseInt Integer s3 a[i][j] = k a[i][j] a[i] a i j k int total = 0; total 0 for(int i = 0; i < r; i++ ){
					int sum = 0;
					for(int j = 0; j < c; j++){
						System.out.print(a[i][j] + " ");
						sum += a[i][j];
					}
					total += sum;
					System.out.println( sum );
				} int i = 0; int i = 0; i 0 i < r i r i++ i++ i {
					int sum = 0;
					for(int j = 0; j < c; j++){
						System.out.print(a[i][j] + " ");
						sum += a[i][j];
					}
					total += sum;
					System.out.println( sum );
				} {
					int sum = 0;
					for(int j = 0; j < c; j++){
						System.out.print(a[i][j] + " ");
						sum += a[i][j];
					}
					total += sum;
					System.out.println( sum );
				} int sum = 0; sum 0 for(int j = 0; j < c; j++){
						System.out.print(a[i][j] + " ");
						sum += a[i][j];
					} int j = 0; int j = 0; j 0 j < c j c j++ j++ j {
						System.out.print(a[i][j] + " ");
						sum += a[i][j];
					} {
						System.out.print(a[i][j] + " ");
						sum += a[i][j];
					} System.out.print(a[i][j] + " ") System.out.print System.out System System.out a[i][j] + " " a[i][j] a[i] a i j " " sum += a[i][j] sum a[i][j] a[i] a i j total += sum total sum System.out.println( sum ) System.out.println System.out System System.out sum for(int j = 0; j < c; j++ ){
					int sum = 0;
					for(int i = 0; i < r; i++){
						sum += a[i][j];
					}
					System.out.print( sum + " ");
				} int j = 0; int j = 0; j 0 j < c j c j++ j++ j {
					int sum = 0;
					for(int i = 0; i < r; i++){
						sum += a[i][j];
					}
					System.out.print( sum + " ");
				} {
					int sum = 0;
					for(int i = 0; i < r; i++){
						sum += a[i][j];
					}
					System.out.print( sum + " ");
				} int sum = 0; sum 0 for(int i = 0; i < r; i++){
						sum += a[i][j];
					} int i = 0; int i = 0; i 0 i < r i r i++ i++ i {
						sum += a[i][j];
					} {
						sum += a[i][j];
					} sum += a[i][j] sum a[i][j] a[i] a i j System.out.print( sum + " ") System.out.print System.out System System.out sum + " " sum " " System.out.println( total ) System.out.println System.out System System.out total String args[] args

import java.util.*;

class Main {
	public static void main(String args[]){
		
		Scanner sc = new Scanner(System.in);
		
		//表の行数rと列数cを読み取る
		String s1 = sc.next();
		int r = Integer.parseInt(s1);
		String s2 = sc.next();
		int c = Integer.parseInt(s2);
		//表を値を配列に受け取る
		int a[][] = new int[r][c];
		
		//cとrが条件範囲内か確認
		if(1 <= r && r <= 100){
			if(1 <= c && c <= 100){
				
				//配列に格納していく
				for(int i = 0; i < r; i++ ){
					for(int j = 0; j < c; j++){
						String s3 = sc.next();
						int k = Integer.parseInt(s3);
						a[i][j] = k;
					}
				}
				
				int total = 0;
				//入力された表の値と行ごとの合計値の表示
				for(int i = 0; i < r; i++ ){
					int sum = 0;
					for(int j = 0; j < c; j++){
						System.out.print(a[i][j] + " ");
						sum += a[i][j];
					}
					total += sum;
					System.out.println( sum );
				}
				
				//入力された表の値の列ごとの合計値の表示
				for(int j = 0; j < c; j++ ){
					int sum = 0;
					for(int i = 0; i < r; i++){
						sum += a[i][j];
					}
					System.out.print( sum + " ");
				}
				System.out.println( total );
			}
		}
	}

}