import java.io.IOException;
import java.util.Scanner;
 
class Main {
 
    public static void main(String[] args) throws IOException {
 
        Scanner scanner = new Scanner(System.in);
 
        int r = scanner.nextInt();
        int c = scanner.nextInt();
        int[][] list = new int[r][c];
        int[] sumR = new int[r];
        int[] sumC = new int[c];
        int sumRC = 0;
 
        for (int i = 0; i < list.length; i++) {
            for (int j = 0; j < list[0].length; j++) {
                list[i][j] = scanner.nextInt();
            }
        }
 
        for (int i = 0; i < list.length; i++) {
            for (int j = 0; j < list[0].length; j++) {
                sumR[i] += list[i][j];
            }
        }
         
        for (int i = 0; i < list[0].length; i++) {
            for (int j = 0; j < list.length; j++) {
                sumC[i] += list[j][i];
            }
            sumRC += sumC[i];
        }
 
        for (int i = 0; i < list.length; i++) {
            for (int j = 0; j < list[0].length; j++) {
                System.out.print(list[i][j] + " ");
            }
            System.out.println(sumR[i] + "");
        }
         
        for (int num : sumC) {
            System.out.print(num + " ");
        }
        System.out.print(sumRC + "\n");
    }
} import java.io.IOException; IOException java.io import java.util.Scanner; Scanner java.util class Main {
 
    public static void main(String[] args) throws IOException {
 
        Scanner scanner = new Scanner(System.in);
 
        int r = scanner.nextInt();
        int c = scanner.nextInt();
        int[][] list = new int[r][c];
        int[] sumR = new int[r];
        int[] sumC = new int[c];
        int sumRC = 0;
 
        for (int i = 0; i < list.length; i++) {
            for (int j = 0; j < list[0].length; j++) {
                list[i][j] = scanner.nextInt();
            }
        }
 
        for (int i = 0; i < list.length; i++) {
            for (int j = 0; j < list[0].length; j++) {
                sumR[i] += list[i][j];
            }
        }
         
        for (int i = 0; i < list[0].length; i++) {
            for (int j = 0; j < list.length; j++) {
                sumC[i] += list[j][i];
            }
            sumRC += sumC[i];
        }
 
        for (int i = 0; i < list.length; i++) {
            for (int j = 0; j < list[0].length; j++) {
                System.out.print(list[i][j] + " ");
            }
            System.out.println(sumR[i] + "");
        }
         
        for (int num : sumC) {
            System.out.print(num + " ");
        }
        System.out.print(sumRC + "\n");
    }
} Main public static void main(String[] args) throws IOException {
 
        Scanner scanner = new Scanner(System.in);
 
        int r = scanner.nextInt();
        int c = scanner.nextInt();
        int[][] list = new int[r][c];
        int[] sumR = new int[r];
        int[] sumC = new int[c];
        int sumRC = 0;
 
        for (int i = 0; i < list.length; i++) {
            for (int j = 0; j < list[0].length; j++) {
                list[i][j] = scanner.nextInt();
            }
        }
 
        for (int i = 0; i < list.length; i++) {
            for (int j = 0; j < list[0].length; j++) {
                sumR[i] += list[i][j];
            }
        }
         
        for (int i = 0; i < list[0].length; i++) {
            for (int j = 0; j < list.length; j++) {
                sumC[i] += list[j][i];
            }
            sumRC += sumC[i];
        }
 
        for (int i = 0; i < list.length; i++) {
            for (int j = 0; j < list[0].length; j++) {
                System.out.print(list[i][j] + " ");
            }
            System.out.println(sumR[i] + "");
        }
         
        for (int num : sumC) {
            System.out.print(num + " ");
        }
        System.out.print(sumRC + "\n");
    } main {
 
        Scanner scanner = new Scanner(System.in);
 
        int r = scanner.nextInt();
        int c = scanner.nextInt();
        int[][] list = new int[r][c];
        int[] sumR = new int[r];
        int[] sumC = new int[c];
        int sumRC = 0;
 
        for (int i = 0; i < list.length; i++) {
            for (int j = 0; j < list[0].length; j++) {
                list[i][j] = scanner.nextInt();
            }
        }
 
        for (int i = 0; i < list.length; i++) {
            for (int j = 0; j < list[0].length; j++) {
                sumR[i] += list[i][j];
            }
        }
         
        for (int i = 0; i < list[0].length; i++) {
            for (int j = 0; j < list.length; j++) {
                sumC[i] += list[j][i];
            }
            sumRC += sumC[i];
        }
 
        for (int i = 0; i < list.length; i++) {
            for (int j = 0; j < list[0].length; j++) {
                System.out.print(list[i][j] + " ");
            }
            System.out.println(sumR[i] + "");
        }
         
        for (int num : sumC) {
            System.out.print(num + " ");
        }
        System.out.print(sumRC + "\n");
    } Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) int r = scanner.nextInt(); r scanner.nextInt() scanner.nextInt scanner int c = scanner.nextInt(); c scanner.nextInt() scanner.nextInt scanner int[][] list = new int[r][c]; list new int[r][c] r c int[] sumR = new int[r]; sumR new int[r] r int[] sumC = new int[c]; sumC new int[c] c int sumRC = 0; sumRC 0 for (int i = 0; i < list.length; i++) {
            for (int j = 0; j < list[0].length; j++) {
                list[i][j] = scanner.nextInt();
            }
        } int i = 0; int i = 0; i 0 i < list.length i list.length list list.length i++ i++ i {
            for (int j = 0; j < list[0].length; j++) {
                list[i][j] = scanner.nextInt();
            }
        } {
            for (int j = 0; j < list[0].length; j++) {
                list[i][j] = scanner.nextInt();
            }
        } for (int j = 0; j < list[0].length; j++) {
                list[i][j] = scanner.nextInt();
            } int j = 0; int j = 0; j 0 j < list[0].length j list[0].length list[0] list 0 list[0].length j++ j++ j {
                list[i][j] = scanner.nextInt();
            } {
                list[i][j] = scanner.nextInt();
            } list[i][j] = scanner.nextInt() list[i][j] list[i] list i j scanner.nextInt() scanner.nextInt scanner for (int i = 0; i < list.length; i++) {
            for (int j = 0; j < list[0].length; j++) {
                sumR[i] += list[i][j];
            }
        } int i = 0; int i = 0; i 0 i < list.length i list.length list list.length i++ i++ i {
            for (int j = 0; j < list[0].length; j++) {
                sumR[i] += list[i][j];
            }
        } {
            for (int j = 0; j < list[0].length; j++) {
                sumR[i] += list[i][j];
            }
        } for (int j = 0; j < list[0].length; j++) {
                sumR[i] += list[i][j];
            } int j = 0; int j = 0; j 0 j < list[0].length j list[0].length list[0] list 0 list[0].length j++ j++ j {
                sumR[i] += list[i][j];
            } {
                sumR[i] += list[i][j];
            } sumR[i] += list[i][j] sumR[i] sumR i list[i][j] list[i] list i j for (int i = 0; i < list[0].length; i++) {
            for (int j = 0; j < list.length; j++) {
                sumC[i] += list[j][i];
            }
            sumRC += sumC[i];
        } int i = 0; int i = 0; i 0 i < list[0].length i list[0].length list[0] list 0 list[0].length i++ i++ i {
            for (int j = 0; j < list.length; j++) {
                sumC[i] += list[j][i];
            }
            sumRC += sumC[i];
        } {
            for (int j = 0; j < list.length; j++) {
                sumC[i] += list[j][i];
            }
            sumRC += sumC[i];
        } for (int j = 0; j < list.length; j++) {
                sumC[i] += list[j][i];
            } int j = 0; int j = 0; j 0 j < list.length j list.length list list.length j++ j++ j {
                sumC[i] += list[j][i];
            } {
                sumC[i] += list[j][i];
            } sumC[i] += list[j][i] sumC[i] sumC i list[j][i] list[j] list j i sumRC += sumC[i] sumRC sumC[i] sumC i for (int i = 0; i < list.length; i++) {
            for (int j = 0; j < list[0].length; j++) {
                System.out.print(list[i][j] + " ");
            }
            System.out.println(sumR[i] + "");
        } int i = 0; int i = 0; i 0 i < list.length i list.length list list.length i++ i++ i {
            for (int j = 0; j < list[0].length; j++) {
                System.out.print(list[i][j] + " ");
            }
            System.out.println(sumR[i] + "");
        } {
            for (int j = 0; j < list[0].length; j++) {
                System.out.print(list[i][j] + " ");
            }
            System.out.println(sumR[i] + "");
        } for (int j = 0; j < list[0].length; j++) {
                System.out.print(list[i][j] + " ");
            } int j = 0; int j = 0; j 0 j < list[0].length j list[0].length list[0] list 0 list[0].length j++ j++ j {
                System.out.print(list[i][j] + " ");
            } {
                System.out.print(list[i][j] + " ");
            } System.out.print(list[i][j] + " ") System.out.print System.out System System.out list[i][j] + " " list[i][j] list[i] list i j " " System.out.println(sumR[i] + "") System.out.println System.out System System.out sumR[i] + "" sumR[i] sumR i "" for (int num : sumC) {
            System.out.print(num + " ");
        } int num sumC {
            System.out.print(num + " ");
        } {
            System.out.print(num + " ");
        } System.out.print(num + " ") System.out.print System.out System System.out num + " " num " " System.out.print(sumRC + "\n") System.out.print System.out System System.out sumRC + "\n" sumRC "\n" String[] args args
import java.io.IOException;
import java.util.Scanner;
 
class Main {
 
    public static void main(String[] args) throws IOException {
 
        Scanner scanner = new Scanner(System.in);
 
        int r = scanner.nextInt();
        int c = scanner.nextInt();
        int[][] list = new int[r][c];
        int[] sumR = new int[r];
        int[] sumC = new int[c];
        int sumRC = 0;
 
        for (int i = 0; i < list.length; i++) {
            for (int j = 0; j < list[0].length; j++) {
                list[i][j] = scanner.nextInt();
            }
        }
 
        for (int i = 0; i < list.length; i++) {
            for (int j = 0; j < list[0].length; j++) {
                sumR[i] += list[i][j];
            }
        }
         
        for (int i = 0; i < list[0].length; i++) {
            for (int j = 0; j < list.length; j++) {
                sumC[i] += list[j][i];
            }
            sumRC += sumC[i];
        }
 
        for (int i = 0; i < list.length; i++) {
            for (int j = 0; j < list[0].length; j++) {
                System.out.print(list[i][j] + " ");
            }
            System.out.println(sumR[i] + "");
        }
         
        for (int num : sumC) {
            System.out.print(num + " ");
        }
        System.out.print(sumRC + "\n");
    }
}