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

public class Main {

    public static void main(String args[]) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        String[] st = br.readLine().split(" ");
        int n = Integer.parseInt(st[0]);
        int m = Integer.parseInt(st[1]);
        int[][] arr = new int[n + 1][m + 1];
        for (int i = 0; i < n; i++) {
            st = br.readLine().split(" ");
            for (int j = 0; j < m; j++) {
                int now = Integer.parseInt(st[j]);
                arr[i][j] = now;
                arr[i][m] += now;
                arr[n][j] += now;
                arr[n][m] += now;
            }
        }

        for (int i = 0; i <= n; i++) {
            bw.append("" + arr[i][0]);
            for (int j = 1; j <= m; j++) {
                bw.append(" " + arr[i][j]);
            }
            bw.newLine();
        }
        bw.flush();
    }


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

    public static void main(String args[]) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        String[] st = br.readLine().split(" ");
        int n = Integer.parseInt(st[0]);
        int m = Integer.parseInt(st[1]);
        int[][] arr = new int[n + 1][m + 1];
        for (int i = 0; i < n; i++) {
            st = br.readLine().split(" ");
            for (int j = 0; j < m; j++) {
                int now = Integer.parseInt(st[j]);
                arr[i][j] = now;
                arr[i][m] += now;
                arr[n][j] += now;
                arr[n][m] += now;
            }
        }

        for (int i = 0; i <= n; i++) {
            bw.append("" + arr[i][0]);
            for (int j = 1; j <= m; j++) {
                bw.append(" " + arr[i][j]);
            }
            bw.newLine();
        }
        bw.flush();
    }


} Main public static void main(String args[]) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        String[] st = br.readLine().split(" ");
        int n = Integer.parseInt(st[0]);
        int m = Integer.parseInt(st[1]);
        int[][] arr = new int[n + 1][m + 1];
        for (int i = 0; i < n; i++) {
            st = br.readLine().split(" ");
            for (int j = 0; j < m; j++) {
                int now = Integer.parseInt(st[j]);
                arr[i][j] = now;
                arr[i][m] += now;
                arr[n][j] += now;
                arr[n][m] += now;
            }
        }

        for (int i = 0; i <= n; i++) {
            bw.append("" + arr[i][0]);
            for (int j = 1; j <= m; j++) {
                bw.append(" " + arr[i][j]);
            }
            bw.newLine();
        }
        bw.flush();
    } main {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        String[] st = br.readLine().split(" ");
        int n = Integer.parseInt(st[0]);
        int m = Integer.parseInt(st[1]);
        int[][] arr = new int[n + 1][m + 1];
        for (int i = 0; i < n; i++) {
            st = br.readLine().split(" ");
            for (int j = 0; j < m; j++) {
                int now = Integer.parseInt(st[j]);
                arr[i][j] = now;
                arr[i][m] += now;
                arr[n][j] += now;
                arr[n][m] += now;
            }
        }

        for (int i = 0; i <= n; i++) {
            bw.append("" + arr[i][0]);
            for (int j = 1; j <= m; j++) {
                bw.append(" " + arr[i][j]);
            }
            bw.newLine();
        }
        bw.flush();
    } BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); bw new BufferedWriter(new OutputStreamWriter(System.out)) String[] st = br.readLine().split(" "); st br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " int n = Integer.parseInt(st[0]); n Integer.parseInt(st[0]) Integer.parseInt Integer st[0] st 0 int m = Integer.parseInt(st[1]); m Integer.parseInt(st[1]) Integer.parseInt Integer st[1] st 1 int[][] arr = new int[n + 1][m + 1]; arr new int[n + 1][m + 1] n + 1 n 1 m + 1 m 1 for (int i = 0; i < n; i++) {
            st = br.readLine().split(" ");
            for (int j = 0; j < m; j++) {
                int now = Integer.parseInt(st[j]);
                arr[i][j] = now;
                arr[i][m] += now;
                arr[n][j] += now;
                arr[n][m] += now;
            }
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            st = br.readLine().split(" ");
            for (int j = 0; j < m; j++) {
                int now = Integer.parseInt(st[j]);
                arr[i][j] = now;
                arr[i][m] += now;
                arr[n][j] += now;
                arr[n][m] += now;
            }
        } {
            st = br.readLine().split(" ");
            for (int j = 0; j < m; j++) {
                int now = Integer.parseInt(st[j]);
                arr[i][j] = now;
                arr[i][m] += now;
                arr[n][j] += now;
                arr[n][m] += now;
            }
        } st = br.readLine().split(" ") st br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " for (int j = 0; j < m; j++) {
                int now = Integer.parseInt(st[j]);
                arr[i][j] = now;
                arr[i][m] += now;
                arr[n][j] += now;
                arr[n][m] += now;
            } int j = 0; int j = 0; j 0 j < m j m j++ j++ j {
                int now = Integer.parseInt(st[j]);
                arr[i][j] = now;
                arr[i][m] += now;
                arr[n][j] += now;
                arr[n][m] += now;
            } {
                int now = Integer.parseInt(st[j]);
                arr[i][j] = now;
                arr[i][m] += now;
                arr[n][j] += now;
                arr[n][m] += now;
            } int now = Integer.parseInt(st[j]); now Integer.parseInt(st[j]) Integer.parseInt Integer st[j] st j arr[i][j] = now arr[i][j] arr[i] arr i j now arr[i][m] += now arr[i][m] arr[i] arr i m now arr[n][j] += now arr[n][j] arr[n] arr n j now arr[n][m] += now arr[n][m] arr[n] arr n m now for (int i = 0; i <= n; i++) {
            bw.append("" + arr[i][0]);
            for (int j = 1; j <= m; j++) {
                bw.append(" " + arr[i][j]);
            }
            bw.newLine();
        } int i = 0; int i = 0; i 0 i <= n i n i++ i++ i {
            bw.append("" + arr[i][0]);
            for (int j = 1; j <= m; j++) {
                bw.append(" " + arr[i][j]);
            }
            bw.newLine();
        } {
            bw.append("" + arr[i][0]);
            for (int j = 1; j <= m; j++) {
                bw.append(" " + arr[i][j]);
            }
            bw.newLine();
        } bw.append("" + arr[i][0]) bw.append bw "" + arr[i][0] "" arr[i][0] arr[i] arr i 0 for (int j = 1; j <= m; j++) {
                bw.append(" " + arr[i][j]);
            } int j = 1; int j = 1; j 1 j <= m j m j++ j++ j {
                bw.append(" " + arr[i][j]);
            } {
                bw.append(" " + arr[i][j]);
            } bw.append(" " + arr[i][j]) bw.append bw " " + arr[i][j] " " arr[i][j] arr[i] arr i j bw.newLine() bw.newLine bw bw.flush() bw.flush bw String args[] args public class Main {

    public static void main(String args[]) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        String[] st = br.readLine().split(" ");
        int n = Integer.parseInt(st[0]);
        int m = Integer.parseInt(st[1]);
        int[][] arr = new int[n + 1][m + 1];
        for (int i = 0; i < n; i++) {
            st = br.readLine().split(" ");
            for (int j = 0; j < m; j++) {
                int now = Integer.parseInt(st[j]);
                arr[i][j] = now;
                arr[i][m] += now;
                arr[n][j] += now;
                arr[n][m] += now;
            }
        }

        for (int i = 0; i <= n; i++) {
            bw.append("" + arr[i][0]);
            for (int j = 1; j <= m; j++) {
                bw.append(" " + arr[i][j]);
            }
            bw.newLine();
        }
        bw.flush();
    }


} public class Main {

    public static void main(String args[]) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        String[] st = br.readLine().split(" ");
        int n = Integer.parseInt(st[0]);
        int m = Integer.parseInt(st[1]);
        int[][] arr = new int[n + 1][m + 1];
        for (int i = 0; i < n; i++) {
            st = br.readLine().split(" ");
            for (int j = 0; j < m; j++) {
                int now = Integer.parseInt(st[j]);
                arr[i][j] = now;
                arr[i][m] += now;
                arr[n][j] += now;
                arr[n][m] += now;
            }
        }

        for (int i = 0; i <= n; i++) {
            bw.append("" + arr[i][0]);
            for (int j = 1; j <= m; j++) {
                bw.append(" " + arr[i][j]);
            }
            bw.newLine();
        }
        bw.flush();
    }


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

public class Main {

    public static void main(String args[]) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        String[] st = br.readLine().split(" ");
        int n = Integer.parseInt(st[0]);
        int m = Integer.parseInt(st[1]);
        int[][] arr = new int[n + 1][m + 1];
        for (int i = 0; i < n; i++) {
            st = br.readLine().split(" ");
            for (int j = 0; j < m; j++) {
                int now = Integer.parseInt(st[j]);
                arr[i][j] = now;
                arr[i][m] += now;
                arr[n][j] += now;
                arr[n][m] += now;
            }
        }

        for (int i = 0; i <= n; i++) {
            bw.append("" + arr[i][0]);
            for (int j = 1; j <= m; j++) {
                bw.append(" " + arr[i][j]);
            }
            bw.newLine();
        }
        bw.flush();
    }


}
