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[] s = new int [r*c+1];
        int t, sum;
        for(int i = 0; i < r; i++)
        {
            sum = 0;
            for(int k = 0; k < c; k++)
            {
                t = sc.nextInt();
                sum += t;
                s[k] += t;
                System.out.print(t + " ");
            }
            s[c] += sum;
            System.out.println(sum);
        }
        for(int i = 0; i < c; i++){
            System.out.print(s[i] + " ");
        }
        System.out.println(s[c]);
    }

} 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[] s = new int [r*c+1];
        int t, sum;
        for(int i = 0; i < r; i++)
        {
            sum = 0;
            for(int k = 0; k < c; k++)
            {
                t = sc.nextInt();
                sum += t;
                s[k] += t;
                System.out.print(t + " ");
            }
            s[c] += sum;
            System.out.println(sum);
        }
        for(int i = 0; i < c; i++){
            System.out.print(s[i] + " ");
        }
        System.out.println(s[c]);
    }

} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int r = sc.nextInt();
        int c = sc.nextInt();
        int[] s = new int [r*c+1];
        int t, sum;
        for(int i = 0; i < r; i++)
        {
            sum = 0;
            for(int k = 0; k < c; k++)
            {
                t = sc.nextInt();
                sum += t;
                s[k] += t;
                System.out.print(t + " ");
            }
            s[c] += sum;
            System.out.println(sum);
        }
        for(int i = 0; i < c; i++){
            System.out.print(s[i] + " ");
        }
        System.out.println(s[c]);
    } main {
        Scanner sc = new Scanner(System.in);
        int r = sc.nextInt();
        int c = sc.nextInt();
        int[] s = new int [r*c+1];
        int t, sum;
        for(int i = 0; i < r; i++)
        {
            sum = 0;
            for(int k = 0; k < c; k++)
            {
                t = sc.nextInt();
                sum += t;
                s[k] += t;
                System.out.print(t + " ");
            }
            s[c] += sum;
            System.out.println(sum);
        }
        for(int i = 0; i < c; i++){
            System.out.print(s[i] + " ");
        }
        System.out.println(s[c]);
    } 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[] s = new int [r*c+1]; s new int [r*c+1] r*c+1 r*c r c 1 int t t sum; sum for(int i = 0; i < r; i++)
        {
            sum = 0;
            for(int k = 0; k < c; k++)
            {
                t = sc.nextInt();
                sum += t;
                s[k] += t;
                System.out.print(t + " ");
            }
            s[c] += sum;
            System.out.println(sum);
        } int i = 0; int i = 0; i 0 i < r i r i++ i++ i {
            sum = 0;
            for(int k = 0; k < c; k++)
            {
                t = sc.nextInt();
                sum += t;
                s[k] += t;
                System.out.print(t + " ");
            }
            s[c] += sum;
            System.out.println(sum);
        } {
            sum = 0;
            for(int k = 0; k < c; k++)
            {
                t = sc.nextInt();
                sum += t;
                s[k] += t;
                System.out.print(t + " ");
            }
            s[c] += sum;
            System.out.println(sum);
        } sum = 0 sum 0 for(int k = 0; k < c; k++)
            {
                t = sc.nextInt();
                sum += t;
                s[k] += t;
                System.out.print(t + " ");
            } int k = 0; int k = 0; k 0 k < c k c k++ k++ k {
                t = sc.nextInt();
                sum += t;
                s[k] += t;
                System.out.print(t + " ");
            } {
                t = sc.nextInt();
                sum += t;
                s[k] += t;
                System.out.print(t + " ");
            } t = sc.nextInt() t sc.nextInt() sc.nextInt sc sum += t sum t s[k] += t s[k] s k t System.out.print(t + " ") System.out.print System.out System System.out t + " " t " " s[c] += sum s[c] s c sum System.out.println(sum) System.out.println System.out System System.out sum for(int i = 0; i < c; i++){
            System.out.print(s[i] + " ");
        } int i = 0; int i = 0; i 0 i < c i c i++ i++ i {
            System.out.print(s[i] + " ");
        } {
            System.out.print(s[i] + " ");
        } System.out.print(s[i] + " ") System.out.print System.out System System.out s[i] + " " s[i] s i " " System.out.println(s[c]) System.out.println System.out System System.out s[c] s c 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[] s = new int [r*c+1];
        int t, sum;
        for(int i = 0; i < r; i++)
        {
            sum = 0;
            for(int k = 0; k < c; k++)
            {
                t = sc.nextInt();
                sum += t;
                s[k] += t;
                System.out.print(t + " ");
            }
            s[c] += sum;
            System.out.println(sum);
        }
        for(int i = 0; i < c; i++){
            System.out.print(s[i] + " ");
        }
        System.out.println(s[c]);
    }

} public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int r = sc.nextInt();
        int c = sc.nextInt();
        int[] s = new int [r*c+1];
        int t, sum;
        for(int i = 0; i < r; i++)
        {
            sum = 0;
            for(int k = 0; k < c; k++)
            {
                t = sc.nextInt();
                sum += t;
                s[k] += t;
                System.out.print(t + " ");
            }
            s[c] += sum;
            System.out.println(sum);
        }
        for(int i = 0; i < c; i++){
            System.out.print(s[i] + " ");
        }
        System.out.println(s[c]);
    }

} 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[] s = new int [r*c+1];
        int t, sum;
        for(int i = 0; i < r; i++)
        {
            sum = 0;
            for(int k = 0; k < c; k++)
            {
                t = sc.nextInt();
                sum += t;
                s[k] += t;
                System.out.print(t + " ");
            }
            s[c] += sum;
            System.out.println(sum);
        }
        for(int i = 0; i < c; i++){
            System.out.print(s[i] + " ");
        }
        System.out.println(s[c]);
    }

}