import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int Row=sc.nextInt();
        int Col=sc.nextInt();
        int table[][] =new int[Row+1][Col+1];
        for(int i=0;i<Row;i++){
            for(int j=0;j<Col;j++){
                table[i][j]=sc.nextInt();
            }
        }
        for(int i = 0; i < Row; i++){
			for(int j = 0; j < Col; j++){
				table[i][Col] += table[i][j];
			}
		}

		for(int i = 0; i <= Col; i++){
			for(int j = 0; j < Row; j++){
				table[Row][i] += table[j][i];
			}
		}

		for(int i = 0; i <= Row; i++){
			System.out.printf("%d", table[i][0]);
			for(int j = 1; j <= Col; j++){
				System.out.printf(" %d", table[i][j]);
			}
			System.out.printf("\n");
		}
    }
} import java.util.*; util.* java public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int Row=sc.nextInt();
        int Col=sc.nextInt();
        int table[][] =new int[Row+1][Col+1];
        for(int i=0;i<Row;i++){
            for(int j=0;j<Col;j++){
                table[i][j]=sc.nextInt();
            }
        }
        for(int i = 0; i < Row; i++){
			for(int j = 0; j < Col; j++){
				table[i][Col] += table[i][j];
			}
		}

		for(int i = 0; i <= Col; i++){
			for(int j = 0; j < Row; j++){
				table[Row][i] += table[j][i];
			}
		}

		for(int i = 0; i <= Row; i++){
			System.out.printf("%d", table[i][0]);
			for(int j = 1; j <= Col; j++){
				System.out.printf(" %d", table[i][j]);
			}
			System.out.printf("\n");
		}
    }
} Main public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int Row=sc.nextInt();
        int Col=sc.nextInt();
        int table[][] =new int[Row+1][Col+1];
        for(int i=0;i<Row;i++){
            for(int j=0;j<Col;j++){
                table[i][j]=sc.nextInt();
            }
        }
        for(int i = 0; i < Row; i++){
			for(int j = 0; j < Col; j++){
				table[i][Col] += table[i][j];
			}
		}

		for(int i = 0; i <= Col; i++){
			for(int j = 0; j < Row; j++){
				table[Row][i] += table[j][i];
			}
		}

		for(int i = 0; i <= Row; i++){
			System.out.printf("%d", table[i][0]);
			for(int j = 1; j <= Col; j++){
				System.out.printf(" %d", table[i][j]);
			}
			System.out.printf("\n");
		}
    } main {
        Scanner sc = new Scanner(System.in);
        int Row=sc.nextInt();
        int Col=sc.nextInt();
        int table[][] =new int[Row+1][Col+1];
        for(int i=0;i<Row;i++){
            for(int j=0;j<Col;j++){
                table[i][j]=sc.nextInt();
            }
        }
        for(int i = 0; i < Row; i++){
			for(int j = 0; j < Col; j++){
				table[i][Col] += table[i][j];
			}
		}

		for(int i = 0; i <= Col; i++){
			for(int j = 0; j < Row; j++){
				table[Row][i] += table[j][i];
			}
		}

		for(int i = 0; i <= Row; i++){
			System.out.printf("%d", table[i][0]);
			for(int j = 1; j <= Col; j++){
				System.out.printf(" %d", table[i][j]);
			}
			System.out.printf("\n");
		}
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int Row=sc.nextInt(); Row sc.nextInt() sc.nextInt sc int Col=sc.nextInt(); Col sc.nextInt() sc.nextInt sc int table[][] =new int[Row+1][Col+1]; table new int[Row+1][Col+1] Row+1 Row 1 Col+1 Col 1 for(int i=0;i<Row;i++){
            for(int j=0;j<Col;j++){
                table[i][j]=sc.nextInt();
            }
        } int i=0; int i=0; i 0 i<Row i Row i++ i++ i {
            for(int j=0;j<Col;j++){
                table[i][j]=sc.nextInt();
            }
        } {
            for(int j=0;j<Col;j++){
                table[i][j]=sc.nextInt();
            }
        } for(int j=0;j<Col;j++){
                table[i][j]=sc.nextInt();
            } int j=0; int j=0; j 0 j<Col j Col j++ j++ j {
                table[i][j]=sc.nextInt();
            } {
                table[i][j]=sc.nextInt();
            } table[i][j]=sc.nextInt() table[i][j] table[i] table i j sc.nextInt() sc.nextInt sc for(int i = 0; i < Row; i++){
			for(int j = 0; j < Col; j++){
				table[i][Col] += table[i][j];
			}
		} int i = 0; int i = 0; i 0 i < Row i Row i++ i++ i {
			for(int j = 0; j < Col; j++){
				table[i][Col] += table[i][j];
			}
		} {
			for(int j = 0; j < Col; j++){
				table[i][Col] += table[i][j];
			}
		} for(int j = 0; j < Col; j++){
				table[i][Col] += table[i][j];
			} int j = 0; int j = 0; j 0 j < Col j Col j++ j++ j {
				table[i][Col] += table[i][j];
			} {
				table[i][Col] += table[i][j];
			} table[i][Col] += table[i][j] table[i][Col] table[i] table i Col table[i][j] table[i] table i j for(int i = 0; i <= Col; i++){
			for(int j = 0; j < Row; j++){
				table[Row][i] += table[j][i];
			}
		} int i = 0; int i = 0; i 0 i <= Col i Col i++ i++ i {
			for(int j = 0; j < Row; j++){
				table[Row][i] += table[j][i];
			}
		} {
			for(int j = 0; j < Row; j++){
				table[Row][i] += table[j][i];
			}
		} for(int j = 0; j < Row; j++){
				table[Row][i] += table[j][i];
			} int j = 0; int j = 0; j 0 j < Row j Row j++ j++ j {
				table[Row][i] += table[j][i];
			} {
				table[Row][i] += table[j][i];
			} table[Row][i] += table[j][i] table[Row][i] table[Row] table Row i table[j][i] table[j] table j i for(int i = 0; i <= Row; i++){
			System.out.printf("%d", table[i][0]);
			for(int j = 1; j <= Col; j++){
				System.out.printf(" %d", table[i][j]);
			}
			System.out.printf("\n");
		} int i = 0; int i = 0; i 0 i <= Row i Row i++ i++ i {
			System.out.printf("%d", table[i][0]);
			for(int j = 1; j <= Col; j++){
				System.out.printf(" %d", table[i][j]);
			}
			System.out.printf("\n");
		} {
			System.out.printf("%d", table[i][0]);
			for(int j = 1; j <= Col; j++){
				System.out.printf(" %d", table[i][j]);
			}
			System.out.printf("\n");
		} System.out.printf("%d", table[i][0]) System.out.printf System.out System System.out "%d" table[i][0] table[i] table i 0 for(int j = 1; j <= Col; j++){
				System.out.printf(" %d", table[i][j]);
			} int j = 1; int j = 1; j 1 j <= Col j Col j++ j++ j {
				System.out.printf(" %d", table[i][j]);
			} {
				System.out.printf(" %d", table[i][j]);
			} System.out.printf(" %d", table[i][j]) System.out.printf System.out System System.out " %d" table[i][j] table[i] table i j System.out.printf("\n") System.out.printf System.out System System.out "\n" String[] args args public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int Row=sc.nextInt();
        int Col=sc.nextInt();
        int table[][] =new int[Row+1][Col+1];
        for(int i=0;i<Row;i++){
            for(int j=0;j<Col;j++){
                table[i][j]=sc.nextInt();
            }
        }
        for(int i = 0; i < Row; i++){
			for(int j = 0; j < Col; j++){
				table[i][Col] += table[i][j];
			}
		}

		for(int i = 0; i <= Col; i++){
			for(int j = 0; j < Row; j++){
				table[Row][i] += table[j][i];
			}
		}

		for(int i = 0; i <= Row; i++){
			System.out.printf("%d", table[i][0]);
			for(int j = 1; j <= Col; j++){
				System.out.printf(" %d", table[i][j]);
			}
			System.out.printf("\n");
		}
    }
} public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int Row=sc.nextInt();
        int Col=sc.nextInt();
        int table[][] =new int[Row+1][Col+1];
        for(int i=0;i<Row;i++){
            for(int j=0;j<Col;j++){
                table[i][j]=sc.nextInt();
            }
        }
        for(int i = 0; i < Row; i++){
			for(int j = 0; j < Col; j++){
				table[i][Col] += table[i][j];
			}
		}

		for(int i = 0; i <= Col; i++){
			for(int j = 0; j < Row; j++){
				table[Row][i] += table[j][i];
			}
		}

		for(int i = 0; i <= Row; i++){
			System.out.printf("%d", table[i][0]);
			for(int j = 1; j <= Col; j++){
				System.out.printf(" %d", table[i][j]);
			}
			System.out.printf("\n");
		}
    }
} Main
import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int Row=sc.nextInt();
        int Col=sc.nextInt();
        int table[][] =new int[Row+1][Col+1];
        for(int i=0;i<Row;i++){
            for(int j=0;j<Col;j++){
                table[i][j]=sc.nextInt();
            }
        }
        for(int i = 0; i < Row; i++){
			for(int j = 0; j < Col; j++){
				table[i][Col] += table[i][j];
			}
		}

		for(int i = 0; i <= Col; i++){
			for(int j = 0; j < Row; j++){
				table[Row][i] += table[j][i];
			}
		}

		for(int i = 0; i <= Row; i++){
			System.out.printf("%d", table[i][0]);
			for(int j = 1; j <= Col; j++){
				System.out.printf(" %d", table[i][j]);
			}
			System.out.printf("\n");
		}
    }
}
