import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int r = sc.nextInt();
		int c = sc.nextInt();
		int [][] cell = new int[r+1][c+1];
		int sum1 = 0;
		for(int i=0; i<r; i++) {
			for(int j=0; j<c; j++) {
				cell[i][j] = sc.nextInt();
			}
		}
		for(int i=0; i<r; i++) {
			for(int j=0; j<c; j++) {
				System.out.printf("%d ", cell[i][j]);
				sum1 += cell[i][j];
			}
			System.out.printf("%d\n", sum1);
			sum1 = 0;
		}
		int sum2 = 0;
		for(int i=0; i<c; i++) {
			for(int j=0; j<r; j++) {
				sum1 += cell[j][i];
			}
			sum2 += sum1;
			System.out.printf("%d ", sum1);
			sum1 = 0;
		}
		System.out.printf("%d\n",sum2);
	}
}
 import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int r = sc.nextInt();
		int c = sc.nextInt();
		int [][] cell = new int[r+1][c+1];
		int sum1 = 0;
		for(int i=0; i<r; i++) {
			for(int j=0; j<c; j++) {
				cell[i][j] = sc.nextInt();
			}
		}
		for(int i=0; i<r; i++) {
			for(int j=0; j<c; j++) {
				System.out.printf("%d ", cell[i][j]);
				sum1 += cell[i][j];
			}
			System.out.printf("%d\n", sum1);
			sum1 = 0;
		}
		int sum2 = 0;
		for(int i=0; i<c; i++) {
			for(int j=0; j<r; j++) {
				sum1 += cell[j][i];
			}
			sum2 += sum1;
			System.out.printf("%d ", sum1);
			sum1 = 0;
		}
		System.out.printf("%d\n",sum2);
	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int r = sc.nextInt();
		int c = sc.nextInt();
		int [][] cell = new int[r+1][c+1];
		int sum1 = 0;
		for(int i=0; i<r; i++) {
			for(int j=0; j<c; j++) {
				cell[i][j] = sc.nextInt();
			}
		}
		for(int i=0; i<r; i++) {
			for(int j=0; j<c; j++) {
				System.out.printf("%d ", cell[i][j]);
				sum1 += cell[i][j];
			}
			System.out.printf("%d\n", sum1);
			sum1 = 0;
		}
		int sum2 = 0;
		for(int i=0; i<c; i++) {
			for(int j=0; j<r; j++) {
				sum1 += cell[j][i];
			}
			sum2 += sum1;
			System.out.printf("%d ", sum1);
			sum1 = 0;
		}
		System.out.printf("%d\n",sum2);
	} main {
		Scanner sc = new Scanner(System.in);
		int r = sc.nextInt();
		int c = sc.nextInt();
		int [][] cell = new int[r+1][c+1];
		int sum1 = 0;
		for(int i=0; i<r; i++) {
			for(int j=0; j<c; j++) {
				cell[i][j] = sc.nextInt();
			}
		}
		for(int i=0; i<r; i++) {
			for(int j=0; j<c; j++) {
				System.out.printf("%d ", cell[i][j]);
				sum1 += cell[i][j];
			}
			System.out.printf("%d\n", sum1);
			sum1 = 0;
		}
		int sum2 = 0;
		for(int i=0; i<c; i++) {
			for(int j=0; j<r; j++) {
				sum1 += cell[j][i];
			}
			sum2 += sum1;
			System.out.printf("%d ", sum1);
			sum1 = 0;
		}
		System.out.printf("%d\n",sum2);
	} 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 [][] cell = new int[r+1][c+1]; cell new int[r+1][c+1] r+1 r 1 c+1 c 1 int sum1 = 0; sum1 0 for(int i=0; i<r; i++) {
			for(int j=0; j<c; j++) {
				cell[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++) {
				cell[i][j] = sc.nextInt();
			}
		} {
			for(int j=0; j<c; j++) {
				cell[i][j] = sc.nextInt();
			}
		} for(int j=0; j<c; j++) {
				cell[i][j] = sc.nextInt();
			} int j=0; int j=0; j 0 j<c j c j++ j++ j {
				cell[i][j] = sc.nextInt();
			} {
				cell[i][j] = sc.nextInt();
			} cell[i][j] = sc.nextInt() cell[i][j] cell[i] cell i j sc.nextInt() sc.nextInt sc for(int i=0; i<r; i++) {
			for(int j=0; j<c; j++) {
				System.out.printf("%d ", cell[i][j]);
				sum1 += cell[i][j];
			}
			System.out.printf("%d\n", sum1);
			sum1 = 0;
		} int i=0; int i=0; i 0 i<r i r i++ i++ i {
			for(int j=0; j<c; j++) {
				System.out.printf("%d ", cell[i][j]);
				sum1 += cell[i][j];
			}
			System.out.printf("%d\n", sum1);
			sum1 = 0;
		} {
			for(int j=0; j<c; j++) {
				System.out.printf("%d ", cell[i][j]);
				sum1 += cell[i][j];
			}
			System.out.printf("%d\n", sum1);
			sum1 = 0;
		} for(int j=0; j<c; j++) {
				System.out.printf("%d ", cell[i][j]);
				sum1 += cell[i][j];
			} int j=0; int j=0; j 0 j<c j c j++ j++ j {
				System.out.printf("%d ", cell[i][j]);
				sum1 += cell[i][j];
			} {
				System.out.printf("%d ", cell[i][j]);
				sum1 += cell[i][j];
			} System.out.printf("%d ", cell[i][j]) System.out.printf System.out System System.out "%d " cell[i][j] cell[i] cell i j sum1 += cell[i][j] sum1 cell[i][j] cell[i] cell i j System.out.printf("%d\n", sum1) System.out.printf System.out System System.out "%d\n" sum1 sum1 = 0 sum1 0 int sum2 = 0; sum2 0 for(int i=0; i<c; i++) {
			for(int j=0; j<r; j++) {
				sum1 += cell[j][i];
			}
			sum2 += sum1;
			System.out.printf("%d ", sum1);
			sum1 = 0;
		} int i=0; int i=0; i 0 i<c i c i++ i++ i {
			for(int j=0; j<r; j++) {
				sum1 += cell[j][i];
			}
			sum2 += sum1;
			System.out.printf("%d ", sum1);
			sum1 = 0;
		} {
			for(int j=0; j<r; j++) {
				sum1 += cell[j][i];
			}
			sum2 += sum1;
			System.out.printf("%d ", sum1);
			sum1 = 0;
		} for(int j=0; j<r; j++) {
				sum1 += cell[j][i];
			} int j=0; int j=0; j 0 j<r j r j++ j++ j {
				sum1 += cell[j][i];
			} {
				sum1 += cell[j][i];
			} sum1 += cell[j][i] sum1 cell[j][i] cell[j] cell j i sum2 += sum1 sum2 sum1 System.out.printf("%d ", sum1) System.out.printf System.out System System.out "%d " sum1 sum1 = 0 sum1 0 System.out.printf("%d\n",sum2) System.out.printf System.out System System.out "%d\n" sum2 String[] args args public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int r = sc.nextInt();
		int c = sc.nextInt();
		int [][] cell = new int[r+1][c+1];
		int sum1 = 0;
		for(int i=0; i<r; i++) {
			for(int j=0; j<c; j++) {
				cell[i][j] = sc.nextInt();
			}
		}
		for(int i=0; i<r; i++) {
			for(int j=0; j<c; j++) {
				System.out.printf("%d ", cell[i][j]);
				sum1 += cell[i][j];
			}
			System.out.printf("%d\n", sum1);
			sum1 = 0;
		}
		int sum2 = 0;
		for(int i=0; i<c; i++) {
			for(int j=0; j<r; j++) {
				sum1 += cell[j][i];
			}
			sum2 += sum1;
			System.out.printf("%d ", sum1);
			sum1 = 0;
		}
		System.out.printf("%d\n",sum2);
	}
} public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int r = sc.nextInt();
		int c = sc.nextInt();
		int [][] cell = new int[r+1][c+1];
		int sum1 = 0;
		for(int i=0; i<r; i++) {
			for(int j=0; j<c; j++) {
				cell[i][j] = sc.nextInt();
			}
		}
		for(int i=0; i<r; i++) {
			for(int j=0; j<c; j++) {
				System.out.printf("%d ", cell[i][j]);
				sum1 += cell[i][j];
			}
			System.out.printf("%d\n", sum1);
			sum1 = 0;
		}
		int sum2 = 0;
		for(int i=0; i<c; i++) {
			for(int j=0; j<r; j++) {
				sum1 += cell[j][i];
			}
			sum2 += sum1;
			System.out.printf("%d ", sum1);
			sum1 = 0;
		}
		System.out.printf("%d\n",sum2);
	}
} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int r = sc.nextInt();
		int c = sc.nextInt();
		int [][] cell = new int[r+1][c+1];
		int sum1 = 0;
		for(int i=0; i<r; i++) {
			for(int j=0; j<c; j++) {
				cell[i][j] = sc.nextInt();
			}
		}
		for(int i=0; i<r; i++) {
			for(int j=0; j<c; j++) {
				System.out.printf("%d ", cell[i][j]);
				sum1 += cell[i][j];
			}
			System.out.printf("%d\n", sum1);
			sum1 = 0;
		}
		int sum2 = 0;
		for(int i=0; i<c; i++) {
			for(int j=0; j<r; j++) {
				sum1 += cell[j][i];
			}
			sum2 += sum1;
			System.out.printf("%d ", sum1);
			sum1 = 0;
		}
		System.out.printf("%d\n",sum2);
	}
}

