import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;
public class Main {
    public static void main(String[] args) throws Exception {
         Scanner sc = new Scanner(System.in);
         int row = sc.nextInt();//row
         int col = sc.nextInt();//col
         int[] sum_v = new int[col];
         int sum_h = 0;
         int sum = 0;
         for(int i=0;i<row;i++){
            for(int j=0;j<col;j++){
                int tmp = sc.nextInt();
                sum_v[j] += tmp;
                sum += tmp;
                System.out.print(tmp + " ");
            }
            sum_h += sum;
            System.out.println(sum);
            sum=0;
         }
         for(int i=0;i<col;i++){
            System.out.print(sum_v[i] + " ");
         }
         System.out.println(sum_h);
    }
} import java.io.BufferedReader; BufferedReader java.io import java.io.InputStreamReader; InputStreamReader java.io import java.util.*; util.* java public class Main {
    public static void main(String[] args) throws Exception {
         Scanner sc = new Scanner(System.in);
         int row = sc.nextInt();//row
         int col = sc.nextInt();//col
         int[] sum_v = new int[col];
         int sum_h = 0;
         int sum = 0;
         for(int i=0;i<row;i++){
            for(int j=0;j<col;j++){
                int tmp = sc.nextInt();
                sum_v[j] += tmp;
                sum += tmp;
                System.out.print(tmp + " ");
            }
            sum_h += sum;
            System.out.println(sum);
            sum=0;
         }
         for(int i=0;i<col;i++){
            System.out.print(sum_v[i] + " ");
         }
         System.out.println(sum_h);
    }
} Main public static void main(String[] args) throws Exception {
         Scanner sc = new Scanner(System.in);
         int row = sc.nextInt();//row
         int col = sc.nextInt();//col
         int[] sum_v = new int[col];
         int sum_h = 0;
         int sum = 0;
         for(int i=0;i<row;i++){
            for(int j=0;j<col;j++){
                int tmp = sc.nextInt();
                sum_v[j] += tmp;
                sum += tmp;
                System.out.print(tmp + " ");
            }
            sum_h += sum;
            System.out.println(sum);
            sum=0;
         }
         for(int i=0;i<col;i++){
            System.out.print(sum_v[i] + " ");
         }
         System.out.println(sum_h);
    } main {
         Scanner sc = new Scanner(System.in);
         int row = sc.nextInt();//row
         int col = sc.nextInt();//col
         int[] sum_v = new int[col];
         int sum_h = 0;
         int sum = 0;
         for(int i=0;i<row;i++){
            for(int j=0;j<col;j++){
                int tmp = sc.nextInt();
                sum_v[j] += tmp;
                sum += tmp;
                System.out.print(tmp + " ");
            }
            sum_h += sum;
            System.out.println(sum);
            sum=0;
         }
         for(int i=0;i<col;i++){
            System.out.print(sum_v[i] + " ");
         }
         System.out.println(sum_h);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int row = sc.nextInt(); row sc.nextInt() sc.nextInt sc int col = sc.nextInt(); col sc.nextInt() sc.nextInt sc int[] sum_v = new int[col]; sum_v new int[col] col int sum_h = 0; sum_h 0 int sum = 0; sum 0 for(int i=0;i<row;i++){
            for(int j=0;j<col;j++){
                int tmp = sc.nextInt();
                sum_v[j] += tmp;
                sum += tmp;
                System.out.print(tmp + " ");
            }
            sum_h += sum;
            System.out.println(sum);
            sum=0;
         } int i=0; int i=0; i 0 i<row i row i++ i++ i {
            for(int j=0;j<col;j++){
                int tmp = sc.nextInt();
                sum_v[j] += tmp;
                sum += tmp;
                System.out.print(tmp + " ");
            }
            sum_h += sum;
            System.out.println(sum);
            sum=0;
         } {
            for(int j=0;j<col;j++){
                int tmp = sc.nextInt();
                sum_v[j] += tmp;
                sum += tmp;
                System.out.print(tmp + " ");
            }
            sum_h += sum;
            System.out.println(sum);
            sum=0;
         } for(int j=0;j<col;j++){
                int tmp = sc.nextInt();
                sum_v[j] += tmp;
                sum += tmp;
                System.out.print(tmp + " ");
            } int j=0; int j=0; j 0 j<col j col j++ j++ j {
                int tmp = sc.nextInt();
                sum_v[j] += tmp;
                sum += tmp;
                System.out.print(tmp + " ");
            } {
                int tmp = sc.nextInt();
                sum_v[j] += tmp;
                sum += tmp;
                System.out.print(tmp + " ");
            } int tmp = sc.nextInt(); tmp sc.nextInt() sc.nextInt sc sum_v[j] += tmp sum_v[j] sum_v j tmp sum += tmp sum tmp System.out.print(tmp + " ") System.out.print System.out System System.out tmp + " " tmp " " sum_h += sum sum_h sum System.out.println(sum) System.out.println System.out System System.out sum sum=0 sum 0 for(int i=0;i<col;i++){
            System.out.print(sum_v[i] + " ");
         } int i=0; int i=0; i 0 i<col i col i++ i++ i {
            System.out.print(sum_v[i] + " ");
         } {
            System.out.print(sum_v[i] + " ");
         } System.out.print(sum_v[i] + " ") System.out.print System.out System System.out sum_v[i] + " " sum_v[i] sum_v i " " System.out.println(sum_h) System.out.println System.out System System.out sum_h String[] args args public class Main {
    public static void main(String[] args) throws Exception {
         Scanner sc = new Scanner(System.in);
         int row = sc.nextInt();//row
         int col = sc.nextInt();//col
         int[] sum_v = new int[col];
         int sum_h = 0;
         int sum = 0;
         for(int i=0;i<row;i++){
            for(int j=0;j<col;j++){
                int tmp = sc.nextInt();
                sum_v[j] += tmp;
                sum += tmp;
                System.out.print(tmp + " ");
            }
            sum_h += sum;
            System.out.println(sum);
            sum=0;
         }
         for(int i=0;i<col;i++){
            System.out.print(sum_v[i] + " ");
         }
         System.out.println(sum_h);
    }
} public class Main {
    public static void main(String[] args) throws Exception {
         Scanner sc = new Scanner(System.in);
         int row = sc.nextInt();//row
         int col = sc.nextInt();//col
         int[] sum_v = new int[col];
         int sum_h = 0;
         int sum = 0;
         for(int i=0;i<row;i++){
            for(int j=0;j<col;j++){
                int tmp = sc.nextInt();
                sum_v[j] += tmp;
                sum += tmp;
                System.out.print(tmp + " ");
            }
            sum_h += sum;
            System.out.println(sum);
            sum=0;
         }
         for(int i=0;i<col;i++){
            System.out.print(sum_v[i] + " ");
         }
         System.out.println(sum_h);
    }
} Main
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;
public class Main {
    public static void main(String[] args) throws Exception {
         Scanner sc = new Scanner(System.in);
         int row = sc.nextInt();//row
         int col = sc.nextInt();//col
         int[] sum_v = new int[col];
         int sum_h = 0;
         int sum = 0;
         for(int i=0;i<row;i++){
            for(int j=0;j<col;j++){
                int tmp = sc.nextInt();
                sum_v[j] += tmp;
                sum += tmp;
                System.out.print(tmp + " ");
            }
            sum_h += sum;
            System.out.println(sum);
            sum=0;
         }
         for(int i=0;i<col;i++){
            System.out.print(sum_v[i] + " ");
         }
         System.out.println(sum_h);
    }
}