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

public class Main {

    public static void main(String[] args) throws IOException {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        String[] line = br.readLine().split(" ");
        
        int f = 0;
        int r = Integer.parseInt(line[0]);
        int c = Integer.parseInt(line[1]);
        int num[][] = new int[r][c];
        int sum_r[] = new int[r];
        int sum_c[] = new int[c];

        for (int a = 0; a < r; a++) {
            String[] line1 = br.readLine().split(" ");
            for (int b = 0; b < c; b++) {                
                num[a][b] = Integer.parseInt(line1[b]);
            }
        }
        
        for (int a = 0; a < r; a++) {
            for (int b = 0; b < c; b++) {                
                sum_r[a] += num[a][b];
            }            
        }
        
        for (int b = 0; b < c; b++) {
            for (int a = 0; a < r; a++) {                
                sum_c[b] += num[a][b];
            }            
        }
        
        for(int a = 0; a < r; a++) {
            f += sum_r[a];
        }

        for(int x = 0; x < r + 1; x++) {
            if(x != r) {               
                for(int y = 0; y < c + 1; y++) {
                    if(y != c) { System.out.print(num[x][y] + " "); }
                    else { System.out.println(sum_r[x]); }
                }                            
            }
            
            else {
                for(int z = 0; z < c + 1; z++) {
                    if(z != c){
                        System.out.print(sum_c[z] + " ");
                    }
                    else {
                        System.out.println(f); 
                    }
                }
            }
        }
        

    }

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

    public static void main(String[] args) throws IOException {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        String[] line = br.readLine().split(" ");
        
        int f = 0;
        int r = Integer.parseInt(line[0]);
        int c = Integer.parseInt(line[1]);
        int num[][] = new int[r][c];
        int sum_r[] = new int[r];
        int sum_c[] = new int[c];

        for (int a = 0; a < r; a++) {
            String[] line1 = br.readLine().split(" ");
            for (int b = 0; b < c; b++) {                
                num[a][b] = Integer.parseInt(line1[b]);
            }
        }
        
        for (int a = 0; a < r; a++) {
            for (int b = 0; b < c; b++) {                
                sum_r[a] += num[a][b];
            }            
        }
        
        for (int b = 0; b < c; b++) {
            for (int a = 0; a < r; a++) {                
                sum_c[b] += num[a][b];
            }            
        }
        
        for(int a = 0; a < r; a++) {
            f += sum_r[a];
        }

        for(int x = 0; x < r + 1; x++) {
            if(x != r) {               
                for(int y = 0; y < c + 1; y++) {
                    if(y != c) { System.out.print(num[x][y] + " "); }
                    else { System.out.println(sum_r[x]); }
                }                            
            }
            
            else {
                for(int z = 0; z < c + 1; z++) {
                    if(z != c){
                        System.out.print(sum_c[z] + " ");
                    }
                    else {
                        System.out.println(f); 
                    }
                }
            }
        }
        

    }

} Main public static void main(String[] args) throws IOException {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        String[] line = br.readLine().split(" ");
        
        int f = 0;
        int r = Integer.parseInt(line[0]);
        int c = Integer.parseInt(line[1]);
        int num[][] = new int[r][c];
        int sum_r[] = new int[r];
        int sum_c[] = new int[c];

        for (int a = 0; a < r; a++) {
            String[] line1 = br.readLine().split(" ");
            for (int b = 0; b < c; b++) {                
                num[a][b] = Integer.parseInt(line1[b]);
            }
        }
        
        for (int a = 0; a < r; a++) {
            for (int b = 0; b < c; b++) {                
                sum_r[a] += num[a][b];
            }            
        }
        
        for (int b = 0; b < c; b++) {
            for (int a = 0; a < r; a++) {                
                sum_c[b] += num[a][b];
            }            
        }
        
        for(int a = 0; a < r; a++) {
            f += sum_r[a];
        }

        for(int x = 0; x < r + 1; x++) {
            if(x != r) {               
                for(int y = 0; y < c + 1; y++) {
                    if(y != c) { System.out.print(num[x][y] + " "); }
                    else { System.out.println(sum_r[x]); }
                }                            
            }
            
            else {
                for(int z = 0; z < c + 1; z++) {
                    if(z != c){
                        System.out.print(sum_c[z] + " ");
                    }
                    else {
                        System.out.println(f); 
                    }
                }
            }
        }
        

    } main {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        String[] line = br.readLine().split(" ");
        
        int f = 0;
        int r = Integer.parseInt(line[0]);
        int c = Integer.parseInt(line[1]);
        int num[][] = new int[r][c];
        int sum_r[] = new int[r];
        int sum_c[] = new int[c];

        for (int a = 0; a < r; a++) {
            String[] line1 = br.readLine().split(" ");
            for (int b = 0; b < c; b++) {                
                num[a][b] = Integer.parseInt(line1[b]);
            }
        }
        
        for (int a = 0; a < r; a++) {
            for (int b = 0; b < c; b++) {                
                sum_r[a] += num[a][b];
            }            
        }
        
        for (int b = 0; b < c; b++) {
            for (int a = 0; a < r; a++) {                
                sum_c[b] += num[a][b];
            }            
        }
        
        for(int a = 0; a < r; a++) {
            f += sum_r[a];
        }

        for(int x = 0; x < r + 1; x++) {
            if(x != r) {               
                for(int y = 0; y < c + 1; y++) {
                    if(y != c) { System.out.print(num[x][y] + " "); }
                    else { System.out.println(sum_r[x]); }
                }                            
            }
            
            else {
                for(int z = 0; z < c + 1; z++) {
                    if(z != c){
                        System.out.print(sum_c[z] + " ");
                    }
                    else {
                        System.out.println(f); 
                    }
                }
            }
        }
        

    } BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) String[] line = br.readLine().split(" "); line br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " int f = 0; f 0 int r = Integer.parseInt(line[0]); r Integer.parseInt(line[0]) Integer.parseInt Integer line[0] line 0 int c = Integer.parseInt(line[1]); c Integer.parseInt(line[1]) Integer.parseInt Integer line[1] line 1 int num[][] = new int[r][c]; num new int[r][c] r c int sum_r[] = new int[r]; sum_r new int[r] r int sum_c[] = new int[c]; sum_c new int[c] c for (int a = 0; a < r; a++) {
            String[] line1 = br.readLine().split(" ");
            for (int b = 0; b < c; b++) {                
                num[a][b] = Integer.parseInt(line1[b]);
            }
        } int a = 0; int a = 0; a 0 a < r a r a++ a++ a {
            String[] line1 = br.readLine().split(" ");
            for (int b = 0; b < c; b++) {                
                num[a][b] = Integer.parseInt(line1[b]);
            }
        } {
            String[] line1 = br.readLine().split(" ");
            for (int b = 0; b < c; b++) {                
                num[a][b] = Integer.parseInt(line1[b]);
            }
        } String[] line1 = br.readLine().split(" "); line1 br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " for (int b = 0; b < c; b++) {                
                num[a][b] = Integer.parseInt(line1[b]);
            } int b = 0; int b = 0; b 0 b < c b c b++ b++ b {                
                num[a][b] = Integer.parseInt(line1[b]);
            } {                
                num[a][b] = Integer.parseInt(line1[b]);
            } num[a][b] = Integer.parseInt(line1[b]) num[a][b] num[a] num a b Integer.parseInt(line1[b]) Integer.parseInt Integer line1[b] line1 b for (int a = 0; a < r; a++) {
            for (int b = 0; b < c; b++) {                
                sum_r[a] += num[a][b];
            }            
        } int a = 0; int a = 0; a 0 a < r a r a++ a++ a {
            for (int b = 0; b < c; b++) {                
                sum_r[a] += num[a][b];
            }            
        } {
            for (int b = 0; b < c; b++) {                
                sum_r[a] += num[a][b];
            }            
        } for (int b = 0; b < c; b++) {                
                sum_r[a] += num[a][b];
            } int b = 0; int b = 0; b 0 b < c b c b++ b++ b {                
                sum_r[a] += num[a][b];
            } {                
                sum_r[a] += num[a][b];
            } sum_r[a] += num[a][b] sum_r[a] sum_r a num[a][b] num[a] num a b for (int b = 0; b < c; b++) {
            for (int a = 0; a < r; a++) {                
                sum_c[b] += num[a][b];
            }            
        } int b = 0; int b = 0; b 0 b < c b c b++ b++ b {
            for (int a = 0; a < r; a++) {                
                sum_c[b] += num[a][b];
            }            
        } {
            for (int a = 0; a < r; a++) {                
                sum_c[b] += num[a][b];
            }            
        } for (int a = 0; a < r; a++) {                
                sum_c[b] += num[a][b];
            } int a = 0; int a = 0; a 0 a < r a r a++ a++ a {                
                sum_c[b] += num[a][b];
            } {                
                sum_c[b] += num[a][b];
            } sum_c[b] += num[a][b] sum_c[b] sum_c b num[a][b] num[a] num a b for(int a = 0; a < r; a++) {
            f += sum_r[a];
        } int a = 0; int a = 0; a 0 a < r a r a++ a++ a {
            f += sum_r[a];
        } {
            f += sum_r[a];
        } f += sum_r[a] f sum_r[a] sum_r a for(int x = 0; x < r + 1; x++) {
            if(x != r) {               
                for(int y = 0; y < c + 1; y++) {
                    if(y != c) { System.out.print(num[x][y] + " "); }
                    else { System.out.println(sum_r[x]); }
                }                            
            }
            
            else {
                for(int z = 0; z < c + 1; z++) {
                    if(z != c){
                        System.out.print(sum_c[z] + " ");
                    }
                    else {
                        System.out.println(f); 
                    }
                }
            }
        } int x = 0; int x = 0; x 0 x < r + 1 x r + 1 r 1 x++ x++ x {
            if(x != r) {               
                for(int y = 0; y < c + 1; y++) {
                    if(y != c) { System.out.print(num[x][y] + " "); }
                    else { System.out.println(sum_r[x]); }
                }                            
            }
            
            else {
                for(int z = 0; z < c + 1; z++) {
                    if(z != c){
                        System.out.print(sum_c[z] + " ");
                    }
                    else {
                        System.out.println(f); 
                    }
                }
            }
        } {
            if(x != r) {               
                for(int y = 0; y < c + 1; y++) {
                    if(y != c) { System.out.print(num[x][y] + " "); }
                    else { System.out.println(sum_r[x]); }
                }                            
            }
            
            else {
                for(int z = 0; z < c + 1; z++) {
                    if(z != c){
                        System.out.print(sum_c[z] + " ");
                    }
                    else {
                        System.out.println(f); 
                    }
                }
            }
        } if(x != r) {               
                for(int y = 0; y < c + 1; y++) {
                    if(y != c) { System.out.print(num[x][y] + " "); }
                    else { System.out.println(sum_r[x]); }
                }                            
            }
            
            else {
                for(int z = 0; z < c + 1; z++) {
                    if(z != c){
                        System.out.print(sum_c[z] + " ");
                    }
                    else {
                        System.out.println(f); 
                    }
                }
            } x != r x r {               
                for(int y = 0; y < c + 1; y++) {
                    if(y != c) { System.out.print(num[x][y] + " "); }
                    else { System.out.println(sum_r[x]); }
                }                            
            } for(int y = 0; y < c + 1; y++) {
                    if(y != c) { System.out.print(num[x][y] + " "); }
                    else { System.out.println(sum_r[x]); }
                } int y = 0; int y = 0; y 0 y < c + 1 y c + 1 c 1 y++ y++ y {
                    if(y != c) { System.out.print(num[x][y] + " "); }
                    else { System.out.println(sum_r[x]); }
                } {
                    if(y != c) { System.out.print(num[x][y] + " "); }
                    else { System.out.println(sum_r[x]); }
                } if(y != c) { System.out.print(num[x][y] + " "); }
                    else { System.out.println(sum_r[x]); } y != c y c { System.out.print(num[x][y] + " "); } System.out.print(num[x][y] + " ") System.out.print System.out System System.out num[x][y] + " " num[x][y] num[x] num x y " " { System.out.println(sum_r[x]); } System.out.println(sum_r[x]) System.out.println System.out System System.out sum_r[x] sum_r x {
                for(int z = 0; z < c + 1; z++) {
                    if(z != c){
                        System.out.print(sum_c[z] + " ");
                    }
                    else {
                        System.out.println(f); 
                    }
                }
            } for(int z = 0; z < c + 1; z++) {
                    if(z != c){
                        System.out.print(sum_c[z] + " ");
                    }
                    else {
                        System.out.println(f); 
                    }
                } int z = 0; int z = 0; z 0 z < c + 1 z c + 1 c 1 z++ z++ z {
                    if(z != c){
                        System.out.print(sum_c[z] + " ");
                    }
                    else {
                        System.out.println(f); 
                    }
                } {
                    if(z != c){
                        System.out.print(sum_c[z] + " ");
                    }
                    else {
                        System.out.println(f); 
                    }
                } if(z != c){
                        System.out.print(sum_c[z] + " ");
                    }
                    else {
                        System.out.println(f); 
                    } z != c z c {
                        System.out.print(sum_c[z] + " ");
                    } System.out.print(sum_c[z] + " ") System.out.print System.out System System.out sum_c[z] + " " sum_c[z] sum_c z " " {
                        System.out.println(f); 
                    } System.out.println(f) System.out.println System.out System System.out f String[] args args public class Main {

    public static void main(String[] args) throws IOException {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        String[] line = br.readLine().split(" ");
        
        int f = 0;
        int r = Integer.parseInt(line[0]);
        int c = Integer.parseInt(line[1]);
        int num[][] = new int[r][c];
        int sum_r[] = new int[r];
        int sum_c[] = new int[c];

        for (int a = 0; a < r; a++) {
            String[] line1 = br.readLine().split(" ");
            for (int b = 0; b < c; b++) {                
                num[a][b] = Integer.parseInt(line1[b]);
            }
        }
        
        for (int a = 0; a < r; a++) {
            for (int b = 0; b < c; b++) {                
                sum_r[a] += num[a][b];
            }            
        }
        
        for (int b = 0; b < c; b++) {
            for (int a = 0; a < r; a++) {                
                sum_c[b] += num[a][b];
            }            
        }
        
        for(int a = 0; a < r; a++) {
            f += sum_r[a];
        }

        for(int x = 0; x < r + 1; x++) {
            if(x != r) {               
                for(int y = 0; y < c + 1; y++) {
                    if(y != c) { System.out.print(num[x][y] + " "); }
                    else { System.out.println(sum_r[x]); }
                }                            
            }
            
            else {
                for(int z = 0; z < c + 1; z++) {
                    if(z != c){
                        System.out.print(sum_c[z] + " ");
                    }
                    else {
                        System.out.println(f); 
                    }
                }
            }
        }
        

    }

} public class Main {

    public static void main(String[] args) throws IOException {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        String[] line = br.readLine().split(" ");
        
        int f = 0;
        int r = Integer.parseInt(line[0]);
        int c = Integer.parseInt(line[1]);
        int num[][] = new int[r][c];
        int sum_r[] = new int[r];
        int sum_c[] = new int[c];

        for (int a = 0; a < r; a++) {
            String[] line1 = br.readLine().split(" ");
            for (int b = 0; b < c; b++) {                
                num[a][b] = Integer.parseInt(line1[b]);
            }
        }
        
        for (int a = 0; a < r; a++) {
            for (int b = 0; b < c; b++) {                
                sum_r[a] += num[a][b];
            }            
        }
        
        for (int b = 0; b < c; b++) {
            for (int a = 0; a < r; a++) {                
                sum_c[b] += num[a][b];
            }            
        }
        
        for(int a = 0; a < r; a++) {
            f += sum_r[a];
        }

        for(int x = 0; x < r + 1; x++) {
            if(x != r) {               
                for(int y = 0; y < c + 1; y++) {
                    if(y != c) { System.out.print(num[x][y] + " "); }
                    else { System.out.println(sum_r[x]); }
                }                            
            }
            
            else {
                for(int z = 0; z < c + 1; z++) {
                    if(z != c){
                        System.out.print(sum_c[z] + " ");
                    }
                    else {
                        System.out.println(f); 
                    }
                }
            }
        }
        

    }

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

public class Main {

    public static void main(String[] args) throws IOException {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        String[] line = br.readLine().split(" ");
        
        int f = 0;
        int r = Integer.parseInt(line[0]);
        int c = Integer.parseInt(line[1]);
        int num[][] = new int[r][c];
        int sum_r[] = new int[r];
        int sum_c[] = new int[c];

        for (int a = 0; a < r; a++) {
            String[] line1 = br.readLine().split(" ");
            for (int b = 0; b < c; b++) {                
                num[a][b] = Integer.parseInt(line1[b]);
            }
        }
        
        for (int a = 0; a < r; a++) {
            for (int b = 0; b < c; b++) {                
                sum_r[a] += num[a][b];
            }            
        }
        
        for (int b = 0; b < c; b++) {
            for (int a = 0; a < r; a++) {                
                sum_c[b] += num[a][b];
            }            
        }
        
        for(int a = 0; a < r; a++) {
            f += sum_r[a];
        }

        for(int x = 0; x < r + 1; x++) {
            if(x != r) {               
                for(int y = 0; y < c + 1; y++) {
                    if(y != c) { System.out.print(num[x][y] + " "); }
                    else { System.out.println(sum_r[x]); }
                }                            
            }
            
            else {
                for(int z = 0; z < c + 1; z++) {
                    if(z != c){
                        System.out.print(sum_c[z] + " ");
                    }
                    else {
                        System.out.println(f); 
                    }
                }
            }
        }
        

    }

}