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

public class Main {

	public static void main(String[] args) throws IOException {
		//入力処理
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer(br.readLine());
		int r=Integer.parseInt(st.nextToken());
		int c=Integer.parseInt(st.nextToken());

		//配列の作成・入力
		int[][] ary=new int[r][c];
		for(int j=0;j<r;j++) {
			StringTokenizer sa=new StringTokenizer(br.readLine());
			for(int i=0;i<c;i++) {
				int d=Integer.parseInt(sa.nextToken());
				ary[j][i]=d;
			}
		}

		//出力する配列作成
		int[][] Opary=new int[r+1][c+1];
		int sum=0;
		for(int j=0;j<r+1;j++) {
			for(int i=0;i<c+1;i++) {
				if(i==c && j==r) {
					for(int k=0;k<=r;k++) {
						sum=sum+Opary[k][i];
					}
					Opary[j][i]=sum;
					break;
				}
				if(j==r) {
					for(int k=0;k<=r;k++) {
						sum=sum+Opary[k][i];
					}
					Opary[j][i]=sum;
					sum=0;
					continue;
				}
				if(i==c && j!=r) {
					Opary[j][i]=sum;
					sum=0;
					continue;
				}
				Opary[j][i]=ary[j][i];
				sum=sum+Opary[j][i];
			}
		}

		//配列の出力
		for(int j=0;j<r+1;j++) {
			for(int i=0;i<c+1;i++) {
				System.out.print(Opary[j][i]);
				if(i==c) {
					break;
				}
				System.out.print(" ");
			}
			System.out.println();
		}
	}

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

	public static void main(String[] args) throws IOException {
		//入力処理
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer(br.readLine());
		int r=Integer.parseInt(st.nextToken());
		int c=Integer.parseInt(st.nextToken());

		//配列の作成・入力
		int[][] ary=new int[r][c];
		for(int j=0;j<r;j++) {
			StringTokenizer sa=new StringTokenizer(br.readLine());
			for(int i=0;i<c;i++) {
				int d=Integer.parseInt(sa.nextToken());
				ary[j][i]=d;
			}
		}

		//出力する配列作成
		int[][] Opary=new int[r+1][c+1];
		int sum=0;
		for(int j=0;j<r+1;j++) {
			for(int i=0;i<c+1;i++) {
				if(i==c && j==r) {
					for(int k=0;k<=r;k++) {
						sum=sum+Opary[k][i];
					}
					Opary[j][i]=sum;
					break;
				}
				if(j==r) {
					for(int k=0;k<=r;k++) {
						sum=sum+Opary[k][i];
					}
					Opary[j][i]=sum;
					sum=0;
					continue;
				}
				if(i==c && j!=r) {
					Opary[j][i]=sum;
					sum=0;
					continue;
				}
				Opary[j][i]=ary[j][i];
				sum=sum+Opary[j][i];
			}
		}

		//配列の出力
		for(int j=0;j<r+1;j++) {
			for(int i=0;i<c+1;i++) {
				System.out.print(Opary[j][i]);
				if(i==c) {
					break;
				}
				System.out.print(" ");
			}
			System.out.println();
		}
	}

} Main public static void main(String[] args) throws IOException {
		//入力処理
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer(br.readLine());
		int r=Integer.parseInt(st.nextToken());
		int c=Integer.parseInt(st.nextToken());

		//配列の作成・入力
		int[][] ary=new int[r][c];
		for(int j=0;j<r;j++) {
			StringTokenizer sa=new StringTokenizer(br.readLine());
			for(int i=0;i<c;i++) {
				int d=Integer.parseInt(sa.nextToken());
				ary[j][i]=d;
			}
		}

		//出力する配列作成
		int[][] Opary=new int[r+1][c+1];
		int sum=0;
		for(int j=0;j<r+1;j++) {
			for(int i=0;i<c+1;i++) {
				if(i==c && j==r) {
					for(int k=0;k<=r;k++) {
						sum=sum+Opary[k][i];
					}
					Opary[j][i]=sum;
					break;
				}
				if(j==r) {
					for(int k=0;k<=r;k++) {
						sum=sum+Opary[k][i];
					}
					Opary[j][i]=sum;
					sum=0;
					continue;
				}
				if(i==c && j!=r) {
					Opary[j][i]=sum;
					sum=0;
					continue;
				}
				Opary[j][i]=ary[j][i];
				sum=sum+Opary[j][i];
			}
		}

		//配列の出力
		for(int j=0;j<r+1;j++) {
			for(int i=0;i<c+1;i++) {
				System.out.print(Opary[j][i]);
				if(i==c) {
					break;
				}
				System.out.print(" ");
			}
			System.out.println();
		}
	} main {
		//入力処理
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer(br.readLine());
		int r=Integer.parseInt(st.nextToken());
		int c=Integer.parseInt(st.nextToken());

		//配列の作成・入力
		int[][] ary=new int[r][c];
		for(int j=0;j<r;j++) {
			StringTokenizer sa=new StringTokenizer(br.readLine());
			for(int i=0;i<c;i++) {
				int d=Integer.parseInt(sa.nextToken());
				ary[j][i]=d;
			}
		}

		//出力する配列作成
		int[][] Opary=new int[r+1][c+1];
		int sum=0;
		for(int j=0;j<r+1;j++) {
			for(int i=0;i<c+1;i++) {
				if(i==c && j==r) {
					for(int k=0;k<=r;k++) {
						sum=sum+Opary[k][i];
					}
					Opary[j][i]=sum;
					break;
				}
				if(j==r) {
					for(int k=0;k<=r;k++) {
						sum=sum+Opary[k][i];
					}
					Opary[j][i]=sum;
					sum=0;
					continue;
				}
				if(i==c && j!=r) {
					Opary[j][i]=sum;
					sum=0;
					continue;
				}
				Opary[j][i]=ary[j][i];
				sum=sum+Opary[j][i];
			}
		}

		//配列の出力
		for(int j=0;j<r+1;j++) {
			for(int i=0;i<c+1;i++) {
				System.out.print(Opary[j][i]);
				if(i==c) {
					break;
				}
				System.out.print(" ");
			}
			System.out.println();
		}
	} BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) StringTokenizer st=new StringTokenizer(br.readLine()); st new StringTokenizer(br.readLine()) int r=Integer.parseInt(st.nextToken()); r Integer.parseInt(st.nextToken()) Integer.parseInt Integer st.nextToken() st.nextToken st int c=Integer.parseInt(st.nextToken()); c Integer.parseInt(st.nextToken()) Integer.parseInt Integer st.nextToken() st.nextToken st int[][] ary=new int[r][c]; ary new int[r][c] r c for(int j=0;j<r;j++) {
			StringTokenizer sa=new StringTokenizer(br.readLine());
			for(int i=0;i<c;i++) {
				int d=Integer.parseInt(sa.nextToken());
				ary[j][i]=d;
			}
		} int j=0; int j=0; j 0 j<r j r j++ j++ j {
			StringTokenizer sa=new StringTokenizer(br.readLine());
			for(int i=0;i<c;i++) {
				int d=Integer.parseInt(sa.nextToken());
				ary[j][i]=d;
			}
		} {
			StringTokenizer sa=new StringTokenizer(br.readLine());
			for(int i=0;i<c;i++) {
				int d=Integer.parseInt(sa.nextToken());
				ary[j][i]=d;
			}
		} StringTokenizer sa=new StringTokenizer(br.readLine()); sa new StringTokenizer(br.readLine()) for(int i=0;i<c;i++) {
				int d=Integer.parseInt(sa.nextToken());
				ary[j][i]=d;
			} int i=0; int i=0; i 0 i<c i c i++ i++ i {
				int d=Integer.parseInt(sa.nextToken());
				ary[j][i]=d;
			} {
				int d=Integer.parseInt(sa.nextToken());
				ary[j][i]=d;
			} int d=Integer.parseInt(sa.nextToken()); d Integer.parseInt(sa.nextToken()) Integer.parseInt Integer sa.nextToken() sa.nextToken sa ary[j][i]=d ary[j][i] ary[j] ary j i d int[][] Opary=new int[r+1][c+1]; Opary new int[r+1][c+1] r+1 r 1 c+1 c 1 int sum=0; sum 0 for(int j=0;j<r+1;j++) {
			for(int i=0;i<c+1;i++) {
				if(i==c && j==r) {
					for(int k=0;k<=r;k++) {
						sum=sum+Opary[k][i];
					}
					Opary[j][i]=sum;
					break;
				}
				if(j==r) {
					for(int k=0;k<=r;k++) {
						sum=sum+Opary[k][i];
					}
					Opary[j][i]=sum;
					sum=0;
					continue;
				}
				if(i==c && j!=r) {
					Opary[j][i]=sum;
					sum=0;
					continue;
				}
				Opary[j][i]=ary[j][i];
				sum=sum+Opary[j][i];
			}
		} int j=0; int j=0; j 0 j<r+1 j r+1 r 1 j++ j++ j {
			for(int i=0;i<c+1;i++) {
				if(i==c && j==r) {
					for(int k=0;k<=r;k++) {
						sum=sum+Opary[k][i];
					}
					Opary[j][i]=sum;
					break;
				}
				if(j==r) {
					for(int k=0;k<=r;k++) {
						sum=sum+Opary[k][i];
					}
					Opary[j][i]=sum;
					sum=0;
					continue;
				}
				if(i==c && j!=r) {
					Opary[j][i]=sum;
					sum=0;
					continue;
				}
				Opary[j][i]=ary[j][i];
				sum=sum+Opary[j][i];
			}
		} {
			for(int i=0;i<c+1;i++) {
				if(i==c && j==r) {
					for(int k=0;k<=r;k++) {
						sum=sum+Opary[k][i];
					}
					Opary[j][i]=sum;
					break;
				}
				if(j==r) {
					for(int k=0;k<=r;k++) {
						sum=sum+Opary[k][i];
					}
					Opary[j][i]=sum;
					sum=0;
					continue;
				}
				if(i==c && j!=r) {
					Opary[j][i]=sum;
					sum=0;
					continue;
				}
				Opary[j][i]=ary[j][i];
				sum=sum+Opary[j][i];
			}
		} for(int i=0;i<c+1;i++) {
				if(i==c && j==r) {
					for(int k=0;k<=r;k++) {
						sum=sum+Opary[k][i];
					}
					Opary[j][i]=sum;
					break;
				}
				if(j==r) {
					for(int k=0;k<=r;k++) {
						sum=sum+Opary[k][i];
					}
					Opary[j][i]=sum;
					sum=0;
					continue;
				}
				if(i==c && j!=r) {
					Opary[j][i]=sum;
					sum=0;
					continue;
				}
				Opary[j][i]=ary[j][i];
				sum=sum+Opary[j][i];
			} int i=0; int i=0; i 0 i<c+1 i c+1 c 1 i++ i++ i {
				if(i==c && j==r) {
					for(int k=0;k<=r;k++) {
						sum=sum+Opary[k][i];
					}
					Opary[j][i]=sum;
					break;
				}
				if(j==r) {
					for(int k=0;k<=r;k++) {
						sum=sum+Opary[k][i];
					}
					Opary[j][i]=sum;
					sum=0;
					continue;
				}
				if(i==c && j!=r) {
					Opary[j][i]=sum;
					sum=0;
					continue;
				}
				Opary[j][i]=ary[j][i];
				sum=sum+Opary[j][i];
			} {
				if(i==c && j==r) {
					for(int k=0;k<=r;k++) {
						sum=sum+Opary[k][i];
					}
					Opary[j][i]=sum;
					break;
				}
				if(j==r) {
					for(int k=0;k<=r;k++) {
						sum=sum+Opary[k][i];
					}
					Opary[j][i]=sum;
					sum=0;
					continue;
				}
				if(i==c && j!=r) {
					Opary[j][i]=sum;
					sum=0;
					continue;
				}
				Opary[j][i]=ary[j][i];
				sum=sum+Opary[j][i];
			} if(i==c && j==r) {
					for(int k=0;k<=r;k++) {
						sum=sum+Opary[k][i];
					}
					Opary[j][i]=sum;
					break;
				} i==c && j==r i==c i c j==r j r {
					for(int k=0;k<=r;k++) {
						sum=sum+Opary[k][i];
					}
					Opary[j][i]=sum;
					break;
				} for(int k=0;k<=r;k++) {
						sum=sum+Opary[k][i];
					} int k=0; int k=0; k 0 k<=r k r k++ k++ k {
						sum=sum+Opary[k][i];
					} {
						sum=sum+Opary[k][i];
					} sum=sum+Opary[k][i] sum sum+Opary[k][i] sum Opary[k][i] Opary[k] Opary k i Opary[j][i]=sum Opary[j][i] Opary[j] Opary j i sum break; if(j==r) {
					for(int k=0;k<=r;k++) {
						sum=sum+Opary[k][i];
					}
					Opary[j][i]=sum;
					sum=0;
					continue;
				} j==r j r {
					for(int k=0;k<=r;k++) {
						sum=sum+Opary[k][i];
					}
					Opary[j][i]=sum;
					sum=0;
					continue;
				} for(int k=0;k<=r;k++) {
						sum=sum+Opary[k][i];
					} int k=0; int k=0; k 0 k<=r k r k++ k++ k {
						sum=sum+Opary[k][i];
					} {
						sum=sum+Opary[k][i];
					} sum=sum+Opary[k][i] sum sum+Opary[k][i] sum Opary[k][i] Opary[k] Opary k i Opary[j][i]=sum Opary[j][i] Opary[j] Opary j i sum sum=0 sum 0 continue; if(i==c && j!=r) {
					Opary[j][i]=sum;
					sum=0;
					continue;
				} i==c && j!=r i==c i c j!=r j r {
					Opary[j][i]=sum;
					sum=0;
					continue;
				} Opary[j][i]=sum Opary[j][i] Opary[j] Opary j i sum sum=0 sum 0 continue; Opary[j][i]=ary[j][i] Opary[j][i] Opary[j] Opary j i ary[j][i] ary[j] ary j i sum=sum+Opary[j][i] sum sum+Opary[j][i] sum Opary[j][i] Opary[j] Opary j i for(int j=0;j<r+1;j++) {
			for(int i=0;i<c+1;i++) {
				System.out.print(Opary[j][i]);
				if(i==c) {
					break;
				}
				System.out.print(" ");
			}
			System.out.println();
		} int j=0; int j=0; j 0 j<r+1 j r+1 r 1 j++ j++ j {
			for(int i=0;i<c+1;i++) {
				System.out.print(Opary[j][i]);
				if(i==c) {
					break;
				}
				System.out.print(" ");
			}
			System.out.println();
		} {
			for(int i=0;i<c+1;i++) {
				System.out.print(Opary[j][i]);
				if(i==c) {
					break;
				}
				System.out.print(" ");
			}
			System.out.println();
		} for(int i=0;i<c+1;i++) {
				System.out.print(Opary[j][i]);
				if(i==c) {
					break;
				}
				System.out.print(" ");
			} int i=0; int i=0; i 0 i<c+1 i c+1 c 1 i++ i++ i {
				System.out.print(Opary[j][i]);
				if(i==c) {
					break;
				}
				System.out.print(" ");
			} {
				System.out.print(Opary[j][i]);
				if(i==c) {
					break;
				}
				System.out.print(" ");
			} System.out.print(Opary[j][i]) System.out.print System.out System System.out Opary[j][i] Opary[j] Opary j i if(i==c) {
					break;
				} i==c i c {
					break;
				} break; System.out.print(" ") System.out.print System.out System System.out " " System.out.println() System.out.println System.out System System.out String[] args args public class Main {

	public static void main(String[] args) throws IOException {
		//入力処理
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer(br.readLine());
		int r=Integer.parseInt(st.nextToken());
		int c=Integer.parseInt(st.nextToken());

		//配列の作成・入力
		int[][] ary=new int[r][c];
		for(int j=0;j<r;j++) {
			StringTokenizer sa=new StringTokenizer(br.readLine());
			for(int i=0;i<c;i++) {
				int d=Integer.parseInt(sa.nextToken());
				ary[j][i]=d;
			}
		}

		//出力する配列作成
		int[][] Opary=new int[r+1][c+1];
		int sum=0;
		for(int j=0;j<r+1;j++) {
			for(int i=0;i<c+1;i++) {
				if(i==c && j==r) {
					for(int k=0;k<=r;k++) {
						sum=sum+Opary[k][i];
					}
					Opary[j][i]=sum;
					break;
				}
				if(j==r) {
					for(int k=0;k<=r;k++) {
						sum=sum+Opary[k][i];
					}
					Opary[j][i]=sum;
					sum=0;
					continue;
				}
				if(i==c && j!=r) {
					Opary[j][i]=sum;
					sum=0;
					continue;
				}
				Opary[j][i]=ary[j][i];
				sum=sum+Opary[j][i];
			}
		}

		//配列の出力
		for(int j=0;j<r+1;j++) {
			for(int i=0;i<c+1;i++) {
				System.out.print(Opary[j][i]);
				if(i==c) {
					break;
				}
				System.out.print(" ");
			}
			System.out.println();
		}
	}

} public class Main {

	public static void main(String[] args) throws IOException {
		//入力処理
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer(br.readLine());
		int r=Integer.parseInt(st.nextToken());
		int c=Integer.parseInt(st.nextToken());

		//配列の作成・入力
		int[][] ary=new int[r][c];
		for(int j=0;j<r;j++) {
			StringTokenizer sa=new StringTokenizer(br.readLine());
			for(int i=0;i<c;i++) {
				int d=Integer.parseInt(sa.nextToken());
				ary[j][i]=d;
			}
		}

		//出力する配列作成
		int[][] Opary=new int[r+1][c+1];
		int sum=0;
		for(int j=0;j<r+1;j++) {
			for(int i=0;i<c+1;i++) {
				if(i==c && j==r) {
					for(int k=0;k<=r;k++) {
						sum=sum+Opary[k][i];
					}
					Opary[j][i]=sum;
					break;
				}
				if(j==r) {
					for(int k=0;k<=r;k++) {
						sum=sum+Opary[k][i];
					}
					Opary[j][i]=sum;
					sum=0;
					continue;
				}
				if(i==c && j!=r) {
					Opary[j][i]=sum;
					sum=0;
					continue;
				}
				Opary[j][i]=ary[j][i];
				sum=sum+Opary[j][i];
			}
		}

		//配列の出力
		for(int j=0;j<r+1;j++) {
			for(int i=0;i<c+1;i++) {
				System.out.print(Opary[j][i]);
				if(i==c) {
					break;
				}
				System.out.print(" ");
			}
			System.out.println();
		}
	}

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

public class Main {

	public static void main(String[] args) throws IOException {
		//入力処理
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer(br.readLine());
		int r=Integer.parseInt(st.nextToken());
		int c=Integer.parseInt(st.nextToken());

		//配列の作成・入力
		int[][] ary=new int[r][c];
		for(int j=0;j<r;j++) {
			StringTokenizer sa=new StringTokenizer(br.readLine());
			for(int i=0;i<c;i++) {
				int d=Integer.parseInt(sa.nextToken());
				ary[j][i]=d;
			}
		}

		//出力する配列作成
		int[][] Opary=new int[r+1][c+1];
		int sum=0;
		for(int j=0;j<r+1;j++) {
			for(int i=0;i<c+1;i++) {
				if(i==c && j==r) {
					for(int k=0;k<=r;k++) {
						sum=sum+Opary[k][i];
					}
					Opary[j][i]=sum;
					break;
				}
				if(j==r) {
					for(int k=0;k<=r;k++) {
						sum=sum+Opary[k][i];
					}
					Opary[j][i]=sum;
					sum=0;
					continue;
				}
				if(i==c && j!=r) {
					Opary[j][i]=sum;
					sum=0;
					continue;
				}
				Opary[j][i]=ary[j][i];
				sum=sum+Opary[j][i];
			}
		}

		//配列の出力
		for(int j=0;j<r+1;j++) {
			for(int i=0;i<c+1;i++) {
				System.out.print(Opary[j][i]);
				if(i==c) {
					break;
				}
				System.out.print(" ");
			}
			System.out.println();
		}
	}

}

