import java.util.Scanner;
 
class Main{
  public static void main(String[] arg){
    int r, c;

    Scanner in = new Scanner(System.in);

    r = in.nextInt();
    c = in.nextInt();

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

    for(int i=0; i<output.length-1; i++){
        in.nextLine();
        for(int j=0; j<output[0].length-1; j++){
            output[i][j] = in.nextInt();
        }
    }

    for(int i=0; i<output.length; i++)
        output[i][output[0].length-1] = 0;

    for(int i=0; i<output[0].length-1; i++)
        output[output.length-1][i] = 0;

    for(int i=0; i<output.length-1; i++){
        for(int j=0; j<output[0].length-1; j++){
            output[i][output[0].length-1] += output[i][j];
            output[output.length-1][j] += output[i][j];
        }
    }

    for(int i=0; i<output[0].length-1; i++)
        output[output.length-1][output[0].length-1] += output[output.length-1][i];

    for(int i=0,j; i<output.length; i++){
        for(j=0; j<output[0].length-1; j++){
            System.out.print(output[i][j] + " ");
        }
        System.out.print(output[i][j]);
        System.out.println();
    }

  }
} import java.util.Scanner; Scanner java.util class Main{
  public static void main(String[] arg){
    int r, c;

    Scanner in = new Scanner(System.in);

    r = in.nextInt();
    c = in.nextInt();

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

    for(int i=0; i<output.length-1; i++){
        in.nextLine();
        for(int j=0; j<output[0].length-1; j++){
            output[i][j] = in.nextInt();
        }
    }

    for(int i=0; i<output.length; i++)
        output[i][output[0].length-1] = 0;

    for(int i=0; i<output[0].length-1; i++)
        output[output.length-1][i] = 0;

    for(int i=0; i<output.length-1; i++){
        for(int j=0; j<output[0].length-1; j++){
            output[i][output[0].length-1] += output[i][j];
            output[output.length-1][j] += output[i][j];
        }
    }

    for(int i=0; i<output[0].length-1; i++)
        output[output.length-1][output[0].length-1] += output[output.length-1][i];

    for(int i=0,j; i<output.length; i++){
        for(j=0; j<output[0].length-1; j++){
            System.out.print(output[i][j] + " ");
        }
        System.out.print(output[i][j]);
        System.out.println();
    }

  }
} Main public static void main(String[] arg){
    int r, c;

    Scanner in = new Scanner(System.in);

    r = in.nextInt();
    c = in.nextInt();

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

    for(int i=0; i<output.length-1; i++){
        in.nextLine();
        for(int j=0; j<output[0].length-1; j++){
            output[i][j] = in.nextInt();
        }
    }

    for(int i=0; i<output.length; i++)
        output[i][output[0].length-1] = 0;

    for(int i=0; i<output[0].length-1; i++)
        output[output.length-1][i] = 0;

    for(int i=0; i<output.length-1; i++){
        for(int j=0; j<output[0].length-1; j++){
            output[i][output[0].length-1] += output[i][j];
            output[output.length-1][j] += output[i][j];
        }
    }

    for(int i=0; i<output[0].length-1; i++)
        output[output.length-1][output[0].length-1] += output[output.length-1][i];

    for(int i=0,j; i<output.length; i++){
        for(j=0; j<output[0].length-1; j++){
            System.out.print(output[i][j] + " ");
        }
        System.out.print(output[i][j]);
        System.out.println();
    }

  } main {
    int r, c;

    Scanner in = new Scanner(System.in);

    r = in.nextInt();
    c = in.nextInt();

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

    for(int i=0; i<output.length-1; i++){
        in.nextLine();
        for(int j=0; j<output[0].length-1; j++){
            output[i][j] = in.nextInt();
        }
    }

    for(int i=0; i<output.length; i++)
        output[i][output[0].length-1] = 0;

    for(int i=0; i<output[0].length-1; i++)
        output[output.length-1][i] = 0;

    for(int i=0; i<output.length-1; i++){
        for(int j=0; j<output[0].length-1; j++){
            output[i][output[0].length-1] += output[i][j];
            output[output.length-1][j] += output[i][j];
        }
    }

    for(int i=0; i<output[0].length-1; i++)
        output[output.length-1][output[0].length-1] += output[output.length-1][i];

    for(int i=0,j; i<output.length; i++){
        for(j=0; j<output[0].length-1; j++){
            System.out.print(output[i][j] + " ");
        }
        System.out.print(output[i][j]);
        System.out.println();
    }

  } int r r c; c Scanner in = new Scanner(System.in); in new Scanner(System.in) r = in.nextInt() r in.nextInt() in.nextInt in c = in.nextInt() c in.nextInt() in.nextInt in int [][] output = new int[r+1][c+1]; output new int[r+1][c+1] r+1 r 1 c+1 c 1 for(int i=0; i<output.length-1; i++){
        in.nextLine();
        for(int j=0; j<output[0].length-1; j++){
            output[i][j] = in.nextInt();
        }
    } int i=0; int i=0; i 0 i<output.length-1 i output.length-1 output.length output output.length 1 i++ i++ i {
        in.nextLine();
        for(int j=0; j<output[0].length-1; j++){
            output[i][j] = in.nextInt();
        }
    } {
        in.nextLine();
        for(int j=0; j<output[0].length-1; j++){
            output[i][j] = in.nextInt();
        }
    } in.nextLine() in.nextLine in for(int j=0; j<output[0].length-1; j++){
            output[i][j] = in.nextInt();
        } int j=0; int j=0; j 0 j<output[0].length-1 j output[0].length-1 output[0].length output[0] output 0 output[0].length 1 j++ j++ j {
            output[i][j] = in.nextInt();
        } {
            output[i][j] = in.nextInt();
        } output[i][j] = in.nextInt() output[i][j] output[i] output i j in.nextInt() in.nextInt in for(int i=0; i<output.length; i++)
        output[i][output[0].length-1] = 0; int i=0; int i=0; i 0 i<output.length i output.length output output.length i++ i++ i output[i][output[0].length-1] = 0; output[i][output[0].length-1] = 0 output[i][output[0].length-1] output[i] output i output[0].length-1 output[0].length output[0] output 0 output[0].length 1 0 for(int i=0; i<output[0].length-1; i++)
        output[output.length-1][i] = 0; int i=0; int i=0; i 0 i<output[0].length-1 i output[0].length-1 output[0].length output[0] output 0 output[0].length 1 i++ i++ i output[output.length-1][i] = 0; output[output.length-1][i] = 0 output[output.length-1][i] output[output.length-1] output output.length-1 output.length output output.length 1 i 0 for(int i=0; i<output.length-1; i++){
        for(int j=0; j<output[0].length-1; j++){
            output[i][output[0].length-1] += output[i][j];
            output[output.length-1][j] += output[i][j];
        }
    } int i=0; int i=0; i 0 i<output.length-1 i output.length-1 output.length output output.length 1 i++ i++ i {
        for(int j=0; j<output[0].length-1; j++){
            output[i][output[0].length-1] += output[i][j];
            output[output.length-1][j] += output[i][j];
        }
    } {
        for(int j=0; j<output[0].length-1; j++){
            output[i][output[0].length-1] += output[i][j];
            output[output.length-1][j] += output[i][j];
        }
    } for(int j=0; j<output[0].length-1; j++){
            output[i][output[0].length-1] += output[i][j];
            output[output.length-1][j] += output[i][j];
        } int j=0; int j=0; j 0 j<output[0].length-1 j output[0].length-1 output[0].length output[0] output 0 output[0].length 1 j++ j++ j {
            output[i][output[0].length-1] += output[i][j];
            output[output.length-1][j] += output[i][j];
        } {
            output[i][output[0].length-1] += output[i][j];
            output[output.length-1][j] += output[i][j];
        } output[i][output[0].length-1] += output[i][j] output[i][output[0].length-1] output[i] output i output[0].length-1 output[0].length output[0] output 0 output[0].length 1 output[i][j] output[i] output i j output[output.length-1][j] += output[i][j] output[output.length-1][j] output[output.length-1] output output.length-1 output.length output output.length 1 j output[i][j] output[i] output i j for(int i=0; i<output[0].length-1; i++)
        output[output.length-1][output[0].length-1] += output[output.length-1][i]; int i=0; int i=0; i 0 i<output[0].length-1 i output[0].length-1 output[0].length output[0] output 0 output[0].length 1 i++ i++ i output[output.length-1][output[0].length-1] += output[output.length-1][i]; output[output.length-1][output[0].length-1] += output[output.length-1][i] output[output.length-1][output[0].length-1] output[output.length-1] output output.length-1 output.length output output.length 1 output[0].length-1 output[0].length output[0] output 0 output[0].length 1 output[output.length-1][i] output[output.length-1] output output.length-1 output.length output output.length 1 i for(int i=0,j; i<output.length; i++){
        for(j=0; j<output[0].length-1; j++){
            System.out.print(output[i][j] + " ");
        }
        System.out.print(output[i][j]);
        System.out.println();
    } int i=0,j; int i=0 i 0 j; j i<output.length i output.length output output.length i++ i++ i {
        for(j=0; j<output[0].length-1; j++){
            System.out.print(output[i][j] + " ");
        }
        System.out.print(output[i][j]);
        System.out.println();
    } {
        for(j=0; j<output[0].length-1; j++){
            System.out.print(output[i][j] + " ");
        }
        System.out.print(output[i][j]);
        System.out.println();
    } for(j=0; j<output[0].length-1; j++){
            System.out.print(output[i][j] + " ");
        } j=0; j=0 j 0 j<output[0].length-1 j output[0].length-1 output[0].length output[0] output 0 output[0].length 1 j++ j++ j {
            System.out.print(output[i][j] + " ");
        } {
            System.out.print(output[i][j] + " ");
        } System.out.print(output[i][j] + " ") System.out.print System.out System System.out output[i][j] + " " output[i][j] output[i] output i j " " System.out.print(output[i][j]) System.out.print System.out System System.out output[i][j] output[i] output i j System.out.println() System.out.println System.out System System.out String[] arg arg
import java.util.Scanner;
 
class Main{
  public static void main(String[] arg){
    int r, c;

    Scanner in = new Scanner(System.in);

    r = in.nextInt();
    c = in.nextInt();

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

    for(int i=0; i<output.length-1; i++){
        in.nextLine();
        for(int j=0; j<output[0].length-1; j++){
            output[i][j] = in.nextInt();
        }
    }

    for(int i=0; i<output.length; i++)
        output[i][output[0].length-1] = 0;

    for(int i=0; i<output[0].length-1; i++)
        output[output.length-1][i] = 0;

    for(int i=0; i<output.length-1; i++){
        for(int j=0; j<output[0].length-1; j++){
            output[i][output[0].length-1] += output[i][j];
            output[output.length-1][j] += output[i][j];
        }
    }

    for(int i=0; i<output[0].length-1; i++)
        output[output.length-1][output[0].length-1] += output[output.length-1][i];

    for(int i=0,j; i<output.length; i++){
        for(j=0; j<output[0].length-1; j++){
            System.out.print(output[i][j] + " ");
        }
        System.out.print(output[i][j]);
        System.out.println();
    }

  }
}