import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] lines = br.readLine().split(" ");
        int n = Integer.parseInt(lines[0]);
        int m = Integer.parseInt(lines[1]);
        int[] rowSum = new int[m];
        for (int i = 0; i < n; i++) {
            lines = br.readLine().split(" ");
            int columnSum=0;
            for (int j = 0; j < m; j++) {
                 int e= Integer.parseInt(lines[j]);
                 columnSum+=e;
                 rowSum[j]+=e;
                 System.out.print(e+" ");
            }
            System.out.println(columnSum);
        }
        int totalSum=0;
        for(int i=0;i<m;i++){
            totalSum+=rowSum[i];
            System.out.print(rowSum[i]+" ");
        }
        System.out.println(totalSum);

    }
} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] lines = br.readLine().split(" ");
        int n = Integer.parseInt(lines[0]);
        int m = Integer.parseInt(lines[1]);
        int[] rowSum = new int[m];
        for (int i = 0; i < n; i++) {
            lines = br.readLine().split(" ");
            int columnSum=0;
            for (int j = 0; j < m; j++) {
                 int e= Integer.parseInt(lines[j]);
                 columnSum+=e;
                 rowSum[j]+=e;
                 System.out.print(e+" ");
            }
            System.out.println(columnSum);
        }
        int totalSum=0;
        for(int i=0;i<m;i++){
            totalSum+=rowSum[i];
            System.out.print(rowSum[i]+" ");
        }
        System.out.println(totalSum);

    }
} Main public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] lines = br.readLine().split(" ");
        int n = Integer.parseInt(lines[0]);
        int m = Integer.parseInt(lines[1]);
        int[] rowSum = new int[m];
        for (int i = 0; i < n; i++) {
            lines = br.readLine().split(" ");
            int columnSum=0;
            for (int j = 0; j < m; j++) {
                 int e= Integer.parseInt(lines[j]);
                 columnSum+=e;
                 rowSum[j]+=e;
                 System.out.print(e+" ");
            }
            System.out.println(columnSum);
        }
        int totalSum=0;
        for(int i=0;i<m;i++){
            totalSum+=rowSum[i];
            System.out.print(rowSum[i]+" ");
        }
        System.out.println(totalSum);

    } main {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] lines = br.readLine().split(" ");
        int n = Integer.parseInt(lines[0]);
        int m = Integer.parseInt(lines[1]);
        int[] rowSum = new int[m];
        for (int i = 0; i < n; i++) {
            lines = br.readLine().split(" ");
            int columnSum=0;
            for (int j = 0; j < m; j++) {
                 int e= Integer.parseInt(lines[j]);
                 columnSum+=e;
                 rowSum[j]+=e;
                 System.out.print(e+" ");
            }
            System.out.println(columnSum);
        }
        int totalSum=0;
        for(int i=0;i<m;i++){
            totalSum+=rowSum[i];
            System.out.print(rowSum[i]+" ");
        }
        System.out.println(totalSum);

    } BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) String[] lines = br.readLine().split(" "); lines br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " int n = Integer.parseInt(lines[0]); n Integer.parseInt(lines[0]) Integer.parseInt Integer lines[0] lines 0 int m = Integer.parseInt(lines[1]); m Integer.parseInt(lines[1]) Integer.parseInt Integer lines[1] lines 1 int[] rowSum = new int[m]; rowSum new int[m] m for (int i = 0; i < n; i++) {
            lines = br.readLine().split(" ");
            int columnSum=0;
            for (int j = 0; j < m; j++) {
                 int e= Integer.parseInt(lines[j]);
                 columnSum+=e;
                 rowSum[j]+=e;
                 System.out.print(e+" ");
            }
            System.out.println(columnSum);
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            lines = br.readLine().split(" ");
            int columnSum=0;
            for (int j = 0; j < m; j++) {
                 int e= Integer.parseInt(lines[j]);
                 columnSum+=e;
                 rowSum[j]+=e;
                 System.out.print(e+" ");
            }
            System.out.println(columnSum);
        } {
            lines = br.readLine().split(" ");
            int columnSum=0;
            for (int j = 0; j < m; j++) {
                 int e= Integer.parseInt(lines[j]);
                 columnSum+=e;
                 rowSum[j]+=e;
                 System.out.print(e+" ");
            }
            System.out.println(columnSum);
        } lines = br.readLine().split(" ") lines br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " int columnSum=0; columnSum 0 for (int j = 0; j < m; j++) {
                 int e= Integer.parseInt(lines[j]);
                 columnSum+=e;
                 rowSum[j]+=e;
                 System.out.print(e+" ");
            } int j = 0; int j = 0; j 0 j < m j m j++ j++ j {
                 int e= Integer.parseInt(lines[j]);
                 columnSum+=e;
                 rowSum[j]+=e;
                 System.out.print(e+" ");
            } {
                 int e= Integer.parseInt(lines[j]);
                 columnSum+=e;
                 rowSum[j]+=e;
                 System.out.print(e+" ");
            } int e= Integer.parseInt(lines[j]); e Integer.parseInt(lines[j]) Integer.parseInt Integer lines[j] lines j columnSum+=e columnSum e rowSum[j]+=e rowSum[j] rowSum j e System.out.print(e+" ") System.out.print System.out System System.out e+" " e " " System.out.println(columnSum) System.out.println System.out System System.out columnSum int totalSum=0; totalSum 0 for(int i=0;i<m;i++){
            totalSum+=rowSum[i];
            System.out.print(rowSum[i]+" ");
        } int i=0; int i=0; i 0 i<m i m i++ i++ i {
            totalSum+=rowSum[i];
            System.out.print(rowSum[i]+" ");
        } {
            totalSum+=rowSum[i];
            System.out.print(rowSum[i]+" ");
        } totalSum+=rowSum[i] totalSum rowSum[i] rowSum i System.out.print(rowSum[i]+" ") System.out.print System.out System System.out rowSum[i]+" " rowSum[i] rowSum i " " System.out.println(totalSum) System.out.println System.out System System.out totalSum String[] args args public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] lines = br.readLine().split(" ");
        int n = Integer.parseInt(lines[0]);
        int m = Integer.parseInt(lines[1]);
        int[] rowSum = new int[m];
        for (int i = 0; i < n; i++) {
            lines = br.readLine().split(" ");
            int columnSum=0;
            for (int j = 0; j < m; j++) {
                 int e= Integer.parseInt(lines[j]);
                 columnSum+=e;
                 rowSum[j]+=e;
                 System.out.print(e+" ");
            }
            System.out.println(columnSum);
        }
        int totalSum=0;
        for(int i=0;i<m;i++){
            totalSum+=rowSum[i];
            System.out.print(rowSum[i]+" ");
        }
        System.out.println(totalSum);

    }
} public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] lines = br.readLine().split(" ");
        int n = Integer.parseInt(lines[0]);
        int m = Integer.parseInt(lines[1]);
        int[] rowSum = new int[m];
        for (int i = 0; i < n; i++) {
            lines = br.readLine().split(" ");
            int columnSum=0;
            for (int j = 0; j < m; j++) {
                 int e= Integer.parseInt(lines[j]);
                 columnSum+=e;
                 rowSum[j]+=e;
                 System.out.print(e+" ");
            }
            System.out.println(columnSum);
        }
        int totalSum=0;
        for(int i=0;i<m;i++){
            totalSum+=rowSum[i];
            System.out.print(rowSum[i]+" ");
        }
        System.out.println(totalSum);

    }
} Main
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] lines = br.readLine().split(" ");
        int n = Integer.parseInt(lines[0]);
        int m = Integer.parseInt(lines[1]);
        int[] rowSum = new int[m];
        for (int i = 0; i < n; i++) {
            lines = br.readLine().split(" ");
            int columnSum=0;
            for (int j = 0; j < m; j++) {
                 int e= Integer.parseInt(lines[j]);
                 columnSum+=e;
                 rowSum[j]+=e;
                 System.out.print(e+" ");
            }
            System.out.println(columnSum);
        }
        int totalSum=0;
        for(int i=0;i<m;i++){
            totalSum+=rowSum[i];
            System.out.print(rowSum[i]+" ");
        }
        System.out.println(totalSum);

    }
}