import java.util.Scanner;

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

		Scanner sc = new Scanner(System.in);
		String line = sc.nextLine();
		String[] k = line.split(" ");
		int[] v = new int[2];
		v[0] = Integer.parseInt(k[0]);
		v[1] = Integer.parseInt(k[1]);
		int[] tatesum = new int[v[1] + 1];
		for (int i = 0; i < v[0]; i++) {
			String linek = sc.nextLine();
			String[] suuzi = linek.split(" ");
			int[] kazu = new int[v[1]];
			for (int j = 0; j < kazu.length; j++) {
				kazu[j] = Integer.parseInt(suuzi[j]);
			}
			int sum = 0;
			for (int j = 0; j < kazu.length; j++) {
				sum += kazu[j];
			}
			for (int j = 0; j < kazu.length; j++) {
				tatesum[j] += kazu[j];
			}
			System.out.println(linek + " " + sum);
			tatesum[v[1] ] += sum;
		}
		for (int i = 0; i < tatesum.length - 1; i++) {
			System.out.print(tatesum[i] + " ");
		}
		System.out.println(tatesum[v[1] ]);

	}
} import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] arges) {

		Scanner sc = new Scanner(System.in);
		String line = sc.nextLine();
		String[] k = line.split(" ");
		int[] v = new int[2];
		v[0] = Integer.parseInt(k[0]);
		v[1] = Integer.parseInt(k[1]);
		int[] tatesum = new int[v[1] + 1];
		for (int i = 0; i < v[0]; i++) {
			String linek = sc.nextLine();
			String[] suuzi = linek.split(" ");
			int[] kazu = new int[v[1]];
			for (int j = 0; j < kazu.length; j++) {
				kazu[j] = Integer.parseInt(suuzi[j]);
			}
			int sum = 0;
			for (int j = 0; j < kazu.length; j++) {
				sum += kazu[j];
			}
			for (int j = 0; j < kazu.length; j++) {
				tatesum[j] += kazu[j];
			}
			System.out.println(linek + " " + sum);
			tatesum[v[1] ] += sum;
		}
		for (int i = 0; i < tatesum.length - 1; i++) {
			System.out.print(tatesum[i] + " ");
		}
		System.out.println(tatesum[v[1] ]);

	}
} Main public static void main(String[] arges) {

		Scanner sc = new Scanner(System.in);
		String line = sc.nextLine();
		String[] k = line.split(" ");
		int[] v = new int[2];
		v[0] = Integer.parseInt(k[0]);
		v[1] = Integer.parseInt(k[1]);
		int[] tatesum = new int[v[1] + 1];
		for (int i = 0; i < v[0]; i++) {
			String linek = sc.nextLine();
			String[] suuzi = linek.split(" ");
			int[] kazu = new int[v[1]];
			for (int j = 0; j < kazu.length; j++) {
				kazu[j] = Integer.parseInt(suuzi[j]);
			}
			int sum = 0;
			for (int j = 0; j < kazu.length; j++) {
				sum += kazu[j];
			}
			for (int j = 0; j < kazu.length; j++) {
				tatesum[j] += kazu[j];
			}
			System.out.println(linek + " " + sum);
			tatesum[v[1] ] += sum;
		}
		for (int i = 0; i < tatesum.length - 1; i++) {
			System.out.print(tatesum[i] + " ");
		}
		System.out.println(tatesum[v[1] ]);

	} main {

		Scanner sc = new Scanner(System.in);
		String line = sc.nextLine();
		String[] k = line.split(" ");
		int[] v = new int[2];
		v[0] = Integer.parseInt(k[0]);
		v[1] = Integer.parseInt(k[1]);
		int[] tatesum = new int[v[1] + 1];
		for (int i = 0; i < v[0]; i++) {
			String linek = sc.nextLine();
			String[] suuzi = linek.split(" ");
			int[] kazu = new int[v[1]];
			for (int j = 0; j < kazu.length; j++) {
				kazu[j] = Integer.parseInt(suuzi[j]);
			}
			int sum = 0;
			for (int j = 0; j < kazu.length; j++) {
				sum += kazu[j];
			}
			for (int j = 0; j < kazu.length; j++) {
				tatesum[j] += kazu[j];
			}
			System.out.println(linek + " " + sum);
			tatesum[v[1] ] += sum;
		}
		for (int i = 0; i < tatesum.length - 1; i++) {
			System.out.print(tatesum[i] + " ");
		}
		System.out.println(tatesum[v[1] ]);

	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) String line = sc.nextLine(); line sc.nextLine() sc.nextLine sc String[] k = line.split(" "); k line.split(" ") line.split line " " int[] v = new int[2]; v new int[2] 2 v[0] = Integer.parseInt(k[0]) v[0] v 0 Integer.parseInt(k[0]) Integer.parseInt Integer k[0] k 0 v[1] = Integer.parseInt(k[1]) v[1] v 1 Integer.parseInt(k[1]) Integer.parseInt Integer k[1] k 1 int[] tatesum = new int[v[1] + 1]; tatesum new int[v[1] + 1] v[1] + 1 v[1] v 1 1 for (int i = 0; i < v[0]; i++) {
			String linek = sc.nextLine();
			String[] suuzi = linek.split(" ");
			int[] kazu = new int[v[1]];
			for (int j = 0; j < kazu.length; j++) {
				kazu[j] = Integer.parseInt(suuzi[j]);
			}
			int sum = 0;
			for (int j = 0; j < kazu.length; j++) {
				sum += kazu[j];
			}
			for (int j = 0; j < kazu.length; j++) {
				tatesum[j] += kazu[j];
			}
			System.out.println(linek + " " + sum);
			tatesum[v[1] ] += sum;
		} int i = 0; int i = 0; i 0 i < v[0] i v[0] v 0 i++ i++ i {
			String linek = sc.nextLine();
			String[] suuzi = linek.split(" ");
			int[] kazu = new int[v[1]];
			for (int j = 0; j < kazu.length; j++) {
				kazu[j] = Integer.parseInt(suuzi[j]);
			}
			int sum = 0;
			for (int j = 0; j < kazu.length; j++) {
				sum += kazu[j];
			}
			for (int j = 0; j < kazu.length; j++) {
				tatesum[j] += kazu[j];
			}
			System.out.println(linek + " " + sum);
			tatesum[v[1] ] += sum;
		} {
			String linek = sc.nextLine();
			String[] suuzi = linek.split(" ");
			int[] kazu = new int[v[1]];
			for (int j = 0; j < kazu.length; j++) {
				kazu[j] = Integer.parseInt(suuzi[j]);
			}
			int sum = 0;
			for (int j = 0; j < kazu.length; j++) {
				sum += kazu[j];
			}
			for (int j = 0; j < kazu.length; j++) {
				tatesum[j] += kazu[j];
			}
			System.out.println(linek + " " + sum);
			tatesum[v[1] ] += sum;
		} String linek = sc.nextLine(); linek sc.nextLine() sc.nextLine sc String[] suuzi = linek.split(" "); suuzi linek.split(" ") linek.split linek " " int[] kazu = new int[v[1]]; kazu new int[v[1]] v[1] v 1 for (int j = 0; j < kazu.length; j++) {
				kazu[j] = Integer.parseInt(suuzi[j]);
			} int j = 0; int j = 0; j 0 j < kazu.length j kazu.length kazu kazu.length j++ j++ j {
				kazu[j] = Integer.parseInt(suuzi[j]);
			} {
				kazu[j] = Integer.parseInt(suuzi[j]);
			} kazu[j] = Integer.parseInt(suuzi[j]) kazu[j] kazu j Integer.parseInt(suuzi[j]) Integer.parseInt Integer suuzi[j] suuzi j int sum = 0; sum 0 for (int j = 0; j < kazu.length; j++) {
				sum += kazu[j];
			} int j = 0; int j = 0; j 0 j < kazu.length j kazu.length kazu kazu.length j++ j++ j {
				sum += kazu[j];
			} {
				sum += kazu[j];
			} sum += kazu[j] sum kazu[j] kazu j for (int j = 0; j < kazu.length; j++) {
				tatesum[j] += kazu[j];
			} int j = 0; int j = 0; j 0 j < kazu.length j kazu.length kazu kazu.length j++ j++ j {
				tatesum[j] += kazu[j];
			} {
				tatesum[j] += kazu[j];
			} tatesum[j] += kazu[j] tatesum[j] tatesum j kazu[j] kazu j System.out.println(linek + " " + sum) System.out.println System.out System System.out linek + " " + sum linek + " " + sum linek " " sum tatesum[v[1] ] += sum tatesum[v[1] ] tatesum v[1] v 1 sum for (int i = 0; i < tatesum.length - 1; i++) {
			System.out.print(tatesum[i] + " ");
		} int i = 0; int i = 0; i 0 i < tatesum.length - 1 i tatesum.length - 1 tatesum.length tatesum tatesum.length 1 i++ i++ i {
			System.out.print(tatesum[i] + " ");
		} {
			System.out.print(tatesum[i] + " ");
		} System.out.print(tatesum[i] + " ") System.out.print System.out System System.out tatesum[i] + " " tatesum[i] tatesum i " " System.out.println(tatesum[v[1] ]) System.out.println System.out System System.out tatesum[v[1] ] tatesum v[1] v 1 String[] arges arges public class Main {
	public static void main(String[] arges) {

		Scanner sc = new Scanner(System.in);
		String line = sc.nextLine();
		String[] k = line.split(" ");
		int[] v = new int[2];
		v[0] = Integer.parseInt(k[0]);
		v[1] = Integer.parseInt(k[1]);
		int[] tatesum = new int[v[1] + 1];
		for (int i = 0; i < v[0]; i++) {
			String linek = sc.nextLine();
			String[] suuzi = linek.split(" ");
			int[] kazu = new int[v[1]];
			for (int j = 0; j < kazu.length; j++) {
				kazu[j] = Integer.parseInt(suuzi[j]);
			}
			int sum = 0;
			for (int j = 0; j < kazu.length; j++) {
				sum += kazu[j];
			}
			for (int j = 0; j < kazu.length; j++) {
				tatesum[j] += kazu[j];
			}
			System.out.println(linek + " " + sum);
			tatesum[v[1] ] += sum;
		}
		for (int i = 0; i < tatesum.length - 1; i++) {
			System.out.print(tatesum[i] + " ");
		}
		System.out.println(tatesum[v[1] ]);

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

		Scanner sc = new Scanner(System.in);
		String line = sc.nextLine();
		String[] k = line.split(" ");
		int[] v = new int[2];
		v[0] = Integer.parseInt(k[0]);
		v[1] = Integer.parseInt(k[1]);
		int[] tatesum = new int[v[1] + 1];
		for (int i = 0; i < v[0]; i++) {
			String linek = sc.nextLine();
			String[] suuzi = linek.split(" ");
			int[] kazu = new int[v[1]];
			for (int j = 0; j < kazu.length; j++) {
				kazu[j] = Integer.parseInt(suuzi[j]);
			}
			int sum = 0;
			for (int j = 0; j < kazu.length; j++) {
				sum += kazu[j];
			}
			for (int j = 0; j < kazu.length; j++) {
				tatesum[j] += kazu[j];
			}
			System.out.println(linek + " " + sum);
			tatesum[v[1] ] += sum;
		}
		for (int i = 0; i < tatesum.length - 1; i++) {
			System.out.print(tatesum[i] + " ");
		}
		System.out.println(tatesum[v[1] ]);

	}
} Main
import java.util.Scanner;

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

		Scanner sc = new Scanner(System.in);
		String line = sc.nextLine();
		String[] k = line.split(" ");
		int[] v = new int[2];
		v[0] = Integer.parseInt(k[0]);
		v[1] = Integer.parseInt(k[1]);
		int[] tatesum = new int[v[1] + 1];
		for (int i = 0; i < v[0]; i++) {
			String linek = sc.nextLine();
			String[] suuzi = linek.split(" ");
			int[] kazu = new int[v[1]];
			for (int j = 0; j < kazu.length; j++) {
				kazu[j] = Integer.parseInt(suuzi[j]);
			}
			int sum = 0;
			for (int j = 0; j < kazu.length; j++) {
				sum += kazu[j];
			}
			for (int j = 0; j < kazu.length; j++) {
				tatesum[j] += kazu[j];
			}
			System.out.println(linek + " " + sum);
			tatesum[v[1] ] += sum;
		}
		for (int i = 0; i < tatesum.length - 1; i++) {
			System.out.print(tatesum[i] + " ");
		}
		System.out.println(tatesum[v[1] ]);

	}
}