import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int retu = scanner.nextInt();
        int gyou = scanner.nextInt();
        int[][] shuturyoku = new int[(retu + 1)][(gyou + 1)];

        for (int i = 1; retu >= i; i++) {
            for (int j = 1; gyou >= j; j++) {
                int a = scanner.nextInt();
                shuturyoku[i - 1][j - 1] = a;
            }
        }
        for (int i = 1; retu >= i; i++) {
            for (int j = 1; gyou >= j; j++) {
                shuturyoku[i - 1][gyou] += shuturyoku[i - 1][j - 1];
            }
        }
        for (int i = 1; retu >= i; i++) {
            for (int j = 1; gyou >= j; j++) {
                shuturyoku[retu][j - 1] += shuturyoku[i - 1][j - 1];
            }
        }
        for (int i = 1; retu >= i; i++) {
            shuturyoku[retu][gyou] += shuturyoku[i-1][gyou];
        }
        for (int i = 1; retu + 1 >= i; i++) {
            for (int j = 1; gyou + 1 >= j; j++) {
                if (j != gyou+1) {
                    System.out.print(shuturyoku[i - 1][j - 1] + " ");
                } else {
                    System.out.println(shuturyoku[i - 1][j - 1]);
                }
            }
        }
    }
} import java.util.Scanner; Scanner java.util public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int retu = scanner.nextInt();
        int gyou = scanner.nextInt();
        int[][] shuturyoku = new int[(retu + 1)][(gyou + 1)];

        for (int i = 1; retu >= i; i++) {
            for (int j = 1; gyou >= j; j++) {
                int a = scanner.nextInt();
                shuturyoku[i - 1][j - 1] = a;
            }
        }
        for (int i = 1; retu >= i; i++) {
            for (int j = 1; gyou >= j; j++) {
                shuturyoku[i - 1][gyou] += shuturyoku[i - 1][j - 1];
            }
        }
        for (int i = 1; retu >= i; i++) {
            for (int j = 1; gyou >= j; j++) {
                shuturyoku[retu][j - 1] += shuturyoku[i - 1][j - 1];
            }
        }
        for (int i = 1; retu >= i; i++) {
            shuturyoku[retu][gyou] += shuturyoku[i-1][gyou];
        }
        for (int i = 1; retu + 1 >= i; i++) {
            for (int j = 1; gyou + 1 >= j; j++) {
                if (j != gyou+1) {
                    System.out.print(shuturyoku[i - 1][j - 1] + " ");
                } else {
                    System.out.println(shuturyoku[i - 1][j - 1]);
                }
            }
        }
    }
} Main public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int retu = scanner.nextInt();
        int gyou = scanner.nextInt();
        int[][] shuturyoku = new int[(retu + 1)][(gyou + 1)];

        for (int i = 1; retu >= i; i++) {
            for (int j = 1; gyou >= j; j++) {
                int a = scanner.nextInt();
                shuturyoku[i - 1][j - 1] = a;
            }
        }
        for (int i = 1; retu >= i; i++) {
            for (int j = 1; gyou >= j; j++) {
                shuturyoku[i - 1][gyou] += shuturyoku[i - 1][j - 1];
            }
        }
        for (int i = 1; retu >= i; i++) {
            for (int j = 1; gyou >= j; j++) {
                shuturyoku[retu][j - 1] += shuturyoku[i - 1][j - 1];
            }
        }
        for (int i = 1; retu >= i; i++) {
            shuturyoku[retu][gyou] += shuturyoku[i-1][gyou];
        }
        for (int i = 1; retu + 1 >= i; i++) {
            for (int j = 1; gyou + 1 >= j; j++) {
                if (j != gyou+1) {
                    System.out.print(shuturyoku[i - 1][j - 1] + " ");
                } else {
                    System.out.println(shuturyoku[i - 1][j - 1]);
                }
            }
        }
    } main {
        Scanner scanner = new Scanner(System.in);
        int retu = scanner.nextInt();
        int gyou = scanner.nextInt();
        int[][] shuturyoku = new int[(retu + 1)][(gyou + 1)];

        for (int i = 1; retu >= i; i++) {
            for (int j = 1; gyou >= j; j++) {
                int a = scanner.nextInt();
                shuturyoku[i - 1][j - 1] = a;
            }
        }
        for (int i = 1; retu >= i; i++) {
            for (int j = 1; gyou >= j; j++) {
                shuturyoku[i - 1][gyou] += shuturyoku[i - 1][j - 1];
            }
        }
        for (int i = 1; retu >= i; i++) {
            for (int j = 1; gyou >= j; j++) {
                shuturyoku[retu][j - 1] += shuturyoku[i - 1][j - 1];
            }
        }
        for (int i = 1; retu >= i; i++) {
            shuturyoku[retu][gyou] += shuturyoku[i-1][gyou];
        }
        for (int i = 1; retu + 1 >= i; i++) {
            for (int j = 1; gyou + 1 >= j; j++) {
                if (j != gyou+1) {
                    System.out.print(shuturyoku[i - 1][j - 1] + " ");
                } else {
                    System.out.println(shuturyoku[i - 1][j - 1]);
                }
            }
        }
    } Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) int retu = scanner.nextInt(); retu scanner.nextInt() scanner.nextInt scanner int gyou = scanner.nextInt(); gyou scanner.nextInt() scanner.nextInt scanner int[][] shuturyoku = new int[(retu + 1)][(gyou + 1)]; shuturyoku new int[(retu + 1)][(gyou + 1)] (retu + 1) retu 1 (gyou + 1) gyou 1 for (int i = 1; retu >= i; i++) {
            for (int j = 1; gyou >= j; j++) {
                int a = scanner.nextInt();
                shuturyoku[i - 1][j - 1] = a;
            }
        } int i = 1; int i = 1; i 1 retu >= i retu i i++ i++ i {
            for (int j = 1; gyou >= j; j++) {
                int a = scanner.nextInt();
                shuturyoku[i - 1][j - 1] = a;
            }
        } {
            for (int j = 1; gyou >= j; j++) {
                int a = scanner.nextInt();
                shuturyoku[i - 1][j - 1] = a;
            }
        } for (int j = 1; gyou >= j; j++) {
                int a = scanner.nextInt();
                shuturyoku[i - 1][j - 1] = a;
            } int j = 1; int j = 1; j 1 gyou >= j gyou j j++ j++ j {
                int a = scanner.nextInt();
                shuturyoku[i - 1][j - 1] = a;
            } {
                int a = scanner.nextInt();
                shuturyoku[i - 1][j - 1] = a;
            } int a = scanner.nextInt(); a scanner.nextInt() scanner.nextInt scanner shuturyoku[i - 1][j - 1] = a shuturyoku[i - 1][j - 1] shuturyoku[i - 1] shuturyoku i - 1 i 1 j - 1 j 1 a for (int i = 1; retu >= i; i++) {
            for (int j = 1; gyou >= j; j++) {
                shuturyoku[i - 1][gyou] += shuturyoku[i - 1][j - 1];
            }
        } int i = 1; int i = 1; i 1 retu >= i retu i i++ i++ i {
            for (int j = 1; gyou >= j; j++) {
                shuturyoku[i - 1][gyou] += shuturyoku[i - 1][j - 1];
            }
        } {
            for (int j = 1; gyou >= j; j++) {
                shuturyoku[i - 1][gyou] += shuturyoku[i - 1][j - 1];
            }
        } for (int j = 1; gyou >= j; j++) {
                shuturyoku[i - 1][gyou] += shuturyoku[i - 1][j - 1];
            } int j = 1; int j = 1; j 1 gyou >= j gyou j j++ j++ j {
                shuturyoku[i - 1][gyou] += shuturyoku[i - 1][j - 1];
            } {
                shuturyoku[i - 1][gyou] += shuturyoku[i - 1][j - 1];
            } shuturyoku[i - 1][gyou] += shuturyoku[i - 1][j - 1] shuturyoku[i - 1][gyou] shuturyoku[i - 1] shuturyoku i - 1 i 1 gyou shuturyoku[i - 1][j - 1] shuturyoku[i - 1] shuturyoku i - 1 i 1 j - 1 j 1 for (int i = 1; retu >= i; i++) {
            for (int j = 1; gyou >= j; j++) {
                shuturyoku[retu][j - 1] += shuturyoku[i - 1][j - 1];
            }
        } int i = 1; int i = 1; i 1 retu >= i retu i i++ i++ i {
            for (int j = 1; gyou >= j; j++) {
                shuturyoku[retu][j - 1] += shuturyoku[i - 1][j - 1];
            }
        } {
            for (int j = 1; gyou >= j; j++) {
                shuturyoku[retu][j - 1] += shuturyoku[i - 1][j - 1];
            }
        } for (int j = 1; gyou >= j; j++) {
                shuturyoku[retu][j - 1] += shuturyoku[i - 1][j - 1];
            } int j = 1; int j = 1; j 1 gyou >= j gyou j j++ j++ j {
                shuturyoku[retu][j - 1] += shuturyoku[i - 1][j - 1];
            } {
                shuturyoku[retu][j - 1] += shuturyoku[i - 1][j - 1];
            } shuturyoku[retu][j - 1] += shuturyoku[i - 1][j - 1] shuturyoku[retu][j - 1] shuturyoku[retu] shuturyoku retu j - 1 j 1 shuturyoku[i - 1][j - 1] shuturyoku[i - 1] shuturyoku i - 1 i 1 j - 1 j 1 for (int i = 1; retu >= i; i++) {
            shuturyoku[retu][gyou] += shuturyoku[i-1][gyou];
        } int i = 1; int i = 1; i 1 retu >= i retu i i++ i++ i {
            shuturyoku[retu][gyou] += shuturyoku[i-1][gyou];
        } {
            shuturyoku[retu][gyou] += shuturyoku[i-1][gyou];
        } shuturyoku[retu][gyou] += shuturyoku[i-1][gyou] shuturyoku[retu][gyou] shuturyoku[retu] shuturyoku retu gyou shuturyoku[i-1][gyou] shuturyoku[i-1] shuturyoku i-1 i 1 gyou for (int i = 1; retu + 1 >= i; i++) {
            for (int j = 1; gyou + 1 >= j; j++) {
                if (j != gyou+1) {
                    System.out.print(shuturyoku[i - 1][j - 1] + " ");
                } else {
                    System.out.println(shuturyoku[i - 1][j - 1]);
                }
            }
        } int i = 1; int i = 1; i 1 retu + 1 >= i retu + 1 retu 1 i i++ i++ i {
            for (int j = 1; gyou + 1 >= j; j++) {
                if (j != gyou+1) {
                    System.out.print(shuturyoku[i - 1][j - 1] + " ");
                } else {
                    System.out.println(shuturyoku[i - 1][j - 1]);
                }
            }
        } {
            for (int j = 1; gyou + 1 >= j; j++) {
                if (j != gyou+1) {
                    System.out.print(shuturyoku[i - 1][j - 1] + " ");
                } else {
                    System.out.println(shuturyoku[i - 1][j - 1]);
                }
            }
        } for (int j = 1; gyou + 1 >= j; j++) {
                if (j != gyou+1) {
                    System.out.print(shuturyoku[i - 1][j - 1] + " ");
                } else {
                    System.out.println(shuturyoku[i - 1][j - 1]);
                }
            } int j = 1; int j = 1; j 1 gyou + 1 >= j gyou + 1 gyou 1 j j++ j++ j {
                if (j != gyou+1) {
                    System.out.print(shuturyoku[i - 1][j - 1] + " ");
                } else {
                    System.out.println(shuturyoku[i - 1][j - 1]);
                }
            } {
                if (j != gyou+1) {
                    System.out.print(shuturyoku[i - 1][j - 1] + " ");
                } else {
                    System.out.println(shuturyoku[i - 1][j - 1]);
                }
            } if (j != gyou+1) {
                    System.out.print(shuturyoku[i - 1][j - 1] + " ");
                } else {
                    System.out.println(shuturyoku[i - 1][j - 1]);
                } j != gyou+1 j gyou+1 gyou 1 {
                    System.out.print(shuturyoku[i - 1][j - 1] + " ");
                } System.out.print(shuturyoku[i - 1][j - 1] + " ") System.out.print System.out System System.out shuturyoku[i - 1][j - 1] + " " shuturyoku[i - 1][j - 1] shuturyoku[i - 1] shuturyoku i - 1 i 1 j - 1 j 1 " " {
                    System.out.println(shuturyoku[i - 1][j - 1]);
                } System.out.println(shuturyoku[i - 1][j - 1]) System.out.println System.out System System.out shuturyoku[i - 1][j - 1] shuturyoku[i - 1] shuturyoku i - 1 i 1 j - 1 j 1 String[] args args public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int retu = scanner.nextInt();
        int gyou = scanner.nextInt();
        int[][] shuturyoku = new int[(retu + 1)][(gyou + 1)];

        for (int i = 1; retu >= i; i++) {
            for (int j = 1; gyou >= j; j++) {
                int a = scanner.nextInt();
                shuturyoku[i - 1][j - 1] = a;
            }
        }
        for (int i = 1; retu >= i; i++) {
            for (int j = 1; gyou >= j; j++) {
                shuturyoku[i - 1][gyou] += shuturyoku[i - 1][j - 1];
            }
        }
        for (int i = 1; retu >= i; i++) {
            for (int j = 1; gyou >= j; j++) {
                shuturyoku[retu][j - 1] += shuturyoku[i - 1][j - 1];
            }
        }
        for (int i = 1; retu >= i; i++) {
            shuturyoku[retu][gyou] += shuturyoku[i-1][gyou];
        }
        for (int i = 1; retu + 1 >= i; i++) {
            for (int j = 1; gyou + 1 >= j; j++) {
                if (j != gyou+1) {
                    System.out.print(shuturyoku[i - 1][j - 1] + " ");
                } else {
                    System.out.println(shuturyoku[i - 1][j - 1]);
                }
            }
        }
    }
} public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int retu = scanner.nextInt();
        int gyou = scanner.nextInt();
        int[][] shuturyoku = new int[(retu + 1)][(gyou + 1)];

        for (int i = 1; retu >= i; i++) {
            for (int j = 1; gyou >= j; j++) {
                int a = scanner.nextInt();
                shuturyoku[i - 1][j - 1] = a;
            }
        }
        for (int i = 1; retu >= i; i++) {
            for (int j = 1; gyou >= j; j++) {
                shuturyoku[i - 1][gyou] += shuturyoku[i - 1][j - 1];
            }
        }
        for (int i = 1; retu >= i; i++) {
            for (int j = 1; gyou >= j; j++) {
                shuturyoku[retu][j - 1] += shuturyoku[i - 1][j - 1];
            }
        }
        for (int i = 1; retu >= i; i++) {
            shuturyoku[retu][gyou] += shuturyoku[i-1][gyou];
        }
        for (int i = 1; retu + 1 >= i; i++) {
            for (int j = 1; gyou + 1 >= j; j++) {
                if (j != gyou+1) {
                    System.out.print(shuturyoku[i - 1][j - 1] + " ");
                } else {
                    System.out.println(shuturyoku[i - 1][j - 1]);
                }
            }
        }
    }
} Main
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int retu = scanner.nextInt();
        int gyou = scanner.nextInt();
        int[][] shuturyoku = new int[(retu + 1)][(gyou + 1)];

        for (int i = 1; retu >= i; i++) {
            for (int j = 1; gyou >= j; j++) {
                int a = scanner.nextInt();
                shuturyoku[i - 1][j - 1] = a;
            }
        }
        for (int i = 1; retu >= i; i++) {
            for (int j = 1; gyou >= j; j++) {
                shuturyoku[i - 1][gyou] += shuturyoku[i - 1][j - 1];
            }
        }
        for (int i = 1; retu >= i; i++) {
            for (int j = 1; gyou >= j; j++) {
                shuturyoku[retu][j - 1] += shuturyoku[i - 1][j - 1];
            }
        }
        for (int i = 1; retu >= i; i++) {
            shuturyoku[retu][gyou] += shuturyoku[i-1][gyou];
        }
        for (int i = 1; retu + 1 >= i; i++) {
            for (int j = 1; gyou + 1 >= j; j++) {
                if (j != gyou+1) {
                    System.out.print(shuturyoku[i - 1][j - 1] + " ");
                } else {
                    System.out.println(shuturyoku[i - 1][j - 1]);
                }
            }
        }
    }
}