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

public class Main {

	public static void main(String[] args) throws Exception {
        // TODO ?????????????????????????????????????????????
        
        boolean first=true;
        try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
            String line;
            int i=0,n=0,m=0;
            int[][] card=null;
            while ((line = br.readLine()) != null) {
            	String[] str=line.split(" ");
            	if(first){
            		n=Integer.parseInt(str[0]);
            		m=Integer.parseInt(str[1]);
            		card=new int[n+1][m+1];
            		first=false;
            	}else{
            		int sum=0;
            		for(int j=0;j<m;j++){
            			card[i][j]=Integer.parseInt(str[j]);
            			card[n][j]+=Integer.parseInt(str[j]);
            			sum+=card[i][j];
            		}
            		card[i][m]=sum;
            		
            		i++;
            		if(i==n){
            			for(int j=0;j<n;j++){
            				card[n][m]+=card[j][m];
            			}
            			for(int j=0;j<n+1;j++){
            				for(int k=0;k<m+1;k++){
                    			System.out.print(card[j][k]);
                    			if(k!=m)System.out.print(" ");
                    		}
            				System.out.println();
                		}
            		}
            	}
            }
        }
    }

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

	public static void main(String[] args) throws Exception {
        // TODO ?????????????????????????????????????????????
        
        boolean first=true;
        try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
            String line;
            int i=0,n=0,m=0;
            int[][] card=null;
            while ((line = br.readLine()) != null) {
            	String[] str=line.split(" ");
            	if(first){
            		n=Integer.parseInt(str[0]);
            		m=Integer.parseInt(str[1]);
            		card=new int[n+1][m+1];
            		first=false;
            	}else{
            		int sum=0;
            		for(int j=0;j<m;j++){
            			card[i][j]=Integer.parseInt(str[j]);
            			card[n][j]+=Integer.parseInt(str[j]);
            			sum+=card[i][j];
            		}
            		card[i][m]=sum;
            		
            		i++;
            		if(i==n){
            			for(int j=0;j<n;j++){
            				card[n][m]+=card[j][m];
            			}
            			for(int j=0;j<n+1;j++){
            				for(int k=0;k<m+1;k++){
                    			System.out.print(card[j][k]);
                    			if(k!=m)System.out.print(" ");
                    		}
            				System.out.println();
                		}
            		}
            	}
            }
        }
    }

} Main public static void main(String[] args) throws Exception {
        // TODO ?????????????????????????????????????????????
        
        boolean first=true;
        try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
            String line;
            int i=0,n=0,m=0;
            int[][] card=null;
            while ((line = br.readLine()) != null) {
            	String[] str=line.split(" ");
            	if(first){
            		n=Integer.parseInt(str[0]);
            		m=Integer.parseInt(str[1]);
            		card=new int[n+1][m+1];
            		first=false;
            	}else{
            		int sum=0;
            		for(int j=0;j<m;j++){
            			card[i][j]=Integer.parseInt(str[j]);
            			card[n][j]+=Integer.parseInt(str[j]);
            			sum+=card[i][j];
            		}
            		card[i][m]=sum;
            		
            		i++;
            		if(i==n){
            			for(int j=0;j<n;j++){
            				card[n][m]+=card[j][m];
            			}
            			for(int j=0;j<n+1;j++){
            				for(int k=0;k<m+1;k++){
                    			System.out.print(card[j][k]);
                    			if(k!=m)System.out.print(" ");
                    		}
            				System.out.println();
                		}
            		}
            	}
            }
        }
    } main {
        // TODO ?????????????????????????????????????????????
        
        boolean first=true;
        try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
            String line;
            int i=0,n=0,m=0;
            int[][] card=null;
            while ((line = br.readLine()) != null) {
            	String[] str=line.split(" ");
            	if(first){
            		n=Integer.parseInt(str[0]);
            		m=Integer.parseInt(str[1]);
            		card=new int[n+1][m+1];
            		first=false;
            	}else{
            		int sum=0;
            		for(int j=0;j<m;j++){
            			card[i][j]=Integer.parseInt(str[j]);
            			card[n][j]+=Integer.parseInt(str[j]);
            			sum+=card[i][j];
            		}
            		card[i][m]=sum;
            		
            		i++;
            		if(i==n){
            			for(int j=0;j<n;j++){
            				card[n][m]+=card[j][m];
            			}
            			for(int j=0;j<n+1;j++){
            				for(int k=0;k<m+1;k++){
                    			System.out.print(card[j][k]);
                    			if(k!=m)System.out.print(" ");
                    		}
            				System.out.println();
                		}
            		}
            	}
            }
        }
    } boolean first=true; first true try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
            String line;
            int i=0,n=0,m=0;
            int[][] card=null;
            while ((line = br.readLine()) != null) {
            	String[] str=line.split(" ");
            	if(first){
            		n=Integer.parseInt(str[0]);
            		m=Integer.parseInt(str[1]);
            		card=new int[n+1][m+1];
            		first=false;
            	}else{
            		int sum=0;
            		for(int j=0;j<m;j++){
            			card[i][j]=Integer.parseInt(str[j]);
            			card[n][j]+=Integer.parseInt(str[j]);
            			sum+=card[i][j];
            		}
            		card[i][m]=sum;
            		
            		i++;
            		if(i==n){
            			for(int j=0;j<n;j++){
            				card[n][m]+=card[j][m];
            			}
            			for(int j=0;j<n+1;j++){
            				for(int k=0;k<m+1;k++){
                    			System.out.print(card[j][k]);
                    			if(k!=m)System.out.print(" ");
                    		}
            				System.out.println();
                		}
            		}
            	}
            }
        } {
            String line;
            int i=0,n=0,m=0;
            int[][] card=null;
            while ((line = br.readLine()) != null) {
            	String[] str=line.split(" ");
            	if(first){
            		n=Integer.parseInt(str[0]);
            		m=Integer.parseInt(str[1]);
            		card=new int[n+1][m+1];
            		first=false;
            	}else{
            		int sum=0;
            		for(int j=0;j<m;j++){
            			card[i][j]=Integer.parseInt(str[j]);
            			card[n][j]+=Integer.parseInt(str[j]);
            			sum+=card[i][j];
            		}
            		card[i][m]=sum;
            		
            		i++;
            		if(i==n){
            			for(int j=0;j<n;j++){
            				card[n][m]+=card[j][m];
            			}
            			for(int j=0;j<n+1;j++){
            				for(int k=0;k<m+1;k++){
                    			System.out.print(card[j][k]);
                    			if(k!=m)System.out.print(" ");
                    		}
            				System.out.println();
                		}
            		}
            	}
            }
        } BufferedReader br = new BufferedReader(new InputStreamReader(System.in)) BufferedReader br = new BufferedReader(new InputStreamReader(System.in)) new BufferedReader(new InputStreamReader(System.in)) String line; line int i=0 i 0 n=0 n 0 m=0; m 0 int[][] card=null; card null while ((line = br.readLine()) != null) {
            	String[] str=line.split(" ");
            	if(first){
            		n=Integer.parseInt(str[0]);
            		m=Integer.parseInt(str[1]);
            		card=new int[n+1][m+1];
            		first=false;
            	}else{
            		int sum=0;
            		for(int j=0;j<m;j++){
            			card[i][j]=Integer.parseInt(str[j]);
            			card[n][j]+=Integer.parseInt(str[j]);
            			sum+=card[i][j];
            		}
            		card[i][m]=sum;
            		
            		i++;
            		if(i==n){
            			for(int j=0;j<n;j++){
            				card[n][m]+=card[j][m];
            			}
            			for(int j=0;j<n+1;j++){
            				for(int k=0;k<m+1;k++){
                    			System.out.print(card[j][k]);
                    			if(k!=m)System.out.print(" ");
                    		}
            				System.out.println();
                		}
            		}
            	}
            } (line = br.readLine()) != null (line = br.readLine()) line br.readLine() br.readLine br null {
            	String[] str=line.split(" ");
            	if(first){
            		n=Integer.parseInt(str[0]);
            		m=Integer.parseInt(str[1]);
            		card=new int[n+1][m+1];
            		first=false;
            	}else{
            		int sum=0;
            		for(int j=0;j<m;j++){
            			card[i][j]=Integer.parseInt(str[j]);
            			card[n][j]+=Integer.parseInt(str[j]);
            			sum+=card[i][j];
            		}
            		card[i][m]=sum;
            		
            		i++;
            		if(i==n){
            			for(int j=0;j<n;j++){
            				card[n][m]+=card[j][m];
            			}
            			for(int j=0;j<n+1;j++){
            				for(int k=0;k<m+1;k++){
                    			System.out.print(card[j][k]);
                    			if(k!=m)System.out.print(" ");
                    		}
            				System.out.println();
                		}
            		}
            	}
            } String[] str=line.split(" "); str line.split(" ") line.split line " " if(first){
            		n=Integer.parseInt(str[0]);
            		m=Integer.parseInt(str[1]);
            		card=new int[n+1][m+1];
            		first=false;
            	}else{
            		int sum=0;
            		for(int j=0;j<m;j++){
            			card[i][j]=Integer.parseInt(str[j]);
            			card[n][j]+=Integer.parseInt(str[j]);
            			sum+=card[i][j];
            		}
            		card[i][m]=sum;
            		
            		i++;
            		if(i==n){
            			for(int j=0;j<n;j++){
            				card[n][m]+=card[j][m];
            			}
            			for(int j=0;j<n+1;j++){
            				for(int k=0;k<m+1;k++){
                    			System.out.print(card[j][k]);
                    			if(k!=m)System.out.print(" ");
                    		}
            				System.out.println();
                		}
            		}
            	} first {
            		n=Integer.parseInt(str[0]);
            		m=Integer.parseInt(str[1]);
            		card=new int[n+1][m+1];
            		first=false;
            	} n=Integer.parseInt(str[0]) n Integer.parseInt(str[0]) Integer.parseInt Integer str[0] str 0 m=Integer.parseInt(str[1]) m Integer.parseInt(str[1]) Integer.parseInt Integer str[1] str 1 card=new int[n+1][m+1] card new int[n+1][m+1] n+1 n 1 m+1 m 1 first=false first false {
            		int sum=0;
            		for(int j=0;j<m;j++){
            			card[i][j]=Integer.parseInt(str[j]);
            			card[n][j]+=Integer.parseInt(str[j]);
            			sum+=card[i][j];
            		}
            		card[i][m]=sum;
            		
            		i++;
            		if(i==n){
            			for(int j=0;j<n;j++){
            				card[n][m]+=card[j][m];
            			}
            			for(int j=0;j<n+1;j++){
            				for(int k=0;k<m+1;k++){
                    			System.out.print(card[j][k]);
                    			if(k!=m)System.out.print(" ");
                    		}
            				System.out.println();
                		}
            		}
            	} int sum=0; sum 0 for(int j=0;j<m;j++){
            			card[i][j]=Integer.parseInt(str[j]);
            			card[n][j]+=Integer.parseInt(str[j]);
            			sum+=card[i][j];
            		} int j=0; int j=0; j 0 j<m j m j++ j++ j {
            			card[i][j]=Integer.parseInt(str[j]);
            			card[n][j]+=Integer.parseInt(str[j]);
            			sum+=card[i][j];
            		} {
            			card[i][j]=Integer.parseInt(str[j]);
            			card[n][j]+=Integer.parseInt(str[j]);
            			sum+=card[i][j];
            		} card[i][j]=Integer.parseInt(str[j]) card[i][j] card[i] card i j Integer.parseInt(str[j]) Integer.parseInt Integer str[j] str j card[n][j]+=Integer.parseInt(str[j]) card[n][j] card[n] card n j Integer.parseInt(str[j]) Integer.parseInt Integer str[j] str j sum+=card[i][j] sum card[i][j] card[i] card i j card[i][m]=sum card[i][m] card[i] card i m sum i++ i if(i==n){
            			for(int j=0;j<n;j++){
            				card[n][m]+=card[j][m];
            			}
            			for(int j=0;j<n+1;j++){
            				for(int k=0;k<m+1;k++){
                    			System.out.print(card[j][k]);
                    			if(k!=m)System.out.print(" ");
                    		}
            				System.out.println();
                		}
            		} i==n i n {
            			for(int j=0;j<n;j++){
            				card[n][m]+=card[j][m];
            			}
            			for(int j=0;j<n+1;j++){
            				for(int k=0;k<m+1;k++){
                    			System.out.print(card[j][k]);
                    			if(k!=m)System.out.print(" ");
                    		}
            				System.out.println();
                		}
            		} for(int j=0;j<n;j++){
            				card[n][m]+=card[j][m];
            			} int j=0; int j=0; j 0 j<n j n j++ j++ j {
            				card[n][m]+=card[j][m];
            			} {
            				card[n][m]+=card[j][m];
            			} card[n][m]+=card[j][m] card[n][m] card[n] card n m card[j][m] card[j] card j m for(int j=0;j<n+1;j++){
            				for(int k=0;k<m+1;k++){
                    			System.out.print(card[j][k]);
                    			if(k!=m)System.out.print(" ");
                    		}
            				System.out.println();
                		} int j=0; int j=0; j 0 j<n+1 j n+1 n 1 j++ j++ j {
            				for(int k=0;k<m+1;k++){
                    			System.out.print(card[j][k]);
                    			if(k!=m)System.out.print(" ");
                    		}
            				System.out.println();
                		} {
            				for(int k=0;k<m+1;k++){
                    			System.out.print(card[j][k]);
                    			if(k!=m)System.out.print(" ");
                    		}
            				System.out.println();
                		} for(int k=0;k<m+1;k++){
                    			System.out.print(card[j][k]);
                    			if(k!=m)System.out.print(" ");
                    		} int k=0; int k=0; k 0 k<m+1 k m+1 m 1 k++ k++ k {
                    			System.out.print(card[j][k]);
                    			if(k!=m)System.out.print(" ");
                    		} {
                    			System.out.print(card[j][k]);
                    			if(k!=m)System.out.print(" ");
                    		} System.out.print(card[j][k]) System.out.print System.out System System.out card[j][k] card[j] card j k if(k!=m)System.out.print(" "); k!=m k m 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 Exception {
        // TODO ?????????????????????????????????????????????
        
        boolean first=true;
        try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
            String line;
            int i=0,n=0,m=0;
            int[][] card=null;
            while ((line = br.readLine()) != null) {
            	String[] str=line.split(" ");
            	if(first){
            		n=Integer.parseInt(str[0]);
            		m=Integer.parseInt(str[1]);
            		card=new int[n+1][m+1];
            		first=false;
            	}else{
            		int sum=0;
            		for(int j=0;j<m;j++){
            			card[i][j]=Integer.parseInt(str[j]);
            			card[n][j]+=Integer.parseInt(str[j]);
            			sum+=card[i][j];
            		}
            		card[i][m]=sum;
            		
            		i++;
            		if(i==n){
            			for(int j=0;j<n;j++){
            				card[n][m]+=card[j][m];
            			}
            			for(int j=0;j<n+1;j++){
            				for(int k=0;k<m+1;k++){
                    			System.out.print(card[j][k]);
                    			if(k!=m)System.out.print(" ");
                    		}
            				System.out.println();
                		}
            		}
            	}
            }
        }
    }

} public class Main {

	public static void main(String[] args) throws Exception {
        // TODO ?????????????????????????????????????????????
        
        boolean first=true;
        try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
            String line;
            int i=0,n=0,m=0;
            int[][] card=null;
            while ((line = br.readLine()) != null) {
            	String[] str=line.split(" ");
            	if(first){
            		n=Integer.parseInt(str[0]);
            		m=Integer.parseInt(str[1]);
            		card=new int[n+1][m+1];
            		first=false;
            	}else{
            		int sum=0;
            		for(int j=0;j<m;j++){
            			card[i][j]=Integer.parseInt(str[j]);
            			card[n][j]+=Integer.parseInt(str[j]);
            			sum+=card[i][j];
            		}
            		card[i][m]=sum;
            		
            		i++;
            		if(i==n){
            			for(int j=0;j<n;j++){
            				card[n][m]+=card[j][m];
            			}
            			for(int j=0;j<n+1;j++){
            				for(int k=0;k<m+1;k++){
                    			System.out.print(card[j][k]);
                    			if(k!=m)System.out.print(" ");
                    		}
            				System.out.println();
                		}
            		}
            	}
            }
        }
    }

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

public class Main {

	public static void main(String[] args) throws Exception {
        // TODO ?????????????????????????????????????????????
        
        boolean first=true;
        try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
            String line;
            int i=0,n=0,m=0;
            int[][] card=null;
            while ((line = br.readLine()) != null) {
            	String[] str=line.split(" ");
            	if(first){
            		n=Integer.parseInt(str[0]);
            		m=Integer.parseInt(str[1]);
            		card=new int[n+1][m+1];
            		first=false;
            	}else{
            		int sum=0;
            		for(int j=0;j<m;j++){
            			card[i][j]=Integer.parseInt(str[j]);
            			card[n][j]+=Integer.parseInt(str[j]);
            			sum+=card[i][j];
            		}
            		card[i][m]=sum;
            		
            		i++;
            		if(i==n){
            			for(int j=0;j<n;j++){
            				card[n][m]+=card[j][m];
            			}
            			for(int j=0;j<n+1;j++){
            				for(int k=0;k<m+1;k++){
                    			System.out.print(card[j][k]);
                    			if(k!=m)System.out.print(" ");
                    		}
            				System.out.println();
                		}
            		}
            	}
            }
        }
    }

}