import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
public class Main{
	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb = new StringBuilder();
		String[] line = br.readLine().split(" ");
		int r = Integer.parseInt(line[0]);
		int c = Integer.parseInt(line[1]);
		int[][] rc = new int[r+1][c+1];
		for(int i = 0; i < r; i++){
			String[] str =br.readLine().split(" ");
			for(int j = 0; j < c; j++){
				rc[i][j] = Integer.parseInt(str[j]);
				rc[i][c] +=  Integer.parseInt(str[j]);
			}
		}
		for(int i = 0; i < c+1; i++){
			for(int j = 0; j < r; j++){
				rc[r][i] += rc[j][i];
			}
		}
		for(int i = 0; i < r+1; i++){
			for(int j = 0; j < c+1; j++){
				//System.out.print(rc[i][j]+" ");
				sb.append(rc[i][j]);
        if(j != c) sb.append(" ");
			}
			//System.out.println();
			sb.append("\n");
		}
		System.out.print(sb);
		
	}
} import java.io.BufferedReader; BufferedReader java.io import java.io.InputStreamReader; InputStreamReader java.io import java.io.IOException; IOException java.io public class Main{
	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb = new StringBuilder();
		String[] line = br.readLine().split(" ");
		int r = Integer.parseInt(line[0]);
		int c = Integer.parseInt(line[1]);
		int[][] rc = new int[r+1][c+1];
		for(int i = 0; i < r; i++){
			String[] str =br.readLine().split(" ");
			for(int j = 0; j < c; j++){
				rc[i][j] = Integer.parseInt(str[j]);
				rc[i][c] +=  Integer.parseInt(str[j]);
			}
		}
		for(int i = 0; i < c+1; i++){
			for(int j = 0; j < r; j++){
				rc[r][i] += rc[j][i];
			}
		}
		for(int i = 0; i < r+1; i++){
			for(int j = 0; j < c+1; j++){
				//System.out.print(rc[i][j]+" ");
				sb.append(rc[i][j]);
        if(j != c) sb.append(" ");
			}
			//System.out.println();
			sb.append("\n");
		}
		System.out.print(sb);
		
	}
} Main public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb = new StringBuilder();
		String[] line = br.readLine().split(" ");
		int r = Integer.parseInt(line[0]);
		int c = Integer.parseInt(line[1]);
		int[][] rc = new int[r+1][c+1];
		for(int i = 0; i < r; i++){
			String[] str =br.readLine().split(" ");
			for(int j = 0; j < c; j++){
				rc[i][j] = Integer.parseInt(str[j]);
				rc[i][c] +=  Integer.parseInt(str[j]);
			}
		}
		for(int i = 0; i < c+1; i++){
			for(int j = 0; j < r; j++){
				rc[r][i] += rc[j][i];
			}
		}
		for(int i = 0; i < r+1; i++){
			for(int j = 0; j < c+1; j++){
				//System.out.print(rc[i][j]+" ");
				sb.append(rc[i][j]);
        if(j != c) sb.append(" ");
			}
			//System.out.println();
			sb.append("\n");
		}
		System.out.print(sb);
		
	} main {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb = new StringBuilder();
		String[] line = br.readLine().split(" ");
		int r = Integer.parseInt(line[0]);
		int c = Integer.parseInt(line[1]);
		int[][] rc = new int[r+1][c+1];
		for(int i = 0; i < r; i++){
			String[] str =br.readLine().split(" ");
			for(int j = 0; j < c; j++){
				rc[i][j] = Integer.parseInt(str[j]);
				rc[i][c] +=  Integer.parseInt(str[j]);
			}
		}
		for(int i = 0; i < c+1; i++){
			for(int j = 0; j < r; j++){
				rc[r][i] += rc[j][i];
			}
		}
		for(int i = 0; i < r+1; i++){
			for(int j = 0; j < c+1; j++){
				//System.out.print(rc[i][j]+" ");
				sb.append(rc[i][j]);
        if(j != c) sb.append(" ");
			}
			//System.out.println();
			sb.append("\n");
		}
		System.out.print(sb);
		
	} BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) StringBuilder sb = new StringBuilder(); sb new StringBuilder() String[] line = br.readLine().split(" "); line br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " int r = Integer.parseInt(line[0]); r Integer.parseInt(line[0]) Integer.parseInt Integer line[0] line 0 int c = Integer.parseInt(line[1]); c Integer.parseInt(line[1]) Integer.parseInt Integer line[1] line 1 int[][] rc = new int[r+1][c+1]; rc new int[r+1][c+1] r+1 r 1 c+1 c 1 for(int i = 0; i < r; i++){
			String[] str =br.readLine().split(" ");
			for(int j = 0; j < c; j++){
				rc[i][j] = Integer.parseInt(str[j]);
				rc[i][c] +=  Integer.parseInt(str[j]);
			}
		} int i = 0; int i = 0; i 0 i < r i r i++ i++ i {
			String[] str =br.readLine().split(" ");
			for(int j = 0; j < c; j++){
				rc[i][j] = Integer.parseInt(str[j]);
				rc[i][c] +=  Integer.parseInt(str[j]);
			}
		} {
			String[] str =br.readLine().split(" ");
			for(int j = 0; j < c; j++){
				rc[i][j] = Integer.parseInt(str[j]);
				rc[i][c] +=  Integer.parseInt(str[j]);
			}
		} String[] str =br.readLine().split(" "); str br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " for(int j = 0; j < c; j++){
				rc[i][j] = Integer.parseInt(str[j]);
				rc[i][c] +=  Integer.parseInt(str[j]);
			} int j = 0; int j = 0; j 0 j < c j c j++ j++ j {
				rc[i][j] = Integer.parseInt(str[j]);
				rc[i][c] +=  Integer.parseInt(str[j]);
			} {
				rc[i][j] = Integer.parseInt(str[j]);
				rc[i][c] +=  Integer.parseInt(str[j]);
			} rc[i][j] = Integer.parseInt(str[j]) rc[i][j] rc[i] rc i j Integer.parseInt(str[j]) Integer.parseInt Integer str[j] str j rc[i][c] +=  Integer.parseInt(str[j]) rc[i][c] rc[i] rc i c Integer.parseInt(str[j]) Integer.parseInt Integer str[j] str j for(int i = 0; i < c+1; i++){
			for(int j = 0; j < r; j++){
				rc[r][i] += rc[j][i];
			}
		} int i = 0; int i = 0; i 0 i < c+1 i c+1 c 1 i++ i++ i {
			for(int j = 0; j < r; j++){
				rc[r][i] += rc[j][i];
			}
		} {
			for(int j = 0; j < r; j++){
				rc[r][i] += rc[j][i];
			}
		} for(int j = 0; j < r; j++){
				rc[r][i] += rc[j][i];
			} int j = 0; int j = 0; j 0 j < r j r j++ j++ j {
				rc[r][i] += rc[j][i];
			} {
				rc[r][i] += rc[j][i];
			} rc[r][i] += rc[j][i] rc[r][i] rc[r] rc r i rc[j][i] rc[j] rc j i for(int i = 0; i < r+1; i++){
			for(int j = 0; j < c+1; j++){
				//System.out.print(rc[i][j]+" ");
				sb.append(rc[i][j]);
        if(j != c) sb.append(" ");
			}
			//System.out.println();
			sb.append("\n");
		} 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+1; j++){
				//System.out.print(rc[i][j]+" ");
				sb.append(rc[i][j]);
        if(j != c) sb.append(" ");
			}
			//System.out.println();
			sb.append("\n");
		} {
			for(int j = 0; j < c+1; j++){
				//System.out.print(rc[i][j]+" ");
				sb.append(rc[i][j]);
        if(j != c) sb.append(" ");
			}
			//System.out.println();
			sb.append("\n");
		} for(int j = 0; j < c+1; j++){
				//System.out.print(rc[i][j]+" ");
				sb.append(rc[i][j]);
        if(j != c) sb.append(" ");
			} int j = 0; int j = 0; j 0 j < c+1 j c+1 c 1 j++ j++ j {
				//System.out.print(rc[i][j]+" ");
				sb.append(rc[i][j]);
        if(j != c) sb.append(" ");
			} {
				//System.out.print(rc[i][j]+" ");
				sb.append(rc[i][j]);
        if(j != c) sb.append(" ");
			} sb.append(rc[i][j]) sb.append sb rc[i][j] rc[i] rc i j if(j != c) sb.append(" "); j != c j c sb.append(" ") sb.append sb " " sb.append("\n") sb.append sb "\n" System.out.print(sb) System.out.print System.out System System.out sb String[] args args public class Main{
	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb = new StringBuilder();
		String[] line = br.readLine().split(" ");
		int r = Integer.parseInt(line[0]);
		int c = Integer.parseInt(line[1]);
		int[][] rc = new int[r+1][c+1];
		for(int i = 0; i < r; i++){
			String[] str =br.readLine().split(" ");
			for(int j = 0; j < c; j++){
				rc[i][j] = Integer.parseInt(str[j]);
				rc[i][c] +=  Integer.parseInt(str[j]);
			}
		}
		for(int i = 0; i < c+1; i++){
			for(int j = 0; j < r; j++){
				rc[r][i] += rc[j][i];
			}
		}
		for(int i = 0; i < r+1; i++){
			for(int j = 0; j < c+1; j++){
				//System.out.print(rc[i][j]+" ");
				sb.append(rc[i][j]);
        if(j != c) sb.append(" ");
			}
			//System.out.println();
			sb.append("\n");
		}
		System.out.print(sb);
		
	}
} public class Main{
	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb = new StringBuilder();
		String[] line = br.readLine().split(" ");
		int r = Integer.parseInt(line[0]);
		int c = Integer.parseInt(line[1]);
		int[][] rc = new int[r+1][c+1];
		for(int i = 0; i < r; i++){
			String[] str =br.readLine().split(" ");
			for(int j = 0; j < c; j++){
				rc[i][j] = Integer.parseInt(str[j]);
				rc[i][c] +=  Integer.parseInt(str[j]);
			}
		}
		for(int i = 0; i < c+1; i++){
			for(int j = 0; j < r; j++){
				rc[r][i] += rc[j][i];
			}
		}
		for(int i = 0; i < r+1; i++){
			for(int j = 0; j < c+1; j++){
				//System.out.print(rc[i][j]+" ");
				sb.append(rc[i][j]);
        if(j != c) sb.append(" ");
			}
			//System.out.println();
			sb.append("\n");
		}
		System.out.print(sb);
		
	}
} Main
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
public class Main{
	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb = new StringBuilder();
		String[] line = br.readLine().split(" ");
		int r = Integer.parseInt(line[0]);
		int c = Integer.parseInt(line[1]);
		int[][] rc = new int[r+1][c+1];
		for(int i = 0; i < r; i++){
			String[] str =br.readLine().split(" ");
			for(int j = 0; j < c; j++){
				rc[i][j] = Integer.parseInt(str[j]);
				rc[i][c] +=  Integer.parseInt(str[j]);
			}
		}
		for(int i = 0; i < c+1; i++){
			for(int j = 0; j < r; j++){
				rc[r][i] += rc[j][i];
			}
		}
		for(int i = 0; i < r+1; i++){
			for(int j = 0; j < c+1; j++){
				//System.out.print(rc[i][j]+" ");
				sb.append(rc[i][j]);
        if(j != c) sb.append(" ");
			}
			//System.out.println();
			sb.append("\n");
		}
		System.out.print(sb);
		
	}
}