import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int r = sc.nextInt();
		int c = sc.nextInt();
		int num = 0;
		int total = 0;
		int [] addc = new int[c];
		for (int i=0;i<r; i++){
			int addr = 0;
			for (int j=0; j<c; j++){
				num = sc.nextInt();
				System.out.print(num + " ");
				addr += num;
				addc[j] += num;
				total += num;
			}
			System.out.println(addr);
		}
		for (int j=0; j<c; j++){
			System.out.print(addc[j] + " ");
		}
		System.out.println(total);
	}
} import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int r = sc.nextInt();
		int c = sc.nextInt();
		int num = 0;
		int total = 0;
		int [] addc = new int[c];
		for (int i=0;i<r; i++){
			int addr = 0;
			for (int j=0; j<c; j++){
				num = sc.nextInt();
				System.out.print(num + " ");
				addr += num;
				addc[j] += num;
				total += num;
			}
			System.out.println(addr);
		}
		for (int j=0; j<c; j++){
			System.out.print(addc[j] + " ");
		}
		System.out.println(total);
	}
} Main public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int r = sc.nextInt();
		int c = sc.nextInt();
		int num = 0;
		int total = 0;
		int [] addc = new int[c];
		for (int i=0;i<r; i++){
			int addr = 0;
			for (int j=0; j<c; j++){
				num = sc.nextInt();
				System.out.print(num + " ");
				addr += num;
				addc[j] += num;
				total += num;
			}
			System.out.println(addr);
		}
		for (int j=0; j<c; j++){
			System.out.print(addc[j] + " ");
		}
		System.out.println(total);
	} main {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int r = sc.nextInt();
		int c = sc.nextInt();
		int num = 0;
		int total = 0;
		int [] addc = new int[c];
		for (int i=0;i<r; i++){
			int addr = 0;
			for (int j=0; j<c; j++){
				num = sc.nextInt();
				System.out.print(num + " ");
				addr += num;
				addc[j] += num;
				total += num;
			}
			System.out.println(addr);
		}
		for (int j=0; j<c; j++){
			System.out.print(addc[j] + " ");
		}
		System.out.println(total);
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int r = sc.nextInt(); r sc.nextInt() sc.nextInt sc int c = sc.nextInt(); c sc.nextInt() sc.nextInt sc int num = 0; num 0 int total = 0; total 0 int [] addc = new int[c]; addc new int[c] c for (int i=0;i<r; i++){
			int addr = 0;
			for (int j=0; j<c; j++){
				num = sc.nextInt();
				System.out.print(num + " ");
				addr += num;
				addc[j] += num;
				total += num;
			}
			System.out.println(addr);
		} int i=0; int i=0; i 0 i<r i r i++ i++ i {
			int addr = 0;
			for (int j=0; j<c; j++){
				num = sc.nextInt();
				System.out.print(num + " ");
				addr += num;
				addc[j] += num;
				total += num;
			}
			System.out.println(addr);
		} {
			int addr = 0;
			for (int j=0; j<c; j++){
				num = sc.nextInt();
				System.out.print(num + " ");
				addr += num;
				addc[j] += num;
				total += num;
			}
			System.out.println(addr);
		} int addr = 0; addr 0 for (int j=0; j<c; j++){
				num = sc.nextInt();
				System.out.print(num + " ");
				addr += num;
				addc[j] += num;
				total += num;
			} int j=0; int j=0; j 0 j<c j c j++ j++ j {
				num = sc.nextInt();
				System.out.print(num + " ");
				addr += num;
				addc[j] += num;
				total += num;
			} {
				num = sc.nextInt();
				System.out.print(num + " ");
				addr += num;
				addc[j] += num;
				total += num;
			} num = sc.nextInt() num sc.nextInt() sc.nextInt sc System.out.print(num + " ") System.out.print System.out System System.out num + " " num " " addr += num addr num addc[j] += num addc[j] addc j num total += num total num System.out.println(addr) System.out.println System.out System System.out addr for (int j=0; j<c; j++){
			System.out.print(addc[j] + " ");
		} int j=0; int j=0; j 0 j<c j c j++ j++ j {
			System.out.print(addc[j] + " ");
		} {
			System.out.print(addc[j] + " ");
		} System.out.print(addc[j] + " ") System.out.print System.out System System.out addc[j] + " " addc[j] addc j " " System.out.println(total) System.out.println System.out System System.out total String[] args args public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int r = sc.nextInt();
		int c = sc.nextInt();
		int num = 0;
		int total = 0;
		int [] addc = new int[c];
		for (int i=0;i<r; i++){
			int addr = 0;
			for (int j=0; j<c; j++){
				num = sc.nextInt();
				System.out.print(num + " ");
				addr += num;
				addc[j] += num;
				total += num;
			}
			System.out.println(addr);
		}
		for (int j=0; j<c; j++){
			System.out.print(addc[j] + " ");
		}
		System.out.println(total);
	}
} public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int r = sc.nextInt();
		int c = sc.nextInt();
		int num = 0;
		int total = 0;
		int [] addc = new int[c];
		for (int i=0;i<r; i++){
			int addr = 0;
			for (int j=0; j<c; j++){
				num = sc.nextInt();
				System.out.print(num + " ");
				addr += num;
				addc[j] += num;
				total += num;
			}
			System.out.println(addr);
		}
		for (int j=0; j<c; j++){
			System.out.print(addc[j] + " ");
		}
		System.out.println(total);
	}
} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int r = sc.nextInt();
		int c = sc.nextInt();
		int num = 0;
		int total = 0;
		int [] addc = new int[c];
		for (int i=0;i<r; i++){
			int addr = 0;
			for (int j=0; j<c; j++){
				num = sc.nextInt();
				System.out.print(num + " ");
				addr += num;
				addc[j] += num;
				total += num;
			}
			System.out.println(addr);
		}
		for (int j=0; j<c; j++){
			System.out.print(addc[j] + " ");
		}
		System.out.println(total);
	}
}