import java.util.*;

class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String[] input =sc.nextLine().split(" ");
		int r = Integer.parseInt(input[0]);
		int c = Integer.parseInt(input[1]);
		int[][] sheet = new int[r+1][c+1];
	//in	
		for(int i=0;i<r;i++){
			String[] line = sc.nextLine().split(" ");
			int sum=0;
			for(int j=0;j<c;j++){
				sheet[i][j]=Integer.parseInt(line[j]);
				sum = sum+sheet[i][j];
			}
			sheet[i][c]=sum;
		}	
		for(int i=0;i<c+1;i++){
			int sum=0;
			for(int j=0;j<r;j++){
				sum=sum+sheet[j][i];
			}
			sheet[r][i]=sum;
		}
	//out
		for(int i=0;i<r+1;i++){
			for(int j=0;j<c;j++){
				System.out.print(sheet[i][j]+" ");
			}
			System.out.println(sheet[i][c]);
		}
	}
} import java.util.*; util.* java class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String[] input =sc.nextLine().split(" ");
		int r = Integer.parseInt(input[0]);
		int c = Integer.parseInt(input[1]);
		int[][] sheet = new int[r+1][c+1];
	//in	
		for(int i=0;i<r;i++){
			String[] line = sc.nextLine().split(" ");
			int sum=0;
			for(int j=0;j<c;j++){
				sheet[i][j]=Integer.parseInt(line[j]);
				sum = sum+sheet[i][j];
			}
			sheet[i][c]=sum;
		}	
		for(int i=0;i<c+1;i++){
			int sum=0;
			for(int j=0;j<r;j++){
				sum=sum+sheet[j][i];
			}
			sheet[r][i]=sum;
		}
	//out
		for(int i=0;i<r+1;i++){
			for(int j=0;j<c;j++){
				System.out.print(sheet[i][j]+" ");
			}
			System.out.println(sheet[i][c]);
		}
	}
} Main public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String[] input =sc.nextLine().split(" ");
		int r = Integer.parseInt(input[0]);
		int c = Integer.parseInt(input[1]);
		int[][] sheet = new int[r+1][c+1];
	//in	
		for(int i=0;i<r;i++){
			String[] line = sc.nextLine().split(" ");
			int sum=0;
			for(int j=0;j<c;j++){
				sheet[i][j]=Integer.parseInt(line[j]);
				sum = sum+sheet[i][j];
			}
			sheet[i][c]=sum;
		}	
		for(int i=0;i<c+1;i++){
			int sum=0;
			for(int j=0;j<r;j++){
				sum=sum+sheet[j][i];
			}
			sheet[r][i]=sum;
		}
	//out
		for(int i=0;i<r+1;i++){
			for(int j=0;j<c;j++){
				System.out.print(sheet[i][j]+" ");
			}
			System.out.println(sheet[i][c]);
		}
	} main {
		Scanner sc = new Scanner(System.in);
		String[] input =sc.nextLine().split(" ");
		int r = Integer.parseInt(input[0]);
		int c = Integer.parseInt(input[1]);
		int[][] sheet = new int[r+1][c+1];
	//in	
		for(int i=0;i<r;i++){
			String[] line = sc.nextLine().split(" ");
			int sum=0;
			for(int j=0;j<c;j++){
				sheet[i][j]=Integer.parseInt(line[j]);
				sum = sum+sheet[i][j];
			}
			sheet[i][c]=sum;
		}	
		for(int i=0;i<c+1;i++){
			int sum=0;
			for(int j=0;j<r;j++){
				sum=sum+sheet[j][i];
			}
			sheet[r][i]=sum;
		}
	//out
		for(int i=0;i<r+1;i++){
			for(int j=0;j<c;j++){
				System.out.print(sheet[i][j]+" ");
			}
			System.out.println(sheet[i][c]);
		}
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) String[] input =sc.nextLine().split(" "); input sc.nextLine().split(" ") sc.nextLine().split sc.nextLine() sc.nextLine sc " " int r = Integer.parseInt(input[0]); r Integer.parseInt(input[0]) Integer.parseInt Integer input[0] input 0 int c = Integer.parseInt(input[1]); c Integer.parseInt(input[1]) Integer.parseInt Integer input[1] input 1 int[][] sheet = new int[r+1][c+1]; sheet new int[r+1][c+1] r+1 r 1 c+1 c 1 for(int i=0;i<r;i++){
			String[] line = sc.nextLine().split(" ");
			int sum=0;
			for(int j=0;j<c;j++){
				sheet[i][j]=Integer.parseInt(line[j]);
				sum = sum+sheet[i][j];
			}
			sheet[i][c]=sum;
		} int i=0; int i=0; i 0 i<r i r i++ i++ i {
			String[] line = sc.nextLine().split(" ");
			int sum=0;
			for(int j=0;j<c;j++){
				sheet[i][j]=Integer.parseInt(line[j]);
				sum = sum+sheet[i][j];
			}
			sheet[i][c]=sum;
		} {
			String[] line = sc.nextLine().split(" ");
			int sum=0;
			for(int j=0;j<c;j++){
				sheet[i][j]=Integer.parseInt(line[j]);
				sum = sum+sheet[i][j];
			}
			sheet[i][c]=sum;
		} String[] line = sc.nextLine().split(" "); line sc.nextLine().split(" ") sc.nextLine().split sc.nextLine() sc.nextLine sc " " int sum=0; sum 0 for(int j=0;j<c;j++){
				sheet[i][j]=Integer.parseInt(line[j]);
				sum = sum+sheet[i][j];
			} int j=0; int j=0; j 0 j<c j c j++ j++ j {
				sheet[i][j]=Integer.parseInt(line[j]);
				sum = sum+sheet[i][j];
			} {
				sheet[i][j]=Integer.parseInt(line[j]);
				sum = sum+sheet[i][j];
			} sheet[i][j]=Integer.parseInt(line[j]) sheet[i][j] sheet[i] sheet i j Integer.parseInt(line[j]) Integer.parseInt Integer line[j] line j sum = sum+sheet[i][j] sum sum+sheet[i][j] sum sheet[i][j] sheet[i] sheet i j sheet[i][c]=sum sheet[i][c] sheet[i] sheet i c sum for(int i=0;i<c+1;i++){
			int sum=0;
			for(int j=0;j<r;j++){
				sum=sum+sheet[j][i];
			}
			sheet[r][i]=sum;
		} int i=0; int i=0; i 0 i<c+1 i c+1 c 1 i++ i++ i {
			int sum=0;
			for(int j=0;j<r;j++){
				sum=sum+sheet[j][i];
			}
			sheet[r][i]=sum;
		} {
			int sum=0;
			for(int j=0;j<r;j++){
				sum=sum+sheet[j][i];
			}
			sheet[r][i]=sum;
		} int sum=0; sum 0 for(int j=0;j<r;j++){
				sum=sum+sheet[j][i];
			} int j=0; int j=0; j 0 j<r j r j++ j++ j {
				sum=sum+sheet[j][i];
			} {
				sum=sum+sheet[j][i];
			} sum=sum+sheet[j][i] sum sum+sheet[j][i] sum sheet[j][i] sheet[j] sheet j i sheet[r][i]=sum sheet[r][i] sheet[r] sheet r i sum for(int i=0;i<r+1;i++){
			for(int j=0;j<c;j++){
				System.out.print(sheet[i][j]+" ");
			}
			System.out.println(sheet[i][c]);
		} int i=0; int i=0; i 0 i<r+1 i r+1 r 1 i++ i++ i {
			for(int j=0;j<c;j++){
				System.out.print(sheet[i][j]+" ");
			}
			System.out.println(sheet[i][c]);
		} {
			for(int j=0;j<c;j++){
				System.out.print(sheet[i][j]+" ");
			}
			System.out.println(sheet[i][c]);
		} for(int j=0;j<c;j++){
				System.out.print(sheet[i][j]+" ");
			} int j=0; int j=0; j 0 j<c j c j++ j++ j {
				System.out.print(sheet[i][j]+" ");
			} {
				System.out.print(sheet[i][j]+" ");
			} System.out.print(sheet[i][j]+" ") System.out.print System.out System System.out sheet[i][j]+" " sheet[i][j] sheet[i] sheet i j " " System.out.println(sheet[i][c]) System.out.println System.out System System.out sheet[i][c] sheet[i] sheet i c String[] args args
import java.util.*;

class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String[] input =sc.nextLine().split(" ");
		int r = Integer.parseInt(input[0]);
		int c = Integer.parseInt(input[1]);
		int[][] sheet = new int[r+1][c+1];
	//in	
		for(int i=0;i<r;i++){
			String[] line = sc.nextLine().split(" ");
			int sum=0;
			for(int j=0;j<c;j++){
				sheet[i][j]=Integer.parseInt(line[j]);
				sum = sum+sheet[i][j];
			}
			sheet[i][c]=sum;
		}	
		for(int i=0;i<c+1;i++){
			int sum=0;
			for(int j=0;j<r;j++){
				sum=sum+sheet[j][i];
			}
			sheet[r][i]=sum;
		}
	//out
		for(int i=0;i<r+1;i++){
			for(int j=0;j<c;j++){
				System.out.print(sheet[i][j]+" ");
			}
			System.out.println(sheet[i][c]);
		}
	}
}