import java.io.*;

class Main {
	public static void main(String[] args){
		try{
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			String[] line = br.readLine().split(" ");
			int r = Integer.parseInt(line[0]);
			int c = Integer.parseInt(line[1]);
			int[][] r1 = new int[r][c];
			int sum2;

			for(int i = 0;i < r;i++){
				String[] str = br.readLine().split(" ");
				for(int j = 0;j < c;j++){
					r1[i][j] = 0;
					int a = Integer.parseInt(str[j]);
					r1[i][j] += a;
				}
			}
			for(int i = 0;i < r;i++){
				int sum = 0;
				for(int j = 0;j < c;j++){
					System.out.print(r1[i][j]+" ");
					sum += r1[i][j];
				}
				System.out.println(sum);
			}
			
			sum2 = 0;
			for(int j = 0;j < c;j++){
				int sum = 0;
				for(int i = 0;i < r;i++){
					sum += r1[i][j];
				}
				sum2 += sum;
				System.out.print(sum+" ");
				if(j == c-1){
					System.out.print(sum2);
				}		
			}
		System.out.print("\n");
		} catch (Exception e){
		}
	}
} import java.io.*; io.* java class Main {
	public static void main(String[] args){
		try{
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			String[] line = br.readLine().split(" ");
			int r = Integer.parseInt(line[0]);
			int c = Integer.parseInt(line[1]);
			int[][] r1 = new int[r][c];
			int sum2;

			for(int i = 0;i < r;i++){
				String[] str = br.readLine().split(" ");
				for(int j = 0;j < c;j++){
					r1[i][j] = 0;
					int a = Integer.parseInt(str[j]);
					r1[i][j] += a;
				}
			}
			for(int i = 0;i < r;i++){
				int sum = 0;
				for(int j = 0;j < c;j++){
					System.out.print(r1[i][j]+" ");
					sum += r1[i][j];
				}
				System.out.println(sum);
			}
			
			sum2 = 0;
			for(int j = 0;j < c;j++){
				int sum = 0;
				for(int i = 0;i < r;i++){
					sum += r1[i][j];
				}
				sum2 += sum;
				System.out.print(sum+" ");
				if(j == c-1){
					System.out.print(sum2);
				}		
			}
		System.out.print("\n");
		} catch (Exception e){
		}
	}
} Main public static void main(String[] args){
		try{
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			String[] line = br.readLine().split(" ");
			int r = Integer.parseInt(line[0]);
			int c = Integer.parseInt(line[1]);
			int[][] r1 = new int[r][c];
			int sum2;

			for(int i = 0;i < r;i++){
				String[] str = br.readLine().split(" ");
				for(int j = 0;j < c;j++){
					r1[i][j] = 0;
					int a = Integer.parseInt(str[j]);
					r1[i][j] += a;
				}
			}
			for(int i = 0;i < r;i++){
				int sum = 0;
				for(int j = 0;j < c;j++){
					System.out.print(r1[i][j]+" ");
					sum += r1[i][j];
				}
				System.out.println(sum);
			}
			
			sum2 = 0;
			for(int j = 0;j < c;j++){
				int sum = 0;
				for(int i = 0;i < r;i++){
					sum += r1[i][j];
				}
				sum2 += sum;
				System.out.print(sum+" ");
				if(j == c-1){
					System.out.print(sum2);
				}		
			}
		System.out.print("\n");
		} catch (Exception e){
		}
	} main {
		try{
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			String[] line = br.readLine().split(" ");
			int r = Integer.parseInt(line[0]);
			int c = Integer.parseInt(line[1]);
			int[][] r1 = new int[r][c];
			int sum2;

			for(int i = 0;i < r;i++){
				String[] str = br.readLine().split(" ");
				for(int j = 0;j < c;j++){
					r1[i][j] = 0;
					int a = Integer.parseInt(str[j]);
					r1[i][j] += a;
				}
			}
			for(int i = 0;i < r;i++){
				int sum = 0;
				for(int j = 0;j < c;j++){
					System.out.print(r1[i][j]+" ");
					sum += r1[i][j];
				}
				System.out.println(sum);
			}
			
			sum2 = 0;
			for(int j = 0;j < c;j++){
				int sum = 0;
				for(int i = 0;i < r;i++){
					sum += r1[i][j];
				}
				sum2 += sum;
				System.out.print(sum+" ");
				if(j == c-1){
					System.out.print(sum2);
				}		
			}
		System.out.print("\n");
		} catch (Exception e){
		}
	} try{
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			String[] line = br.readLine().split(" ");
			int r = Integer.parseInt(line[0]);
			int c = Integer.parseInt(line[1]);
			int[][] r1 = new int[r][c];
			int sum2;

			for(int i = 0;i < r;i++){
				String[] str = br.readLine().split(" ");
				for(int j = 0;j < c;j++){
					r1[i][j] = 0;
					int a = Integer.parseInt(str[j]);
					r1[i][j] += a;
				}
			}
			for(int i = 0;i < r;i++){
				int sum = 0;
				for(int j = 0;j < c;j++){
					System.out.print(r1[i][j]+" ");
					sum += r1[i][j];
				}
				System.out.println(sum);
			}
			
			sum2 = 0;
			for(int j = 0;j < c;j++){
				int sum = 0;
				for(int i = 0;i < r;i++){
					sum += r1[i][j];
				}
				sum2 += sum;
				System.out.print(sum+" ");
				if(j == c-1){
					System.out.print(sum2);
				}		
			}
		System.out.print("\n");
		} catch (Exception e){
		} catch (Exception e){
		} Exception e {
		} {
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			String[] line = br.readLine().split(" ");
			int r = Integer.parseInt(line[0]);
			int c = Integer.parseInt(line[1]);
			int[][] r1 = new int[r][c];
			int sum2;

			for(int i = 0;i < r;i++){
				String[] str = br.readLine().split(" ");
				for(int j = 0;j < c;j++){
					r1[i][j] = 0;
					int a = Integer.parseInt(str[j]);
					r1[i][j] += a;
				}
			}
			for(int i = 0;i < r;i++){
				int sum = 0;
				for(int j = 0;j < c;j++){
					System.out.print(r1[i][j]+" ");
					sum += r1[i][j];
				}
				System.out.println(sum);
			}
			
			sum2 = 0;
			for(int j = 0;j < c;j++){
				int sum = 0;
				for(int i = 0;i < r;i++){
					sum += r1[i][j];
				}
				sum2 += sum;
				System.out.print(sum+" ");
				if(j == c-1){
					System.out.print(sum2);
				}		
			}
		System.out.print("\n");
		} BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) 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[][] r1 = new int[r][c]; r1 new int[r][c] r c int sum2; sum2 for(int i = 0;i < r;i++){
				String[] str = br.readLine().split(" ");
				for(int j = 0;j < c;j++){
					r1[i][j] = 0;
					int a = Integer.parseInt(str[j]);
					r1[i][j] += a;
				}
			} 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++){
					r1[i][j] = 0;
					int a = Integer.parseInt(str[j]);
					r1[i][j] += a;
				}
			} {
				String[] str = br.readLine().split(" ");
				for(int j = 0;j < c;j++){
					r1[i][j] = 0;
					int a = Integer.parseInt(str[j]);
					r1[i][j] += a;
				}
			} String[] str = br.readLine().split(" "); str br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " for(int j = 0;j < c;j++){
					r1[i][j] = 0;
					int a = Integer.parseInt(str[j]);
					r1[i][j] += a;
				} int j = 0; int j = 0; j 0 j < c j c j++ j++ j {
					r1[i][j] = 0;
					int a = Integer.parseInt(str[j]);
					r1[i][j] += a;
				} {
					r1[i][j] = 0;
					int a = Integer.parseInt(str[j]);
					r1[i][j] += a;
				} r1[i][j] = 0 r1[i][j] r1[i] r1 i j 0 int a = Integer.parseInt(str[j]); a Integer.parseInt(str[j]) Integer.parseInt Integer str[j] str j r1[i][j] += a r1[i][j] r1[i] r1 i j a for(int i = 0;i < r;i++){
				int sum = 0;
				for(int j = 0;j < c;j++){
					System.out.print(r1[i][j]+" ");
					sum += r1[i][j];
				}
				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(r1[i][j]+" ");
					sum += r1[i][j];
				}
				System.out.println(sum);
			} {
				int sum = 0;
				for(int j = 0;j < c;j++){
					System.out.print(r1[i][j]+" ");
					sum += r1[i][j];
				}
				System.out.println(sum);
			} int sum = 0; sum 0 for(int j = 0;j < c;j++){
					System.out.print(r1[i][j]+" ");
					sum += r1[i][j];
				} int j = 0; int j = 0; j 0 j < c j c j++ j++ j {
					System.out.print(r1[i][j]+" ");
					sum += r1[i][j];
				} {
					System.out.print(r1[i][j]+" ");
					sum += r1[i][j];
				} System.out.print(r1[i][j]+" ") System.out.print System.out System System.out r1[i][j]+" " r1[i][j] r1[i] r1 i j " " sum += r1[i][j] sum r1[i][j] r1[i] r1 i j System.out.println(sum) System.out.println System.out System System.out sum sum2 = 0 sum2 0 for(int j = 0;j < c;j++){
				int sum = 0;
				for(int i = 0;i < r;i++){
					sum += r1[i][j];
				}
				sum2 += sum;
				System.out.print(sum+" ");
				if(j == c-1){
					System.out.print(sum2);
				}		
			} 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 += r1[i][j];
				}
				sum2 += sum;
				System.out.print(sum+" ");
				if(j == c-1){
					System.out.print(sum2);
				}		
			} {
				int sum = 0;
				for(int i = 0;i < r;i++){
					sum += r1[i][j];
				}
				sum2 += sum;
				System.out.print(sum+" ");
				if(j == c-1){
					System.out.print(sum2);
				}		
			} int sum = 0; sum 0 for(int i = 0;i < r;i++){
					sum += r1[i][j];
				} int i = 0; int i = 0; i 0 i < r i r i++ i++ i {
					sum += r1[i][j];
				} {
					sum += r1[i][j];
				} sum += r1[i][j] sum r1[i][j] r1[i] r1 i j sum2 += sum sum2 sum System.out.print(sum+" ") System.out.print System.out System System.out sum+" " sum " " if(j == c-1){
					System.out.print(sum2);
				} j == c-1 j c-1 c 1 {
					System.out.print(sum2);
				} System.out.print(sum2) System.out.print System.out System System.out sum2 System.out.print("\n") System.out.print System.out System System.out "\n" String[] args args
import java.io.*;

class Main {
	public static void main(String[] args){
		try{
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			String[] line = br.readLine().split(" ");
			int r = Integer.parseInt(line[0]);
			int c = Integer.parseInt(line[1]);
			int[][] r1 = new int[r][c];
			int sum2;

			for(int i = 0;i < r;i++){
				String[] str = br.readLine().split(" ");
				for(int j = 0;j < c;j++){
					r1[i][j] = 0;
					int a = Integer.parseInt(str[j]);
					r1[i][j] += a;
				}
			}
			for(int i = 0;i < r;i++){
				int sum = 0;
				for(int j = 0;j < c;j++){
					System.out.print(r1[i][j]+" ");
					sum += r1[i][j];
				}
				System.out.println(sum);
			}
			
			sum2 = 0;
			for(int j = 0;j < c;j++){
				int sum = 0;
				for(int i = 0;i < r;i++){
					sum += r1[i][j];
				}
				sum2 += sum;
				System.out.print(sum+" ");
				if(j == c-1){
					System.out.print(sum2);
				}		
			}
		System.out.print("\n");
		} catch (Exception e){
		}
	}
}