import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int retu = scanner.nextInt();
        int gyou = scanner.nextInt();
        int[][] shuturyoku = new int[(retu + 1)][(gyou + 1)];

        for (int i = 1; retu >= i; i++) {
            for (int j = 1; gyou >= j; j++) {
                int a = scanner.nextInt();
                shuturyoku[i - 1][j - 1] = a;
            }
        }
        for (int i = 1; retu >= i; i++) {
            for (int j = 1; gyou >= j; j++) {
                shuturyoku[i - 1][gyou] += shuturyoku[i - 1][j - 1];
            }
        }
        for (int i = 1; retu >= i; i++) {
            for (int j = 1; gyou >= j; j++) {
                shuturyoku[retu][j - 1] += shuturyoku[i - 1][j - 1];
            }
        }
        for (int i = 1; retu >= i; i++) {
            shuturyoku[retu][gyou] += shuturyoku[i-1][gyou];
        }
        for (int i = 1; retu + 1 >= i; i++) {
            for (int j = 1; gyou + 1 >= j; j++) {
                if (j != gyou+1) {
                    System.out.print(shuturyoku[i - 1][j - 1] + " ");
                } else {
                    System.out.println(shuturyoku[i - 1][j - 1]);
                }
            }
        }
    }
}
/tmp/hf-datasets-cache/medium/datasets/42704881117311-config-parquet-and-info-qiankunmu-Project_CodeNet-896c9d36/hub/datasets--qiankunmu--Project_CodeNet_Python800_and_Java250/snapshots/c899fde44a77ba1cc14973ed3de064e4ff3aadc7/Project_CodeNet_Java250.tar.gz