
import java.util.Scanner;

public class Main{
	public static void main(String args[]){

		//??????????????¨???????????????
		Scanner sc = new Scanner(System.in);
		int list [][];

		//????????????????????¨??¨?????????????????????????????????
		int r = sc.nextInt();
		int c = sc.nextInt();
		list = new int[r][c];


		//2?¬???????????????°?????????????????????
		for(int i = 0; i < r; i++){
			for(int j = 0; j < c; j++){
				list[i][j] = sc.nextInt();
			}
		}

		//??????????????¨???

		//???????????¨r???????¨??????¨???
		for(int i = 0; i < r; i++){
			int rsum = 0;
			String a = "";
			for(int j = 0; j < c; j++){
				rsum += list[i][j];
				a += (list[i][j] +" ");
			}
			System.out.println(a + (rsum));
		}

		//c??¨????¨??????¨???

		int sum = 0;
		for(int i = 0 ; i < c; i++){
			int csum = 0;
			for(int j = 0 ; j < r; j++){
				csum += list[j][i];
			}
			System.out.print(csum + " ");
			sum += csum;
		}

		System.out.println(sum);
		sc.close();
	}
} import java.util.Scanner; Scanner java.util public class Main{
	public static void main(String args[]){

		//??????????????¨???????????????
		Scanner sc = new Scanner(System.in);
		int list [][];

		//????????????????????¨??¨?????????????????????????????????
		int r = sc.nextInt();
		int c = sc.nextInt();
		list = new int[r][c];


		//2?¬???????????????°?????????????????????
		for(int i = 0; i < r; i++){
			for(int j = 0; j < c; j++){
				list[i][j] = sc.nextInt();
			}
		}

		//??????????????¨???

		//???????????¨r???????¨??????¨???
		for(int i = 0; i < r; i++){
			int rsum = 0;
			String a = "";
			for(int j = 0; j < c; j++){
				rsum += list[i][j];
				a += (list[i][j] +" ");
			}
			System.out.println(a + (rsum));
		}

		//c??¨????¨??????¨???

		int sum = 0;
		for(int i = 0 ; i < c; i++){
			int csum = 0;
			for(int j = 0 ; j < r; j++){
				csum += list[j][i];
			}
			System.out.print(csum + " ");
			sum += csum;
		}

		System.out.println(sum);
		sc.close();
	}
} Main public static void main(String args[]){

		//??????????????¨???????????????
		Scanner sc = new Scanner(System.in);
		int list [][];

		//????????????????????¨??¨?????????????????????????????????
		int r = sc.nextInt();
		int c = sc.nextInt();
		list = new int[r][c];


		//2?¬???????????????°?????????????????????
		for(int i = 0; i < r; i++){
			for(int j = 0; j < c; j++){
				list[i][j] = sc.nextInt();
			}
		}

		//??????????????¨???

		//???????????¨r???????¨??????¨???
		for(int i = 0; i < r; i++){
			int rsum = 0;
			String a = "";
			for(int j = 0; j < c; j++){
				rsum += list[i][j];
				a += (list[i][j] +" ");
			}
			System.out.println(a + (rsum));
		}

		//c??¨????¨??????¨???

		int sum = 0;
		for(int i = 0 ; i < c; i++){
			int csum = 0;
			for(int j = 0 ; j < r; j++){
				csum += list[j][i];
			}
			System.out.print(csum + " ");
			sum += csum;
		}

		System.out.println(sum);
		sc.close();
	} main {

		//??????????????¨???????????????
		Scanner sc = new Scanner(System.in);
		int list [][];

		//????????????????????¨??¨?????????????????????????????????
		int r = sc.nextInt();
		int c = sc.nextInt();
		list = new int[r][c];


		//2?¬???????????????°?????????????????????
		for(int i = 0; i < r; i++){
			for(int j = 0; j < c; j++){
				list[i][j] = sc.nextInt();
			}
		}

		//??????????????¨???

		//???????????¨r???????¨??????¨???
		for(int i = 0; i < r; i++){
			int rsum = 0;
			String a = "";
			for(int j = 0; j < c; j++){
				rsum += list[i][j];
				a += (list[i][j] +" ");
			}
			System.out.println(a + (rsum));
		}

		//c??¨????¨??????¨???

		int sum = 0;
		for(int i = 0 ; i < c; i++){
			int csum = 0;
			for(int j = 0 ; j < r; j++){
				csum += list[j][i];
			}
			System.out.print(csum + " ");
			sum += csum;
		}

		System.out.println(sum);
		sc.close();
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int list [][]; list int r = sc.nextInt(); r sc.nextInt() sc.nextInt sc int c = sc.nextInt(); c sc.nextInt() sc.nextInt sc list = new int[r][c] list new int[r][c] r c for(int i = 0; i < r; i++){
			for(int j = 0; j < c; j++){
				list[i][j] = sc.nextInt();
			}
		} int i = 0; int i = 0; i 0 i < r i r i++ i++ i {
			for(int j = 0; j < c; j++){
				list[i][j] = sc.nextInt();
			}
		} {
			for(int j = 0; j < c; j++){
				list[i][j] = sc.nextInt();
			}
		} for(int j = 0; j < c; j++){
				list[i][j] = sc.nextInt();
			} int j = 0; int j = 0; j 0 j < c j c j++ j++ j {
				list[i][j] = sc.nextInt();
			} {
				list[i][j] = sc.nextInt();
			} list[i][j] = sc.nextInt() list[i][j] list[i] list i j sc.nextInt() sc.nextInt sc for(int i = 0; i < r; i++){
			int rsum = 0;
			String a = "";
			for(int j = 0; j < c; j++){
				rsum += list[i][j];
				a += (list[i][j] +" ");
			}
			System.out.println(a + (rsum));
		} int i = 0; int i = 0; i 0 i < r i r i++ i++ i {
			int rsum = 0;
			String a = "";
			for(int j = 0; j < c; j++){
				rsum += list[i][j];
				a += (list[i][j] +" ");
			}
			System.out.println(a + (rsum));
		} {
			int rsum = 0;
			String a = "";
			for(int j = 0; j < c; j++){
				rsum += list[i][j];
				a += (list[i][j] +" ");
			}
			System.out.println(a + (rsum));
		} int rsum = 0; rsum 0 String a = ""; a "" for(int j = 0; j < c; j++){
				rsum += list[i][j];
				a += (list[i][j] +" ");
			} int j = 0; int j = 0; j 0 j < c j c j++ j++ j {
				rsum += list[i][j];
				a += (list[i][j] +" ");
			} {
				rsum += list[i][j];
				a += (list[i][j] +" ");
			} rsum += list[i][j] rsum list[i][j] list[i] list i j a += (list[i][j] +" ") a (list[i][j] +" ") list[i][j] list[i] list i j " " System.out.println(a + (rsum)) System.out.println System.out System System.out a + (rsum) a (rsum) int sum = 0; sum 0 for(int i = 0 ; i < c; i++){
			int csum = 0;
			for(int j = 0 ; j < r; j++){
				csum += list[j][i];
			}
			System.out.print(csum + " ");
			sum += csum;
		} int i = 0 ; int i = 0 ; i 0 i < c i c i++ i++ i {
			int csum = 0;
			for(int j = 0 ; j < r; j++){
				csum += list[j][i];
			}
			System.out.print(csum + " ");
			sum += csum;
		} {
			int csum = 0;
			for(int j = 0 ; j < r; j++){
				csum += list[j][i];
			}
			System.out.print(csum + " ");
			sum += csum;
		} int csum = 0; csum 0 for(int j = 0 ; j < r; j++){
				csum += list[j][i];
			} int j = 0 ; int j = 0 ; j 0 j < r j r j++ j++ j {
				csum += list[j][i];
			} {
				csum += list[j][i];
			} csum += list[j][i] csum list[j][i] list[j] list j i System.out.print(csum + " ") System.out.print System.out System System.out csum + " " csum " " sum += csum sum csum System.out.println(sum) System.out.println System.out System System.out sum sc.close() sc.close sc String args[] args public class Main{
	public static void main(String args[]){

		//??????????????¨???????????????
		Scanner sc = new Scanner(System.in);
		int list [][];

		//????????????????????¨??¨?????????????????????????????????
		int r = sc.nextInt();
		int c = sc.nextInt();
		list = new int[r][c];


		//2?¬???????????????°?????????????????????
		for(int i = 0; i < r; i++){
			for(int j = 0; j < c; j++){
				list[i][j] = sc.nextInt();
			}
		}

		//??????????????¨???

		//???????????¨r???????¨??????¨???
		for(int i = 0; i < r; i++){
			int rsum = 0;
			String a = "";
			for(int j = 0; j < c; j++){
				rsum += list[i][j];
				a += (list[i][j] +" ");
			}
			System.out.println(a + (rsum));
		}

		//c??¨????¨??????¨???

		int sum = 0;
		for(int i = 0 ; i < c; i++){
			int csum = 0;
			for(int j = 0 ; j < r; j++){
				csum += list[j][i];
			}
			System.out.print(csum + " ");
			sum += csum;
		}

		System.out.println(sum);
		sc.close();
	}
} public class Main{
	public static void main(String args[]){

		//??????????????¨???????????????
		Scanner sc = new Scanner(System.in);
		int list [][];

		//????????????????????¨??¨?????????????????????????????????
		int r = sc.nextInt();
		int c = sc.nextInt();
		list = new int[r][c];


		//2?¬???????????????°?????????????????????
		for(int i = 0; i < r; i++){
			for(int j = 0; j < c; j++){
				list[i][j] = sc.nextInt();
			}
		}

		//??????????????¨???

		//???????????¨r???????¨??????¨???
		for(int i = 0; i < r; i++){
			int rsum = 0;
			String a = "";
			for(int j = 0; j < c; j++){
				rsum += list[i][j];
				a += (list[i][j] +" ");
			}
			System.out.println(a + (rsum));
		}

		//c??¨????¨??????¨???

		int sum = 0;
		for(int i = 0 ; i < c; i++){
			int csum = 0;
			for(int j = 0 ; j < r; j++){
				csum += list[j][i];
			}
			System.out.print(csum + " ");
			sum += csum;
		}

		System.out.println(sum);
		sc.close();
	}
} Main

import java.util.Scanner;

public class Main{
	public static void main(String args[]){

		//??????????????¨???????????????
		Scanner sc = new Scanner(System.in);
		int list [][];

		//????????????????????¨??¨?????????????????????????????????
		int r = sc.nextInt();
		int c = sc.nextInt();
		list = new int[r][c];


		//2?¬???????????????°?????????????????????
		for(int i = 0; i < r; i++){
			for(int j = 0; j < c; j++){
				list[i][j] = sc.nextInt();
			}
		}

		//??????????????¨???

		//???????????¨r???????¨??????¨???
		for(int i = 0; i < r; i++){
			int rsum = 0;
			String a = "";
			for(int j = 0; j < c; j++){
				rsum += list[i][j];
				a += (list[i][j] +" ");
			}
			System.out.println(a + (rsum));
		}

		//c??¨????¨??????¨???

		int sum = 0;
		for(int i = 0 ; i < c; i++){
			int csum = 0;
			for(int j = 0 ; j < r; j++){
				csum += list[j][i];
			}
			System.out.print(csum + " ");
			sum += csum;
		}

		System.out.println(sum);
		sc.close();
	}
}