import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int t = scan.nextInt();
		int u = scan.nextInt();
		int n = t + 1;
		int m = u + 1;
		int[][] a = new int[n][m];
		int b[] = new int[m];
		int c[] = new int[n];
		int i,r;
		for(i = 0; i < n - 1; ++i){
			for(r = 0; r < m - 1; ++r){
				a[i][r] = scan.nextInt();
				a[i][m - 1] += a[i][r];
				a[n - 1][r]	+= a[i][r];
				a[n - 1][m - 1] += a[i][r];
			}
		}
		for(i = 0; i < n; ++i){
			for(r = 0; r < m; ++r){
				if(r == m - 1){
					System.out.println(a[i][r]);
				}
				else
				System.out.print(a[i][r]+" ");
				
			}
		}
	}
}
		 import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int t = scan.nextInt();
		int u = scan.nextInt();
		int n = t + 1;
		int m = u + 1;
		int[][] a = new int[n][m];
		int b[] = new int[m];
		int c[] = new int[n];
		int i,r;
		for(i = 0; i < n - 1; ++i){
			for(r = 0; r < m - 1; ++r){
				a[i][r] = scan.nextInt();
				a[i][m - 1] += a[i][r];
				a[n - 1][r]	+= a[i][r];
				a[n - 1][m - 1] += a[i][r];
			}
		}
		for(i = 0; i < n; ++i){
			for(r = 0; r < m; ++r){
				if(r == m - 1){
					System.out.println(a[i][r]);
				}
				else
				System.out.print(a[i][r]+" ");
				
			}
		}
	}
} Main public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int t = scan.nextInt();
		int u = scan.nextInt();
		int n = t + 1;
		int m = u + 1;
		int[][] a = new int[n][m];
		int b[] = new int[m];
		int c[] = new int[n];
		int i,r;
		for(i = 0; i < n - 1; ++i){
			for(r = 0; r < m - 1; ++r){
				a[i][r] = scan.nextInt();
				a[i][m - 1] += a[i][r];
				a[n - 1][r]	+= a[i][r];
				a[n - 1][m - 1] += a[i][r];
			}
		}
		for(i = 0; i < n; ++i){
			for(r = 0; r < m; ++r){
				if(r == m - 1){
					System.out.println(a[i][r]);
				}
				else
				System.out.print(a[i][r]+" ");
				
			}
		}
	} main {
		Scanner scan = new Scanner(System.in);
		int t = scan.nextInt();
		int u = scan.nextInt();
		int n = t + 1;
		int m = u + 1;
		int[][] a = new int[n][m];
		int b[] = new int[m];
		int c[] = new int[n];
		int i,r;
		for(i = 0; i < n - 1; ++i){
			for(r = 0; r < m - 1; ++r){
				a[i][r] = scan.nextInt();
				a[i][m - 1] += a[i][r];
				a[n - 1][r]	+= a[i][r];
				a[n - 1][m - 1] += a[i][r];
			}
		}
		for(i = 0; i < n; ++i){
			for(r = 0; r < m; ++r){
				if(r == m - 1){
					System.out.println(a[i][r]);
				}
				else
				System.out.print(a[i][r]+" ");
				
			}
		}
	} Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int t = scan.nextInt(); t scan.nextInt() scan.nextInt scan int u = scan.nextInt(); u scan.nextInt() scan.nextInt scan int n = t + 1; n t + 1 t 1 int m = u + 1; m u + 1 u 1 int[][] a = new int[n][m]; a new int[n][m] n m int b[] = new int[m]; b new int[m] m int c[] = new int[n]; c new int[n] n int i i r; r for(i = 0; i < n - 1; ++i){
			for(r = 0; r < m - 1; ++r){
				a[i][r] = scan.nextInt();
				a[i][m - 1] += a[i][r];
				a[n - 1][r]	+= a[i][r];
				a[n - 1][m - 1] += a[i][r];
			}
		} i = 0; i = 0 i 0 i < n - 1 i n - 1 n 1 ++i ++i i {
			for(r = 0; r < m - 1; ++r){
				a[i][r] = scan.nextInt();
				a[i][m - 1] += a[i][r];
				a[n - 1][r]	+= a[i][r];
				a[n - 1][m - 1] += a[i][r];
			}
		} {
			for(r = 0; r < m - 1; ++r){
				a[i][r] = scan.nextInt();
				a[i][m - 1] += a[i][r];
				a[n - 1][r]	+= a[i][r];
				a[n - 1][m - 1] += a[i][r];
			}
		} for(r = 0; r < m - 1; ++r){
				a[i][r] = scan.nextInt();
				a[i][m - 1] += a[i][r];
				a[n - 1][r]	+= a[i][r];
				a[n - 1][m - 1] += a[i][r];
			} r = 0; r = 0 r 0 r < m - 1 r m - 1 m 1 ++r ++r r {
				a[i][r] = scan.nextInt();
				a[i][m - 1] += a[i][r];
				a[n - 1][r]	+= a[i][r];
				a[n - 1][m - 1] += a[i][r];
			} {
				a[i][r] = scan.nextInt();
				a[i][m - 1] += a[i][r];
				a[n - 1][r]	+= a[i][r];
				a[n - 1][m - 1] += a[i][r];
			} a[i][r] = scan.nextInt() a[i][r] a[i] a i r scan.nextInt() scan.nextInt scan a[i][m - 1] += a[i][r] a[i][m - 1] a[i] a i m - 1 m 1 a[i][r] a[i] a i r a[n - 1][r]	+= a[i][r] a[n - 1][r] a[n - 1] a n - 1 n 1 r a[i][r] a[i] a i r a[n - 1][m - 1] += a[i][r] a[n - 1][m - 1] a[n - 1] a n - 1 n 1 m - 1 m 1 a[i][r] a[i] a i r for(i = 0; i < n; ++i){
			for(r = 0; r < m; ++r){
				if(r == m - 1){
					System.out.println(a[i][r]);
				}
				else
				System.out.print(a[i][r]+" ");
				
			}
		} i = 0; i = 0 i 0 i < n i n ++i ++i i {
			for(r = 0; r < m; ++r){
				if(r == m - 1){
					System.out.println(a[i][r]);
				}
				else
				System.out.print(a[i][r]+" ");
				
			}
		} {
			for(r = 0; r < m; ++r){
				if(r == m - 1){
					System.out.println(a[i][r]);
				}
				else
				System.out.print(a[i][r]+" ");
				
			}
		} for(r = 0; r < m; ++r){
				if(r == m - 1){
					System.out.println(a[i][r]);
				}
				else
				System.out.print(a[i][r]+" ");
				
			} r = 0; r = 0 r 0 r < m r m ++r ++r r {
				if(r == m - 1){
					System.out.println(a[i][r]);
				}
				else
				System.out.print(a[i][r]+" ");
				
			} {
				if(r == m - 1){
					System.out.println(a[i][r]);
				}
				else
				System.out.print(a[i][r]+" ");
				
			} if(r == m - 1){
					System.out.println(a[i][r]);
				}
				else
				System.out.print(a[i][r]+" "); r == m - 1 r m - 1 m 1 {
					System.out.println(a[i][r]);
				} System.out.println(a[i][r]) System.out.println System.out System System.out a[i][r] a[i] a i r System.out.print(a[i][r]+" ") System.out.print System.out System System.out a[i][r]+" " a[i][r] a[i] a i r " " String[] args args public class Main {
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int t = scan.nextInt();
		int u = scan.nextInt();
		int n = t + 1;
		int m = u + 1;
		int[][] a = new int[n][m];
		int b[] = new int[m];
		int c[] = new int[n];
		int i,r;
		for(i = 0; i < n - 1; ++i){
			for(r = 0; r < m - 1; ++r){
				a[i][r] = scan.nextInt();
				a[i][m - 1] += a[i][r];
				a[n - 1][r]	+= a[i][r];
				a[n - 1][m - 1] += a[i][r];
			}
		}
		for(i = 0; i < n; ++i){
			for(r = 0; r < m; ++r){
				if(r == m - 1){
					System.out.println(a[i][r]);
				}
				else
				System.out.print(a[i][r]+" ");
				
			}
		}
	}
} public class Main {
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int t = scan.nextInt();
		int u = scan.nextInt();
		int n = t + 1;
		int m = u + 1;
		int[][] a = new int[n][m];
		int b[] = new int[m];
		int c[] = new int[n];
		int i,r;
		for(i = 0; i < n - 1; ++i){
			for(r = 0; r < m - 1; ++r){
				a[i][r] = scan.nextInt();
				a[i][m - 1] += a[i][r];
				a[n - 1][r]	+= a[i][r];
				a[n - 1][m - 1] += a[i][r];
			}
		}
		for(i = 0; i < n; ++i){
			for(r = 0; r < m; ++r){
				if(r == m - 1){
					System.out.println(a[i][r]);
				}
				else
				System.out.print(a[i][r]+" ");
				
			}
		}
	}
} Main
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int t = scan.nextInt();
		int u = scan.nextInt();
		int n = t + 1;
		int m = u + 1;
		int[][] a = new int[n][m];
		int b[] = new int[m];
		int c[] = new int[n];
		int i,r;
		for(i = 0; i < n - 1; ++i){
			for(r = 0; r < m - 1; ++r){
				a[i][r] = scan.nextInt();
				a[i][m - 1] += a[i][r];
				a[n - 1][r]	+= a[i][r];
				a[n - 1][m - 1] += a[i][r];
			}
		}
		for(i = 0; i < n; ++i){
			for(r = 0; r < m; ++r){
				if(r == m - 1){
					System.out.println(a[i][r]);
				}
				else
				System.out.print(a[i][r]+" ");
				
			}
		}
	}
}
		