import java.util.Scanner;

public class Main {

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

} 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(),c = sc.nextInt(),sum;
        int[][] a = new int[c][r];
        for(int i = 0;i < r;++i){
            for(int j = 0;j < c;++j) a[j][i] = sc.nextInt();
        }
        int[] b = new int[c];
        for(int i = 0;i < r;++i){
            sum = a[0][i];
            b[0] += a[0][i];
            System.out.print(a[0][i]);
            for(int j = 1;j < c;++j){
                int v = a[j][i];
                sum += v;
                b[j] += v;
                System.out.printf(" %d",v);
            }
            System.out.printf(" %d\n",sum);
        }
        sum = b[0];
        System.out.print(b[0]);
        for(int i = 1;i < c;++i){
            sum += b[i];
            System.out.printf(" %d",b[i]);
        }
        System.out.printf(" %d\n",sum);
    }

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

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

} public class Main {

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

} Main
import java.util.Scanner;

public class Main {

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

}