import java.util.*;
import java.io.*;
 
public class Main{
  public static void main(String[] args)throws IOException{
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
 
String str = br.readLine();
                    String[] strs = str.split("\\s");
                    int r = Integer.parseInt(strs[0]);
                    int c = Integer.parseInt(strs[1]);
                    int[][] graph = new int[r+1][c+1];
                    int lastnum = 0;
 
                    for(int i = 0;i<r;i++){
                        str = br.readLine();
                        String[] temp = str.split("\\s");
                        int total =0;
 
                        for(int j =0;j<c;j++){
                            int tempnum = Integer.parseInt(temp[j]);
                            total += tempnum;
                            graph[i][j] = tempnum;
 
                            if(i == 0){
                                graph[r][j]= tempnum;
                            }else{
                                int tempnum2 = graph[r][j];
                                tempnum2 += tempnum;
                                graph[r][j]=tempnum2;
                            }
                        }
                        graph[i][c] = total;
                        lastnum += total;
                    }
                    br.close();
                    graph[r][c] = lastnum;
                     
                    for(int i =0;i<r+1;i++){
                        StringBuilder sb = new StringBuilder();
                        for(int j=0;j<c+1;j++){
                            String ts = String.valueOf(graph[i][j]);
                            sb.append(ts);
                            
                             if(j != c){
                            sb.append(" ");
                            }
                        }
                        System.out.println(new String(sb));
 
                    }
 
 
}
} import java.util.*; util.* java import java.io.*; io.* java public class Main{
  public static void main(String[] args)throws IOException{
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
 
String str = br.readLine();
                    String[] strs = str.split("\\s");
                    int r = Integer.parseInt(strs[0]);
                    int c = Integer.parseInt(strs[1]);
                    int[][] graph = new int[r+1][c+1];
                    int lastnum = 0;
 
                    for(int i = 0;i<r;i++){
                        str = br.readLine();
                        String[] temp = str.split("\\s");
                        int total =0;
 
                        for(int j =0;j<c;j++){
                            int tempnum = Integer.parseInt(temp[j]);
                            total += tempnum;
                            graph[i][j] = tempnum;
 
                            if(i == 0){
                                graph[r][j]= tempnum;
                            }else{
                                int tempnum2 = graph[r][j];
                                tempnum2 += tempnum;
                                graph[r][j]=tempnum2;
                            }
                        }
                        graph[i][c] = total;
                        lastnum += total;
                    }
                    br.close();
                    graph[r][c] = lastnum;
                     
                    for(int i =0;i<r+1;i++){
                        StringBuilder sb = new StringBuilder();
                        for(int j=0;j<c+1;j++){
                            String ts = String.valueOf(graph[i][j]);
                            sb.append(ts);
                            
                             if(j != c){
                            sb.append(" ");
                            }
                        }
                        System.out.println(new String(sb));
 
                    }
 
 
}
} Main public static void main(String[] args)throws IOException{
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
 
String str = br.readLine();
                    String[] strs = str.split("\\s");
                    int r = Integer.parseInt(strs[0]);
                    int c = Integer.parseInt(strs[1]);
                    int[][] graph = new int[r+1][c+1];
                    int lastnum = 0;
 
                    for(int i = 0;i<r;i++){
                        str = br.readLine();
                        String[] temp = str.split("\\s");
                        int total =0;
 
                        for(int j =0;j<c;j++){
                            int tempnum = Integer.parseInt(temp[j]);
                            total += tempnum;
                            graph[i][j] = tempnum;
 
                            if(i == 0){
                                graph[r][j]= tempnum;
                            }else{
                                int tempnum2 = graph[r][j];
                                tempnum2 += tempnum;
                                graph[r][j]=tempnum2;
                            }
                        }
                        graph[i][c] = total;
                        lastnum += total;
                    }
                    br.close();
                    graph[r][c] = lastnum;
                     
                    for(int i =0;i<r+1;i++){
                        StringBuilder sb = new StringBuilder();
                        for(int j=0;j<c+1;j++){
                            String ts = String.valueOf(graph[i][j]);
                            sb.append(ts);
                            
                             if(j != c){
                            sb.append(" ");
                            }
                        }
                        System.out.println(new String(sb));
 
                    }
 
 
} main {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
 
String str = br.readLine();
                    String[] strs = str.split("\\s");
                    int r = Integer.parseInt(strs[0]);
                    int c = Integer.parseInt(strs[1]);
                    int[][] graph = new int[r+1][c+1];
                    int lastnum = 0;
 
                    for(int i = 0;i<r;i++){
                        str = br.readLine();
                        String[] temp = str.split("\\s");
                        int total =0;
 
                        for(int j =0;j<c;j++){
                            int tempnum = Integer.parseInt(temp[j]);
                            total += tempnum;
                            graph[i][j] = tempnum;
 
                            if(i == 0){
                                graph[r][j]= tempnum;
                            }else{
                                int tempnum2 = graph[r][j];
                                tempnum2 += tempnum;
                                graph[r][j]=tempnum2;
                            }
                        }
                        graph[i][c] = total;
                        lastnum += total;
                    }
                    br.close();
                    graph[r][c] = lastnum;
                     
                    for(int i =0;i<r+1;i++){
                        StringBuilder sb = new StringBuilder();
                        for(int j=0;j<c+1;j++){
                            String ts = String.valueOf(graph[i][j]);
                            sb.append(ts);
                            
                             if(j != c){
                            sb.append(" ");
                            }
                        }
                        System.out.println(new String(sb));
 
                    }
 
 
} BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) String str = br.readLine(); str br.readLine() br.readLine br String[] strs = str.split("\\s"); strs str.split("\\s") str.split str "\\s" int r = Integer.parseInt(strs[0]); r Integer.parseInt(strs[0]) Integer.parseInt Integer strs[0] strs 0 int c = Integer.parseInt(strs[1]); c Integer.parseInt(strs[1]) Integer.parseInt Integer strs[1] strs 1 int[][] graph = new int[r+1][c+1]; graph new int[r+1][c+1] r+1 r 1 c+1 c 1 int lastnum = 0; lastnum 0 for(int i = 0;i<r;i++){
                        str = br.readLine();
                        String[] temp = str.split("\\s");
                        int total =0;
 
                        for(int j =0;j<c;j++){
                            int tempnum = Integer.parseInt(temp[j]);
                            total += tempnum;
                            graph[i][j] = tempnum;
 
                            if(i == 0){
                                graph[r][j]= tempnum;
                            }else{
                                int tempnum2 = graph[r][j];
                                tempnum2 += tempnum;
                                graph[r][j]=tempnum2;
                            }
                        }
                        graph[i][c] = total;
                        lastnum += total;
                    } int i = 0; int i = 0; i 0 i<r i r i++ i++ i {
                        str = br.readLine();
                        String[] temp = str.split("\\s");
                        int total =0;
 
                        for(int j =0;j<c;j++){
                            int tempnum = Integer.parseInt(temp[j]);
                            total += tempnum;
                            graph[i][j] = tempnum;
 
                            if(i == 0){
                                graph[r][j]= tempnum;
                            }else{
                                int tempnum2 = graph[r][j];
                                tempnum2 += tempnum;
                                graph[r][j]=tempnum2;
                            }
                        }
                        graph[i][c] = total;
                        lastnum += total;
                    } {
                        str = br.readLine();
                        String[] temp = str.split("\\s");
                        int total =0;
 
                        for(int j =0;j<c;j++){
                            int tempnum = Integer.parseInt(temp[j]);
                            total += tempnum;
                            graph[i][j] = tempnum;
 
                            if(i == 0){
                                graph[r][j]= tempnum;
                            }else{
                                int tempnum2 = graph[r][j];
                                tempnum2 += tempnum;
                                graph[r][j]=tempnum2;
                            }
                        }
                        graph[i][c] = total;
                        lastnum += total;
                    } str = br.readLine() str br.readLine() br.readLine br String[] temp = str.split("\\s"); temp str.split("\\s") str.split str "\\s" int total =0; total 0 for(int j =0;j<c;j++){
                            int tempnum = Integer.parseInt(temp[j]);
                            total += tempnum;
                            graph[i][j] = tempnum;
 
                            if(i == 0){
                                graph[r][j]= tempnum;
                            }else{
                                int tempnum2 = graph[r][j];
                                tempnum2 += tempnum;
                                graph[r][j]=tempnum2;
                            }
                        } int j =0; int j =0; j 0 j<c j c j++ j++ j {
                            int tempnum = Integer.parseInt(temp[j]);
                            total += tempnum;
                            graph[i][j] = tempnum;
 
                            if(i == 0){
                                graph[r][j]= tempnum;
                            }else{
                                int tempnum2 = graph[r][j];
                                tempnum2 += tempnum;
                                graph[r][j]=tempnum2;
                            }
                        } {
                            int tempnum = Integer.parseInt(temp[j]);
                            total += tempnum;
                            graph[i][j] = tempnum;
 
                            if(i == 0){
                                graph[r][j]= tempnum;
                            }else{
                                int tempnum2 = graph[r][j];
                                tempnum2 += tempnum;
                                graph[r][j]=tempnum2;
                            }
                        } int tempnum = Integer.parseInt(temp[j]); tempnum Integer.parseInt(temp[j]) Integer.parseInt Integer temp[j] temp j total += tempnum total tempnum graph[i][j] = tempnum graph[i][j] graph[i] graph i j tempnum if(i == 0){
                                graph[r][j]= tempnum;
                            }else{
                                int tempnum2 = graph[r][j];
                                tempnum2 += tempnum;
                                graph[r][j]=tempnum2;
                            } i == 0 i 0 {
                                graph[r][j]= tempnum;
                            } graph[r][j]= tempnum graph[r][j] graph[r] graph r j tempnum {
                                int tempnum2 = graph[r][j];
                                tempnum2 += tempnum;
                                graph[r][j]=tempnum2;
                            } int tempnum2 = graph[r][j]; tempnum2 graph[r][j] graph[r] graph r j tempnum2 += tempnum tempnum2 tempnum graph[r][j]=tempnum2 graph[r][j] graph[r] graph r j tempnum2 graph[i][c] = total graph[i][c] graph[i] graph i c total lastnum += total lastnum total br.close() br.close br graph[r][c] = lastnum graph[r][c] graph[r] graph r c lastnum for(int i =0;i<r+1;i++){
                        StringBuilder sb = new StringBuilder();
                        for(int j=0;j<c+1;j++){
                            String ts = String.valueOf(graph[i][j]);
                            sb.append(ts);
                            
                             if(j != c){
                            sb.append(" ");
                            }
                        }
                        System.out.println(new String(sb));
 
                    } int i =0; int i =0; i 0 i<r+1 i r+1 r 1 i++ i++ i {
                        StringBuilder sb = new StringBuilder();
                        for(int j=0;j<c+1;j++){
                            String ts = String.valueOf(graph[i][j]);
                            sb.append(ts);
                            
                             if(j != c){
                            sb.append(" ");
                            }
                        }
                        System.out.println(new String(sb));
 
                    } {
                        StringBuilder sb = new StringBuilder();
                        for(int j=0;j<c+1;j++){
                            String ts = String.valueOf(graph[i][j]);
                            sb.append(ts);
                            
                             if(j != c){
                            sb.append(" ");
                            }
                        }
                        System.out.println(new String(sb));
 
                    } StringBuilder sb = new StringBuilder(); sb new StringBuilder() for(int j=0;j<c+1;j++){
                            String ts = String.valueOf(graph[i][j]);
                            sb.append(ts);
                            
                             if(j != c){
                            sb.append(" ");
                            }
                        } int j=0; int j=0; j 0 j<c+1 j c+1 c 1 j++ j++ j {
                            String ts = String.valueOf(graph[i][j]);
                            sb.append(ts);
                            
                             if(j != c){
                            sb.append(" ");
                            }
                        } {
                            String ts = String.valueOf(graph[i][j]);
                            sb.append(ts);
                            
                             if(j != c){
                            sb.append(" ");
                            }
                        } String ts = String.valueOf(graph[i][j]); ts String.valueOf(graph[i][j]) String.valueOf String graph[i][j] graph[i] graph i j sb.append(ts) sb.append sb ts if(j != c){
                            sb.append(" ");
                            } j != c j c {
                            sb.append(" ");
                            } sb.append(" ") sb.append sb " " System.out.println(new String(sb)) System.out.println System.out System System.out new String(sb) String[] args args public class Main{
  public static void main(String[] args)throws IOException{
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
 
String str = br.readLine();
                    String[] strs = str.split("\\s");
                    int r = Integer.parseInt(strs[0]);
                    int c = Integer.parseInt(strs[1]);
                    int[][] graph = new int[r+1][c+1];
                    int lastnum = 0;
 
                    for(int i = 0;i<r;i++){
                        str = br.readLine();
                        String[] temp = str.split("\\s");
                        int total =0;
 
                        for(int j =0;j<c;j++){
                            int tempnum = Integer.parseInt(temp[j]);
                            total += tempnum;
                            graph[i][j] = tempnum;
 
                            if(i == 0){
                                graph[r][j]= tempnum;
                            }else{
                                int tempnum2 = graph[r][j];
                                tempnum2 += tempnum;
                                graph[r][j]=tempnum2;
                            }
                        }
                        graph[i][c] = total;
                        lastnum += total;
                    }
                    br.close();
                    graph[r][c] = lastnum;
                     
                    for(int i =0;i<r+1;i++){
                        StringBuilder sb = new StringBuilder();
                        for(int j=0;j<c+1;j++){
                            String ts = String.valueOf(graph[i][j]);
                            sb.append(ts);
                            
                             if(j != c){
                            sb.append(" ");
                            }
                        }
                        System.out.println(new String(sb));
 
                    }
 
 
}
} public class Main{
  public static void main(String[] args)throws IOException{
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
 
String str = br.readLine();
                    String[] strs = str.split("\\s");
                    int r = Integer.parseInt(strs[0]);
                    int c = Integer.parseInt(strs[1]);
                    int[][] graph = new int[r+1][c+1];
                    int lastnum = 0;
 
                    for(int i = 0;i<r;i++){
                        str = br.readLine();
                        String[] temp = str.split("\\s");
                        int total =0;
 
                        for(int j =0;j<c;j++){
                            int tempnum = Integer.parseInt(temp[j]);
                            total += tempnum;
                            graph[i][j] = tempnum;
 
                            if(i == 0){
                                graph[r][j]= tempnum;
                            }else{
                                int tempnum2 = graph[r][j];
                                tempnum2 += tempnum;
                                graph[r][j]=tempnum2;
                            }
                        }
                        graph[i][c] = total;
                        lastnum += total;
                    }
                    br.close();
                    graph[r][c] = lastnum;
                     
                    for(int i =0;i<r+1;i++){
                        StringBuilder sb = new StringBuilder();
                        for(int j=0;j<c+1;j++){
                            String ts = String.valueOf(graph[i][j]);
                            sb.append(ts);
                            
                             if(j != c){
                            sb.append(" ");
                            }
                        }
                        System.out.println(new String(sb));
 
                    }
 
 
}
} Main
import java.util.*;
import java.io.*;
 
public class Main{
  public static void main(String[] args)throws IOException{
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
 
String str = br.readLine();
                    String[] strs = str.split("\\s");
                    int r = Integer.parseInt(strs[0]);
                    int c = Integer.parseInt(strs[1]);
                    int[][] graph = new int[r+1][c+1];
                    int lastnum = 0;
 
                    for(int i = 0;i<r;i++){
                        str = br.readLine();
                        String[] temp = str.split("\\s");
                        int total =0;
 
                        for(int j =0;j<c;j++){
                            int tempnum = Integer.parseInt(temp[j]);
                            total += tempnum;
                            graph[i][j] = tempnum;
 
                            if(i == 0){
                                graph[r][j]= tempnum;
                            }else{
                                int tempnum2 = graph[r][j];
                                tempnum2 += tempnum;
                                graph[r][j]=tempnum2;
                            }
                        }
                        graph[i][c] = total;
                        lastnum += total;
                    }
                    br.close();
                    graph[r][c] = lastnum;
                     
                    for(int i =0;i<r+1;i++){
                        StringBuilder sb = new StringBuilder();
                        for(int j=0;j<c+1;j++){
                            String ts = String.valueOf(graph[i][j]);
                            sb.append(ts);
                            
                             if(j != c){
                            sb.append(" ");
                            }
                        }
                        System.out.println(new String(sb));
 
                    }
 
 
}
}