import java.io.*;
import java.util.*;

public class Main {

	/**
	 * @param args
	 * @throws IOException 
	 */
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] input = br.readLine().split(" ");
		Integer height = Integer.parseInt(input[0]);
		Integer width = Integer.parseInt(input[1]);
		Integer[][] board = new Integer[height][width+1];

		for(int i = 0; i < height; i++){
			String line = br.readLine();
			System.out.print(line + " ");
			String[] numbers = line.split(" ");
			Integer total = 0;
			for(int j = 0; j < width; j++){
				Integer num = Integer.parseInt(numbers[j]);
				total += num;
				board[i][j] = num;
			}
			board[i][width] = total;
			System.out.print(total + "\n");
		}
		for(int i = 0; i <= width; i++){
			Integer result = 0;
			for(int j = 0; j < height; j++){
				result += board[j][i];
			}
			if(i == width){
				System.out.print(result + "\n");
			}
			else{
				System.out.print(result + " ");
			}
		}
	}
} import java.io.*; io.* java import java.util.*; util.* java public class Main {

	/**
	 * @param args
	 * @throws IOException 
	 */
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] input = br.readLine().split(" ");
		Integer height = Integer.parseInt(input[0]);
		Integer width = Integer.parseInt(input[1]);
		Integer[][] board = new Integer[height][width+1];

		for(int i = 0; i < height; i++){
			String line = br.readLine();
			System.out.print(line + " ");
			String[] numbers = line.split(" ");
			Integer total = 0;
			for(int j = 0; j < width; j++){
				Integer num = Integer.parseInt(numbers[j]);
				total += num;
				board[i][j] = num;
			}
			board[i][width] = total;
			System.out.print(total + "\n");
		}
		for(int i = 0; i <= width; i++){
			Integer result = 0;
			for(int j = 0; j < height; j++){
				result += board[j][i];
			}
			if(i == width){
				System.out.print(result + "\n");
			}
			else{
				System.out.print(result + " ");
			}
		}
	}
} Main /**
	 * @param args
	 * @throws IOException 
	 */
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] input = br.readLine().split(" ");
		Integer height = Integer.parseInt(input[0]);
		Integer width = Integer.parseInt(input[1]);
		Integer[][] board = new Integer[height][width+1];

		for(int i = 0; i < height; i++){
			String line = br.readLine();
			System.out.print(line + " ");
			String[] numbers = line.split(" ");
			Integer total = 0;
			for(int j = 0; j < width; j++){
				Integer num = Integer.parseInt(numbers[j]);
				total += num;
				board[i][j] = num;
			}
			board[i][width] = total;
			System.out.print(total + "\n");
		}
		for(int i = 0; i <= width; i++){
			Integer result = 0;
			for(int j = 0; j < height; j++){
				result += board[j][i];
			}
			if(i == width){
				System.out.print(result + "\n");
			}
			else{
				System.out.print(result + " ");
			}
		}
	} main {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] input = br.readLine().split(" ");
		Integer height = Integer.parseInt(input[0]);
		Integer width = Integer.parseInt(input[1]);
		Integer[][] board = new Integer[height][width+1];

		for(int i = 0; i < height; i++){
			String line = br.readLine();
			System.out.print(line + " ");
			String[] numbers = line.split(" ");
			Integer total = 0;
			for(int j = 0; j < width; j++){
				Integer num = Integer.parseInt(numbers[j]);
				total += num;
				board[i][j] = num;
			}
			board[i][width] = total;
			System.out.print(total + "\n");
		}
		for(int i = 0; i <= width; i++){
			Integer result = 0;
			for(int j = 0; j < height; j++){
				result += board[j][i];
			}
			if(i == width){
				System.out.print(result + "\n");
			}
			else{
				System.out.print(result + " ");
			}
		}
	} BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) String[] input = br.readLine().split(" "); input br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " Integer height = Integer.parseInt(input[0]); height Integer.parseInt(input[0]) Integer.parseInt Integer input[0] input 0 Integer width = Integer.parseInt(input[1]); width Integer.parseInt(input[1]) Integer.parseInt Integer input[1] input 1 Integer[][] board = new Integer[height][width+1]; board new Integer[height][width+1] height width+1 width 1 for(int i = 0; i < height; i++){
			String line = br.readLine();
			System.out.print(line + " ");
			String[] numbers = line.split(" ");
			Integer total = 0;
			for(int j = 0; j < width; j++){
				Integer num = Integer.parseInt(numbers[j]);
				total += num;
				board[i][j] = num;
			}
			board[i][width] = total;
			System.out.print(total + "\n");
		} int i = 0; int i = 0; i 0 i < height i height i++ i++ i {
			String line = br.readLine();
			System.out.print(line + " ");
			String[] numbers = line.split(" ");
			Integer total = 0;
			for(int j = 0; j < width; j++){
				Integer num = Integer.parseInt(numbers[j]);
				total += num;
				board[i][j] = num;
			}
			board[i][width] = total;
			System.out.print(total + "\n");
		} {
			String line = br.readLine();
			System.out.print(line + " ");
			String[] numbers = line.split(" ");
			Integer total = 0;
			for(int j = 0; j < width; j++){
				Integer num = Integer.parseInt(numbers[j]);
				total += num;
				board[i][j] = num;
			}
			board[i][width] = total;
			System.out.print(total + "\n");
		} String line = br.readLine(); line br.readLine() br.readLine br System.out.print(line + " ") System.out.print System.out System System.out line + " " line " " String[] numbers = line.split(" "); numbers line.split(" ") line.split line " " Integer total = 0; total 0 for(int j = 0; j < width; j++){
				Integer num = Integer.parseInt(numbers[j]);
				total += num;
				board[i][j] = num;
			} int j = 0; int j = 0; j 0 j < width j width j++ j++ j {
				Integer num = Integer.parseInt(numbers[j]);
				total += num;
				board[i][j] = num;
			} {
				Integer num = Integer.parseInt(numbers[j]);
				total += num;
				board[i][j] = num;
			} Integer num = Integer.parseInt(numbers[j]); num Integer.parseInt(numbers[j]) Integer.parseInt Integer numbers[j] numbers j total += num total num board[i][j] = num board[i][j] board[i] board i j num board[i][width] = total board[i][width] board[i] board i width total System.out.print(total + "\n") System.out.print System.out System System.out total + "\n" total "\n" for(int i = 0; i <= width; i++){
			Integer result = 0;
			for(int j = 0; j < height; j++){
				result += board[j][i];
			}
			if(i == width){
				System.out.print(result + "\n");
			}
			else{
				System.out.print(result + " ");
			}
		} int i = 0; int i = 0; i 0 i <= width i width i++ i++ i {
			Integer result = 0;
			for(int j = 0; j < height; j++){
				result += board[j][i];
			}
			if(i == width){
				System.out.print(result + "\n");
			}
			else{
				System.out.print(result + " ");
			}
		} {
			Integer result = 0;
			for(int j = 0; j < height; j++){
				result += board[j][i];
			}
			if(i == width){
				System.out.print(result + "\n");
			}
			else{
				System.out.print(result + " ");
			}
		} Integer result = 0; result 0 for(int j = 0; j < height; j++){
				result += board[j][i];
			} int j = 0; int j = 0; j 0 j < height j height j++ j++ j {
				result += board[j][i];
			} {
				result += board[j][i];
			} result += board[j][i] result board[j][i] board[j] board j i if(i == width){
				System.out.print(result + "\n");
			}
			else{
				System.out.print(result + " ");
			} i == width i width {
				System.out.print(result + "\n");
			} System.out.print(result + "\n") System.out.print System.out System System.out result + "\n" result "\n" {
				System.out.print(result + " ");
			} System.out.print(result + " ") System.out.print System.out System System.out result + " " result " " String[] args args public class Main {

	/**
	 * @param args
	 * @throws IOException 
	 */
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] input = br.readLine().split(" ");
		Integer height = Integer.parseInt(input[0]);
		Integer width = Integer.parseInt(input[1]);
		Integer[][] board = new Integer[height][width+1];

		for(int i = 0; i < height; i++){
			String line = br.readLine();
			System.out.print(line + " ");
			String[] numbers = line.split(" ");
			Integer total = 0;
			for(int j = 0; j < width; j++){
				Integer num = Integer.parseInt(numbers[j]);
				total += num;
				board[i][j] = num;
			}
			board[i][width] = total;
			System.out.print(total + "\n");
		}
		for(int i = 0; i <= width; i++){
			Integer result = 0;
			for(int j = 0; j < height; j++){
				result += board[j][i];
			}
			if(i == width){
				System.out.print(result + "\n");
			}
			else{
				System.out.print(result + " ");
			}
		}
	}
} public class Main {

	/**
	 * @param args
	 * @throws IOException 
	 */
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] input = br.readLine().split(" ");
		Integer height = Integer.parseInt(input[0]);
		Integer width = Integer.parseInt(input[1]);
		Integer[][] board = new Integer[height][width+1];

		for(int i = 0; i < height; i++){
			String line = br.readLine();
			System.out.print(line + " ");
			String[] numbers = line.split(" ");
			Integer total = 0;
			for(int j = 0; j < width; j++){
				Integer num = Integer.parseInt(numbers[j]);
				total += num;
				board[i][j] = num;
			}
			board[i][width] = total;
			System.out.print(total + "\n");
		}
		for(int i = 0; i <= width; i++){
			Integer result = 0;
			for(int j = 0; j < height; j++){
				result += board[j][i];
			}
			if(i == width){
				System.out.print(result + "\n");
			}
			else{
				System.out.print(result + " ");
			}
		}
	}
} Main
import java.io.*;
import java.util.*;

public class Main {

	/**
	 * @param args
	 * @throws IOException 
	 */
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] input = br.readLine().split(" ");
		Integer height = Integer.parseInt(input[0]);
		Integer width = Integer.parseInt(input[1]);
		Integer[][] board = new Integer[height][width+1];

		for(int i = 0; i < height; i++){
			String line = br.readLine();
			System.out.print(line + " ");
			String[] numbers = line.split(" ");
			Integer total = 0;
			for(int j = 0; j < width; j++){
				Integer num = Integer.parseInt(numbers[j]);
				total += num;
				board[i][j] = num;
			}
			board[i][width] = total;
			System.out.print(total + "\n");
		}
		for(int i = 0; i <= width; i++){
			Integer result = 0;
			for(int j = 0; j < height; j++){
				result += board[j][i];
			}
			if(i == width){
				System.out.print(result + "\n");
			}
			else{
				System.out.print(result + " ");
			}
		}
	}
}