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 ary[][] = new int[r + 1][c + 1];

        for (int i = 0; i < r; i++) {
            for (int j = 0; j < c; j++) {
                ary[i][j] = Integer.valueOf(sc.next());
            }
        }

        for (int i = 0; i < r; i++) {
            for (int j = 0; j < c; j++) {
                ary[i][c] += ary[i][j];
            }
        }
        for (int i = 0; i <= c; i++) {
            for (int j = 0; j < r; j++) {
                ary[r][i] += ary[j][i];
            }
        }

        for (int i = 0; i <= r; i++) {
            for (int j = 0; j < c; j++) {
                System.out.print(ary[i][j]+" ");
                
            }
            System.out.println(ary[i][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 ary[][] = new int[r + 1][c + 1];

        for (int i = 0; i < r; i++) {
            for (int j = 0; j < c; j++) {
                ary[i][j] = Integer.valueOf(sc.next());
            }
        }

        for (int i = 0; i < r; i++) {
            for (int j = 0; j < c; j++) {
                ary[i][c] += ary[i][j];
            }
        }
        for (int i = 0; i <= c; i++) {
            for (int j = 0; j < r; j++) {
                ary[r][i] += ary[j][i];
            }
        }

        for (int i = 0; i <= r; i++) {
            for (int j = 0; j < c; j++) {
                System.out.print(ary[i][j]+" ");
                
            }
            System.out.println(ary[i][c]);
        }
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int r = sc.nextInt();
        int c = sc.nextInt();

        int ary[][] = new int[r + 1][c + 1];

        for (int i = 0; i < r; i++) {
            for (int j = 0; j < c; j++) {
                ary[i][j] = Integer.valueOf(sc.next());
            }
        }

        for (int i = 0; i < r; i++) {
            for (int j = 0; j < c; j++) {
                ary[i][c] += ary[i][j];
            }
        }
        for (int i = 0; i <= c; i++) {
            for (int j = 0; j < r; j++) {
                ary[r][i] += ary[j][i];
            }
        }

        for (int i = 0; i <= r; i++) {
            for (int j = 0; j < c; j++) {
                System.out.print(ary[i][j]+" ");
                
            }
            System.out.println(ary[i][c]);
        }
    } main {
        Scanner sc = new Scanner(System.in);

        int r = sc.nextInt();
        int c = sc.nextInt();

        int ary[][] = new int[r + 1][c + 1];

        for (int i = 0; i < r; i++) {
            for (int j = 0; j < c; j++) {
                ary[i][j] = Integer.valueOf(sc.next());
            }
        }

        for (int i = 0; i < r; i++) {
            for (int j = 0; j < c; j++) {
                ary[i][c] += ary[i][j];
            }
        }
        for (int i = 0; i <= c; i++) {
            for (int j = 0; j < r; j++) {
                ary[r][i] += ary[j][i];
            }
        }

        for (int i = 0; i <= r; i++) {
            for (int j = 0; j < c; j++) {
                System.out.print(ary[i][j]+" ");
                
            }
            System.out.println(ary[i][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 ary[][] = new int[r + 1][c + 1]; ary new int[r + 1][c + 1] r + 1 r 1 c + 1 c 1 for (int i = 0; i < r; i++) {
            for (int j = 0; j < c; j++) {
                ary[i][j] = Integer.valueOf(sc.next());
            }
        } int i = 0; int i = 0; i 0 i < r i r i++ i++ i {
            for (int j = 0; j < c; j++) {
                ary[i][j] = Integer.valueOf(sc.next());
            }
        } {
            for (int j = 0; j < c; j++) {
                ary[i][j] = Integer.valueOf(sc.next());
            }
        } for (int j = 0; j < c; j++) {
                ary[i][j] = Integer.valueOf(sc.next());
            } int j = 0; int j = 0; j 0 j < c j c j++ j++ j {
                ary[i][j] = Integer.valueOf(sc.next());
            } {
                ary[i][j] = Integer.valueOf(sc.next());
            } ary[i][j] = Integer.valueOf(sc.next()) ary[i][j] ary[i] ary i j Integer.valueOf(sc.next()) Integer.valueOf Integer sc.next() sc.next sc for (int i = 0; i < r; i++) {
            for (int j = 0; j < c; j++) {
                ary[i][c] += ary[i][j];
            }
        } int i = 0; int i = 0; i 0 i < r i r i++ i++ i {
            for (int j = 0; j < c; j++) {
                ary[i][c] += ary[i][j];
            }
        } {
            for (int j = 0; j < c; j++) {
                ary[i][c] += ary[i][j];
            }
        } for (int j = 0; j < c; j++) {
                ary[i][c] += ary[i][j];
            } int j = 0; int j = 0; j 0 j < c j c j++ j++ j {
                ary[i][c] += ary[i][j];
            } {
                ary[i][c] += ary[i][j];
            } ary[i][c] += ary[i][j] ary[i][c] ary[i] ary i c ary[i][j] ary[i] ary i j for (int i = 0; i <= c; i++) {
            for (int j = 0; j < r; j++) {
                ary[r][i] += ary[j][i];
            }
        } int i = 0; int i = 0; i 0 i <= c i c i++ i++ i {
            for (int j = 0; j < r; j++) {
                ary[r][i] += ary[j][i];
            }
        } {
            for (int j = 0; j < r; j++) {
                ary[r][i] += ary[j][i];
            }
        } for (int j = 0; j < r; j++) {
                ary[r][i] += ary[j][i];
            } int j = 0; int j = 0; j 0 j < r j r j++ j++ j {
                ary[r][i] += ary[j][i];
            } {
                ary[r][i] += ary[j][i];
            } ary[r][i] += ary[j][i] ary[r][i] ary[r] ary r i ary[j][i] ary[j] ary j i for (int i = 0; i <= r; i++) {
            for (int j = 0; j < c; j++) {
                System.out.print(ary[i][j]+" ");
                
            }
            System.out.println(ary[i][c]);
        } int i = 0; int i = 0; i 0 i <= r i r i++ i++ i {
            for (int j = 0; j < c; j++) {
                System.out.print(ary[i][j]+" ");
                
            }
            System.out.println(ary[i][c]);
        } {
            for (int j = 0; j < c; j++) {
                System.out.print(ary[i][j]+" ");
                
            }
            System.out.println(ary[i][c]);
        } for (int j = 0; j < c; j++) {
                System.out.print(ary[i][j]+" ");
                
            } int j = 0; int j = 0; j 0 j < c j c j++ j++ j {
                System.out.print(ary[i][j]+" ");
                
            } {
                System.out.print(ary[i][j]+" ");
                
            } System.out.print(ary[i][j]+" ") System.out.print System.out System System.out ary[i][j]+" " ary[i][j] ary[i] ary i j " " System.out.println(ary[i][c]) System.out.println System.out System System.out ary[i][c] ary[i] ary i 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 ary[][] = new int[r + 1][c + 1];

        for (int i = 0; i < r; i++) {
            for (int j = 0; j < c; j++) {
                ary[i][j] = Integer.valueOf(sc.next());
            }
        }

        for (int i = 0; i < r; i++) {
            for (int j = 0; j < c; j++) {
                ary[i][c] += ary[i][j];
            }
        }
        for (int i = 0; i <= c; i++) {
            for (int j = 0; j < r; j++) {
                ary[r][i] += ary[j][i];
            }
        }

        for (int i = 0; i <= r; i++) {
            for (int j = 0; j < c; j++) {
                System.out.print(ary[i][j]+" ");
                
            }
            System.out.println(ary[i][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 ary[][] = new int[r + 1][c + 1];

        for (int i = 0; i < r; i++) {
            for (int j = 0; j < c; j++) {
                ary[i][j] = Integer.valueOf(sc.next());
            }
        }

        for (int i = 0; i < r; i++) {
            for (int j = 0; j < c; j++) {
                ary[i][c] += ary[i][j];
            }
        }
        for (int i = 0; i <= c; i++) {
            for (int j = 0; j < r; j++) {
                ary[r][i] += ary[j][i];
            }
        }

        for (int i = 0; i <= r; i++) {
            for (int j = 0; j < c; j++) {
                System.out.print(ary[i][j]+" ");
                
            }
            System.out.println(ary[i][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 ary[][] = new int[r + 1][c + 1];

        for (int i = 0; i < r; i++) {
            for (int j = 0; j < c; j++) {
                ary[i][j] = Integer.valueOf(sc.next());
            }
        }

        for (int i = 0; i < r; i++) {
            for (int j = 0; j < c; j++) {
                ary[i][c] += ary[i][j];
            }
        }
        for (int i = 0; i <= c; i++) {
            for (int j = 0; j < r; j++) {
                ary[r][i] += ary[j][i];
            }
        }

        for (int i = 0; i <= r; i++) {
            for (int j = 0; j < c; j++) {
                System.out.print(ary[i][j]+" ");
                
            }
            System.out.println(ary[i][c]);
        }
    }
}