import java.io.PrintWriter;
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		int gyou = sc.nextInt();
		int retu = sc.nextInt();
		int gyouSum = 0;
		int retuSum = 0;
		int sum = 0;
		int map[][] = new int[gyou][retu];

		for(int i = 0; i < gyou; i++){
			for(int j = 0; j < retu; j++){
				map[i][j] = sc.nextInt();
			}
		}

		for(int i = 0; i < gyou; i++){
			gyouSum = 0;
			for(int j = 0; j < retu; j++){
				System.out.print(map[i][j] + " ");
				gyouSum += map[i][j];
			}
			System.out.println(gyouSum);
		}
		for(int j = 0; j < retu; j++){
			retuSum = 0;
			for(int i = 0; i < gyou; i++){
				retuSum += map[i][j];
			}
			System.out.print(retuSum + " ");
			sum += retuSum;
		}
		System.out.println(sum);


	}
} import java.io.PrintWriter; PrintWriter java.io import java.util.Scanner; Scanner java.util public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		int gyou = sc.nextInt();
		int retu = sc.nextInt();
		int gyouSum = 0;
		int retuSum = 0;
		int sum = 0;
		int map[][] = new int[gyou][retu];

		for(int i = 0; i < gyou; i++){
			for(int j = 0; j < retu; j++){
				map[i][j] = sc.nextInt();
			}
		}

		for(int i = 0; i < gyou; i++){
			gyouSum = 0;
			for(int j = 0; j < retu; j++){
				System.out.print(map[i][j] + " ");
				gyouSum += map[i][j];
			}
			System.out.println(gyouSum);
		}
		for(int j = 0; j < retu; j++){
			retuSum = 0;
			for(int i = 0; i < gyou; i++){
				retuSum += map[i][j];
			}
			System.out.print(retuSum + " ");
			sum += retuSum;
		}
		System.out.println(sum);


	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		int gyou = sc.nextInt();
		int retu = sc.nextInt();
		int gyouSum = 0;
		int retuSum = 0;
		int sum = 0;
		int map[][] = new int[gyou][retu];

		for(int i = 0; i < gyou; i++){
			for(int j = 0; j < retu; j++){
				map[i][j] = sc.nextInt();
			}
		}

		for(int i = 0; i < gyou; i++){
			gyouSum = 0;
			for(int j = 0; j < retu; j++){
				System.out.print(map[i][j] + " ");
				gyouSum += map[i][j];
			}
			System.out.println(gyouSum);
		}
		for(int j = 0; j < retu; j++){
			retuSum = 0;
			for(int i = 0; i < gyou; i++){
				retuSum += map[i][j];
			}
			System.out.print(retuSum + " ");
			sum += retuSum;
		}
		System.out.println(sum);


	} main {
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		int gyou = sc.nextInt();
		int retu = sc.nextInt();
		int gyouSum = 0;
		int retuSum = 0;
		int sum = 0;
		int map[][] = new int[gyou][retu];

		for(int i = 0; i < gyou; i++){
			for(int j = 0; j < retu; j++){
				map[i][j] = sc.nextInt();
			}
		}

		for(int i = 0; i < gyou; i++){
			gyouSum = 0;
			for(int j = 0; j < retu; j++){
				System.out.print(map[i][j] + " ");
				gyouSum += map[i][j];
			}
			System.out.println(gyouSum);
		}
		for(int j = 0; j < retu; j++){
			retuSum = 0;
			for(int i = 0; i < gyou; i++){
				retuSum += map[i][j];
			}
			System.out.print(retuSum + " ");
			sum += retuSum;
		}
		System.out.println(sum);


	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) PrintWriter out = new PrintWriter(System.out); out new PrintWriter(System.out) int gyou = sc.nextInt(); gyou sc.nextInt() sc.nextInt sc int retu = sc.nextInt(); retu sc.nextInt() sc.nextInt sc int gyouSum = 0; gyouSum 0 int retuSum = 0; retuSum 0 int sum = 0; sum 0 int map[][] = new int[gyou][retu]; map new int[gyou][retu] gyou retu for(int i = 0; i < gyou; i++){
			for(int j = 0; j < retu; j++){
				map[i][j] = sc.nextInt();
			}
		} int i = 0; int i = 0; i 0 i < gyou i gyou i++ i++ i {
			for(int j = 0; j < retu; j++){
				map[i][j] = sc.nextInt();
			}
		} {
			for(int j = 0; j < retu; j++){
				map[i][j] = sc.nextInt();
			}
		} for(int j = 0; j < retu; j++){
				map[i][j] = sc.nextInt();
			} int j = 0; int j = 0; j 0 j < retu j retu j++ j++ j {
				map[i][j] = sc.nextInt();
			} {
				map[i][j] = sc.nextInt();
			} map[i][j] = sc.nextInt() map[i][j] map[i] map i j sc.nextInt() sc.nextInt sc for(int i = 0; i < gyou; i++){
			gyouSum = 0;
			for(int j = 0; j < retu; j++){
				System.out.print(map[i][j] + " ");
				gyouSum += map[i][j];
			}
			System.out.println(gyouSum);
		} int i = 0; int i = 0; i 0 i < gyou i gyou i++ i++ i {
			gyouSum = 0;
			for(int j = 0; j < retu; j++){
				System.out.print(map[i][j] + " ");
				gyouSum += map[i][j];
			}
			System.out.println(gyouSum);
		} {
			gyouSum = 0;
			for(int j = 0; j < retu; j++){
				System.out.print(map[i][j] + " ");
				gyouSum += map[i][j];
			}
			System.out.println(gyouSum);
		} gyouSum = 0 gyouSum 0 for(int j = 0; j < retu; j++){
				System.out.print(map[i][j] + " ");
				gyouSum += map[i][j];
			} int j = 0; int j = 0; j 0 j < retu j retu j++ j++ j {
				System.out.print(map[i][j] + " ");
				gyouSum += map[i][j];
			} {
				System.out.print(map[i][j] + " ");
				gyouSum += map[i][j];
			} System.out.print(map[i][j] + " ") System.out.print System.out System System.out map[i][j] + " " map[i][j] map[i] map i j " " gyouSum += map[i][j] gyouSum map[i][j] map[i] map i j System.out.println(gyouSum) System.out.println System.out System System.out gyouSum for(int j = 0; j < retu; j++){
			retuSum = 0;
			for(int i = 0; i < gyou; i++){
				retuSum += map[i][j];
			}
			System.out.print(retuSum + " ");
			sum += retuSum;
		} int j = 0; int j = 0; j 0 j < retu j retu j++ j++ j {
			retuSum = 0;
			for(int i = 0; i < gyou; i++){
				retuSum += map[i][j];
			}
			System.out.print(retuSum + " ");
			sum += retuSum;
		} {
			retuSum = 0;
			for(int i = 0; i < gyou; i++){
				retuSum += map[i][j];
			}
			System.out.print(retuSum + " ");
			sum += retuSum;
		} retuSum = 0 retuSum 0 for(int i = 0; i < gyou; i++){
				retuSum += map[i][j];
			} int i = 0; int i = 0; i 0 i < gyou i gyou i++ i++ i {
				retuSum += map[i][j];
			} {
				retuSum += map[i][j];
			} retuSum += map[i][j] retuSum map[i][j] map[i] map i j System.out.print(retuSum + " ") System.out.print System.out System System.out retuSum + " " retuSum " " sum += retuSum sum retuSum System.out.println(sum) System.out.println System.out System System.out sum String[] args args public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		int gyou = sc.nextInt();
		int retu = sc.nextInt();
		int gyouSum = 0;
		int retuSum = 0;
		int sum = 0;
		int map[][] = new int[gyou][retu];

		for(int i = 0; i < gyou; i++){
			for(int j = 0; j < retu; j++){
				map[i][j] = sc.nextInt();
			}
		}

		for(int i = 0; i < gyou; i++){
			gyouSum = 0;
			for(int j = 0; j < retu; j++){
				System.out.print(map[i][j] + " ");
				gyouSum += map[i][j];
			}
			System.out.println(gyouSum);
		}
		for(int j = 0; j < retu; j++){
			retuSum = 0;
			for(int i = 0; i < gyou; i++){
				retuSum += map[i][j];
			}
			System.out.print(retuSum + " ");
			sum += retuSum;
		}
		System.out.println(sum);


	}
} public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		int gyou = sc.nextInt();
		int retu = sc.nextInt();
		int gyouSum = 0;
		int retuSum = 0;
		int sum = 0;
		int map[][] = new int[gyou][retu];

		for(int i = 0; i < gyou; i++){
			for(int j = 0; j < retu; j++){
				map[i][j] = sc.nextInt();
			}
		}

		for(int i = 0; i < gyou; i++){
			gyouSum = 0;
			for(int j = 0; j < retu; j++){
				System.out.print(map[i][j] + " ");
				gyouSum += map[i][j];
			}
			System.out.println(gyouSum);
		}
		for(int j = 0; j < retu; j++){
			retuSum = 0;
			for(int i = 0; i < gyou; i++){
				retuSum += map[i][j];
			}
			System.out.print(retuSum + " ");
			sum += retuSum;
		}
		System.out.println(sum);


	}
} Main
import java.io.PrintWriter;
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		int gyou = sc.nextInt();
		int retu = sc.nextInt();
		int gyouSum = 0;
		int retuSum = 0;
		int sum = 0;
		int map[][] = new int[gyou][retu];

		for(int i = 0; i < gyou; i++){
			for(int j = 0; j < retu; j++){
				map[i][j] = sc.nextInt();
			}
		}

		for(int i = 0; i < gyou; i++){
			gyouSum = 0;
			for(int j = 0; j < retu; j++){
				System.out.print(map[i][j] + " ");
				gyouSum += map[i][j];
			}
			System.out.println(gyouSum);
		}
		for(int j = 0; j < retu; j++){
			retuSum = 0;
			for(int i = 0; i < gyou; i++){
				retuSum += map[i][j];
			}
			System.out.print(retuSum + " ");
			sum += retuSum;
		}
		System.out.println(sum);


	}
}