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

public class Main {
  static InputReader in;
  static PrintWriter out;

  static class Solution {
    void solve() throws IOException {
        int r = in.nextInt();
        int c = in.nextInt();
        int sum = 0;
        int[][] sheet = new int[r][c]; 
        int[] sumofrow = new int[r];
        int[] sumofcolumn = new int[c];
        
        for (int i = 0; i < r; i++) {
          for (int j = 0; j < c; j++) {
            sheet[i][j] = in.nextInt();
            sum += sheet[i][j];
          }
        }
        
        for (int i = 0; i < r; i++) {
          for (int j = 0; j < c; j++) {
            sumofrow[i] += sheet[i][j];
            sumofcolumn[j] += sheet[i][j];
          }
        }
        
        for (int i = 0; i < r; i++) {
          for (int j = 0; j < c; j++) {
            out.print(sheet[i][j] + " ");
          }
          out.println(sumofrow[i]);
        }
        
        for (int i = 0; i < c; i++) {
          out.print(sumofcolumn[i] + " ");
        }
        
        out.println(sum);
        
//      End solve()
    }
//    End Solution
}

  public static void main(String[] args) throws IOException {
    in = new InputReader(System.in);
    out = new PrintWriter(System.out);
    Solution solver = new Solution();
    solver.solve();
    out.close();
}

  static class InputReader {
    public BufferedReader br;
    public StringTokenizer st;

    public InputReader(InputStream stream) {
      br = new BufferedReader(new InputStreamReader(stream));
    }

    public int nextInt() throws IOException {
      while (st == null || !st.hasMoreTokens()) {
        st = new StringTokenizer(br.readLine());
      }
      return Integer.parseInt(st.nextToken());
    }

    public long nextLong() throws IOException {
      while (st == null || !st.hasMoreTokens()) {
        st = new StringTokenizer(br.readLine());
      }
      return Long.parseLong(st.nextToken());
    }

    public String next() throws IOException {
      while (st == null || !st.hasMoreTokens()) {
        st = new StringTokenizer(br.readLine());
      }
      return st.nextToken();
    }

    public double nextDouble() throws IOException {
      while (st == null || !st.hasMoreTokens()) {
        st = new StringTokenizer(br.readLine());
      }
      return Double.parseDouble(st.nextToken());
    }


  }

} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStream; InputStream java.io import java.io.InputStreamReader; InputStreamReader java.io import java.io.PrintWriter; PrintWriter java.io import java.util.StringTokenizer; StringTokenizer java.util public class Main {
  static InputReader in;
  static PrintWriter out;

  static class Solution {
    void solve() throws IOException {
        int r = in.nextInt();
        int c = in.nextInt();
        int sum = 0;
        int[][] sheet = new int[r][c]; 
        int[] sumofrow = new int[r];
        int[] sumofcolumn = new int[c];
        
        for (int i = 0; i < r; i++) {
          for (int j = 0; j < c; j++) {
            sheet[i][j] = in.nextInt();
            sum += sheet[i][j];
          }
        }
        
        for (int i = 0; i < r; i++) {
          for (int j = 0; j < c; j++) {
            sumofrow[i] += sheet[i][j];
            sumofcolumn[j] += sheet[i][j];
          }
        }
        
        for (int i = 0; i < r; i++) {
          for (int j = 0; j < c; j++) {
            out.print(sheet[i][j] + " ");
          }
          out.println(sumofrow[i]);
        }
        
        for (int i = 0; i < c; i++) {
          out.print(sumofcolumn[i] + " ");
        }
        
        out.println(sum);
        
//      End solve()
    }
//    End Solution
}

  public static void main(String[] args) throws IOException {
    in = new InputReader(System.in);
    out = new PrintWriter(System.out);
    Solution solver = new Solution();
    solver.solve();
    out.close();
}

  static class InputReader {
    public BufferedReader br;
    public StringTokenizer st;

    public InputReader(InputStream stream) {
      br = new BufferedReader(new InputStreamReader(stream));
    }

    public int nextInt() throws IOException {
      while (st == null || !st.hasMoreTokens()) {
        st = new StringTokenizer(br.readLine());
      }
      return Integer.parseInt(st.nextToken());
    }

    public long nextLong() throws IOException {
      while (st == null || !st.hasMoreTokens()) {
        st = new StringTokenizer(br.readLine());
      }
      return Long.parseLong(st.nextToken());
    }

    public String next() throws IOException {
      while (st == null || !st.hasMoreTokens()) {
        st = new StringTokenizer(br.readLine());
      }
      return st.nextToken();
    }

    public double nextDouble() throws IOException {
      while (st == null || !st.hasMoreTokens()) {
        st = new StringTokenizer(br.readLine());
      }
      return Double.parseDouble(st.nextToken());
    }


  }

} Main static InputReader in; in static PrintWriter out; out public static void main(String[] args) throws IOException {
    in = new InputReader(System.in);
    out = new PrintWriter(System.out);
    Solution solver = new Solution();
    solver.solve();
    out.close();
} main {
    in = new InputReader(System.in);
    out = new PrintWriter(System.out);
    Solution solver = new Solution();
    solver.solve();
    out.close();
} in = new InputReader(System.in) in new InputReader(System.in) out = new PrintWriter(System.out) out new PrintWriter(System.out) Solution solver = new Solution(); solver new Solution() solver.solve() solver.solve solver out.close() out.close out String[] args args static class Solution {
    void solve() throws IOException {
        int r = in.nextInt();
        int c = in.nextInt();
        int sum = 0;
        int[][] sheet = new int[r][c]; 
        int[] sumofrow = new int[r];
        int[] sumofcolumn = new int[c];
        
        for (int i = 0; i < r; i++) {
          for (int j = 0; j < c; j++) {
            sheet[i][j] = in.nextInt();
            sum += sheet[i][j];
          }
        }
        
        for (int i = 0; i < r; i++) {
          for (int j = 0; j < c; j++) {
            sumofrow[i] += sheet[i][j];
            sumofcolumn[j] += sheet[i][j];
          }
        }
        
        for (int i = 0; i < r; i++) {
          for (int j = 0; j < c; j++) {
            out.print(sheet[i][j] + " ");
          }
          out.println(sumofrow[i]);
        }
        
        for (int i = 0; i < c; i++) {
          out.print(sumofcolumn[i] + " ");
        }
        
        out.println(sum);
        
//      End solve()
    }
//    End Solution
} Solution void solve() throws IOException {
        int r = in.nextInt();
        int c = in.nextInt();
        int sum = 0;
        int[][] sheet = new int[r][c]; 
        int[] sumofrow = new int[r];
        int[] sumofcolumn = new int[c];
        
        for (int i = 0; i < r; i++) {
          for (int j = 0; j < c; j++) {
            sheet[i][j] = in.nextInt();
            sum += sheet[i][j];
          }
        }
        
        for (int i = 0; i < r; i++) {
          for (int j = 0; j < c; j++) {
            sumofrow[i] += sheet[i][j];
            sumofcolumn[j] += sheet[i][j];
          }
        }
        
        for (int i = 0; i < r; i++) {
          for (int j = 0; j < c; j++) {
            out.print(sheet[i][j] + " ");
          }
          out.println(sumofrow[i]);
        }
        
        for (int i = 0; i < c; i++) {
          out.print(sumofcolumn[i] + " ");
        }
        
        out.println(sum);
        
//      End solve()
    } solve {
        int r = in.nextInt();
        int c = in.nextInt();
        int sum = 0;
        int[][] sheet = new int[r][c]; 
        int[] sumofrow = new int[r];
        int[] sumofcolumn = new int[c];
        
        for (int i = 0; i < r; i++) {
          for (int j = 0; j < c; j++) {
            sheet[i][j] = in.nextInt();
            sum += sheet[i][j];
          }
        }
        
        for (int i = 0; i < r; i++) {
          for (int j = 0; j < c; j++) {
            sumofrow[i] += sheet[i][j];
            sumofcolumn[j] += sheet[i][j];
          }
        }
        
        for (int i = 0; i < r; i++) {
          for (int j = 0; j < c; j++) {
            out.print(sheet[i][j] + " ");
          }
          out.println(sumofrow[i]);
        }
        
        for (int i = 0; i < c; i++) {
          out.print(sumofcolumn[i] + " ");
        }
        
        out.println(sum);
        
//      End solve()
    } int r = in.nextInt(); r in.nextInt() in.nextInt in int c = in.nextInt(); c in.nextInt() in.nextInt in int sum = 0; sum 0 int[][] sheet = new int[r][c]; sheet new int[r][c] r c int[] sumofrow = new int[r]; sumofrow new int[r] r int[] sumofcolumn = new int[c]; sumofcolumn new int[c] c for (int i = 0; i < r; i++) {
          for (int j = 0; j < c; j++) {
            sheet[i][j] = in.nextInt();
            sum += sheet[i][j];
          }
        } int i = 0; int i = 0; i 0 i < r i r i++ i++ i {
          for (int j = 0; j < c; j++) {
            sheet[i][j] = in.nextInt();
            sum += sheet[i][j];
          }
        } {
          for (int j = 0; j < c; j++) {
            sheet[i][j] = in.nextInt();
            sum += sheet[i][j];
          }
        } for (int j = 0; j < c; j++) {
            sheet[i][j] = in.nextInt();
            sum += sheet[i][j];
          } int j = 0; int j = 0; j 0 j < c j c j++ j++ j {
            sheet[i][j] = in.nextInt();
            sum += sheet[i][j];
          } {
            sheet[i][j] = in.nextInt();
            sum += sheet[i][j];
          } sheet[i][j] = in.nextInt() sheet[i][j] sheet[i] sheet i j in.nextInt() in.nextInt in sum += sheet[i][j] sum sheet[i][j] sheet[i] sheet i j for (int i = 0; i < r; i++) {
          for (int j = 0; j < c; j++) {
            sumofrow[i] += sheet[i][j];
            sumofcolumn[j] += sheet[i][j];
          }
        } int i = 0; int i = 0; i 0 i < r i r i++ i++ i {
          for (int j = 0; j < c; j++) {
            sumofrow[i] += sheet[i][j];
            sumofcolumn[j] += sheet[i][j];
          }
        } {
          for (int j = 0; j < c; j++) {
            sumofrow[i] += sheet[i][j];
            sumofcolumn[j] += sheet[i][j];
          }
        } for (int j = 0; j < c; j++) {
            sumofrow[i] += sheet[i][j];
            sumofcolumn[j] += sheet[i][j];
          } int j = 0; int j = 0; j 0 j < c j c j++ j++ j {
            sumofrow[i] += sheet[i][j];
            sumofcolumn[j] += sheet[i][j];
          } {
            sumofrow[i] += sheet[i][j];
            sumofcolumn[j] += sheet[i][j];
          } sumofrow[i] += sheet[i][j] sumofrow[i] sumofrow i sheet[i][j] sheet[i] sheet i j sumofcolumn[j] += sheet[i][j] sumofcolumn[j] sumofcolumn j sheet[i][j] sheet[i] sheet i j for (int i = 0; i < r; i++) {
          for (int j = 0; j < c; j++) {
            out.print(sheet[i][j] + " ");
          }
          out.println(sumofrow[i]);
        } int i = 0; int i = 0; i 0 i < r i r i++ i++ i {
          for (int j = 0; j < c; j++) {
            out.print(sheet[i][j] + " ");
          }
          out.println(sumofrow[i]);
        } {
          for (int j = 0; j < c; j++) {
            out.print(sheet[i][j] + " ");
          }
          out.println(sumofrow[i]);
        } for (int j = 0; j < c; j++) {
            out.print(sheet[i][j] + " ");
          } int j = 0; int j = 0; j 0 j < c j c j++ j++ j {
            out.print(sheet[i][j] + " ");
          } {
            out.print(sheet[i][j] + " ");
          } out.print(sheet[i][j] + " ") out.print out sheet[i][j] + " " sheet[i][j] sheet[i] sheet i j " " out.println(sumofrow[i]) out.println out sumofrow[i] sumofrow i for (int i = 0; i < c; i++) {
          out.print(sumofcolumn[i] + " ");
        } int i = 0; int i = 0; i 0 i < c i c i++ i++ i {
          out.print(sumofcolumn[i] + " ");
        } {
          out.print(sumofcolumn[i] + " ");
        } out.print(sumofcolumn[i] + " ") out.print out sumofcolumn[i] + " " sumofcolumn[i] sumofcolumn i " " out.println(sum) out.println out sum static class InputReader {
    public BufferedReader br;
    public StringTokenizer st;

    public InputReader(InputStream stream) {
      br = new BufferedReader(new InputStreamReader(stream));
    }

    public int nextInt() throws IOException {
      while (st == null || !st.hasMoreTokens()) {
        st = new StringTokenizer(br.readLine());
      }
      return Integer.parseInt(st.nextToken());
    }

    public long nextLong() throws IOException {
      while (st == null || !st.hasMoreTokens()) {
        st = new StringTokenizer(br.readLine());
      }
      return Long.parseLong(st.nextToken());
    }

    public String next() throws IOException {
      while (st == null || !st.hasMoreTokens()) {
        st = new StringTokenizer(br.readLine());
      }
      return st.nextToken();
    }

    public double nextDouble() throws IOException {
      while (st == null || !st.hasMoreTokens()) {
        st = new StringTokenizer(br.readLine());
      }
      return Double.parseDouble(st.nextToken());
    }


  } InputReader public BufferedReader br; br public StringTokenizer st; st public InputReader(InputStream stream) {
      br = new BufferedReader(new InputStreamReader(stream));
    } InputReader {
      br = new BufferedReader(new InputStreamReader(stream));
    } br = new BufferedReader(new InputStreamReader(stream)) br new BufferedReader(new InputStreamReader(stream)) InputStream stream stream public int nextInt() throws IOException {
      while (st == null || !st.hasMoreTokens()) {
        st = new StringTokenizer(br.readLine());
      }
      return Integer.parseInt(st.nextToken());
    } nextInt {
      while (st == null || !st.hasMoreTokens()) {
        st = new StringTokenizer(br.readLine());
      }
      return Integer.parseInt(st.nextToken());
    } while (st == null || !st.hasMoreTokens()) {
        st = new StringTokenizer(br.readLine());
      } st == null || !st.hasMoreTokens() st == null st null !st.hasMoreTokens() st.hasMoreTokens() st.hasMoreTokens st {
        st = new StringTokenizer(br.readLine());
      } st = new StringTokenizer(br.readLine()) st new StringTokenizer(br.readLine()) return Integer.parseInt(st.nextToken()); Integer.parseInt(st.nextToken()) Integer.parseInt Integer st.nextToken() st.nextToken st public long nextLong() throws IOException {
      while (st == null || !st.hasMoreTokens()) {
        st = new StringTokenizer(br.readLine());
      }
      return Long.parseLong(st.nextToken());
    } nextLong {
      while (st == null || !st.hasMoreTokens()) {
        st = new StringTokenizer(br.readLine());
      }
      return Long.parseLong(st.nextToken());
    } while (st == null || !st.hasMoreTokens()) {
        st = new StringTokenizer(br.readLine());
      } st == null || !st.hasMoreTokens() st == null st null !st.hasMoreTokens() st.hasMoreTokens() st.hasMoreTokens st {
        st = new StringTokenizer(br.readLine());
      } st = new StringTokenizer(br.readLine()) st new StringTokenizer(br.readLine()) return Long.parseLong(st.nextToken()); Long.parseLong(st.nextToken()) Long.parseLong Long st.nextToken() st.nextToken st public String next() throws IOException {
      while (st == null || !st.hasMoreTokens()) {
        st = new StringTokenizer(br.readLine());
      }
      return st.nextToken();
    } next {
      while (st == null || !st.hasMoreTokens()) {
        st = new StringTokenizer(br.readLine());
      }
      return st.nextToken();
    } while (st == null || !st.hasMoreTokens()) {
        st = new StringTokenizer(br.readLine());
      } st == null || !st.hasMoreTokens() st == null st null !st.hasMoreTokens() st.hasMoreTokens() st.hasMoreTokens st {
        st = new StringTokenizer(br.readLine());
      } st = new StringTokenizer(br.readLine()) st new StringTokenizer(br.readLine()) return st.nextToken(); st.nextToken() st.nextToken st public double nextDouble() throws IOException {
      while (st == null || !st.hasMoreTokens()) {
        st = new StringTokenizer(br.readLine());
      }
      return Double.parseDouble(st.nextToken());
    } nextDouble {
      while (st == null || !st.hasMoreTokens()) {
        st = new StringTokenizer(br.readLine());
      }
      return Double.parseDouble(st.nextToken());
    } while (st == null || !st.hasMoreTokens()) {
        st = new StringTokenizer(br.readLine());
      } st == null || !st.hasMoreTokens() st == null st null !st.hasMoreTokens() st.hasMoreTokens() st.hasMoreTokens st {
        st = new StringTokenizer(br.readLine());
      } st = new StringTokenizer(br.readLine()) st new StringTokenizer(br.readLine()) return Double.parseDouble(st.nextToken()); Double.parseDouble(st.nextToken()) Double.parseDouble Double st.nextToken() st.nextToken st public class Main {
  static InputReader in;
  static PrintWriter out;

  static class Solution {
    void solve() throws IOException {
        int r = in.nextInt();
        int c = in.nextInt();
        int sum = 0;
        int[][] sheet = new int[r][c]; 
        int[] sumofrow = new int[r];
        int[] sumofcolumn = new int[c];
        
        for (int i = 0; i < r; i++) {
          for (int j = 0; j < c; j++) {
            sheet[i][j] = in.nextInt();
            sum += sheet[i][j];
          }
        }
        
        for (int i = 0; i < r; i++) {
          for (int j = 0; j < c; j++) {
            sumofrow[i] += sheet[i][j];
            sumofcolumn[j] += sheet[i][j];
          }
        }
        
        for (int i = 0; i < r; i++) {
          for (int j = 0; j < c; j++) {
            out.print(sheet[i][j] + " ");
          }
          out.println(sumofrow[i]);
        }
        
        for (int i = 0; i < c; i++) {
          out.print(sumofcolumn[i] + " ");
        }
        
        out.println(sum);
        
//      End solve()
    }
//    End Solution
}

  public static void main(String[] args) throws IOException {
    in = new InputReader(System.in);
    out = new PrintWriter(System.out);
    Solution solver = new Solution();
    solver.solve();
    out.close();
}

  static class InputReader {
    public BufferedReader br;
    public StringTokenizer st;

    public InputReader(InputStream stream) {
      br = new BufferedReader(new InputStreamReader(stream));
    }

    public int nextInt() throws IOException {
      while (st == null || !st.hasMoreTokens()) {
        st = new StringTokenizer(br.readLine());
      }
      return Integer.parseInt(st.nextToken());
    }

    public long nextLong() throws IOException {
      while (st == null || !st.hasMoreTokens()) {
        st = new StringTokenizer(br.readLine());
      }
      return Long.parseLong(st.nextToken());
    }

    public String next() throws IOException {
      while (st == null || !st.hasMoreTokens()) {
        st = new StringTokenizer(br.readLine());
      }
      return st.nextToken();
    }

    public double nextDouble() throws IOException {
      while (st == null || !st.hasMoreTokens()) {
        st = new StringTokenizer(br.readLine());
      }
      return Double.parseDouble(st.nextToken());
    }


  }

} public class Main {
  static InputReader in;
  static PrintWriter out;

  static class Solution {
    void solve() throws IOException {
        int r = in.nextInt();
        int c = in.nextInt();
        int sum = 0;
        int[][] sheet = new int[r][c]; 
        int[] sumofrow = new int[r];
        int[] sumofcolumn = new int[c];
        
        for (int i = 0; i < r; i++) {
          for (int j = 0; j < c; j++) {
            sheet[i][j] = in.nextInt();
            sum += sheet[i][j];
          }
        }
        
        for (int i = 0; i < r; i++) {
          for (int j = 0; j < c; j++) {
            sumofrow[i] += sheet[i][j];
            sumofcolumn[j] += sheet[i][j];
          }
        }
        
        for (int i = 0; i < r; i++) {
          for (int j = 0; j < c; j++) {
            out.print(sheet[i][j] + " ");
          }
          out.println(sumofrow[i]);
        }
        
        for (int i = 0; i < c; i++) {
          out.print(sumofcolumn[i] + " ");
        }
        
        out.println(sum);
        
//      End solve()
    }
//    End Solution
}

  public static void main(String[] args) throws IOException {
    in = new InputReader(System.in);
    out = new PrintWriter(System.out);
    Solution solver = new Solution();
    solver.solve();
    out.close();
}

  static class InputReader {
    public BufferedReader br;
    public StringTokenizer st;

    public InputReader(InputStream stream) {
      br = new BufferedReader(new InputStreamReader(stream));
    }

    public int nextInt() throws IOException {
      while (st == null || !st.hasMoreTokens()) {
        st = new StringTokenizer(br.readLine());
      }
      return Integer.parseInt(st.nextToken());
    }

    public long nextLong() throws IOException {
      while (st == null || !st.hasMoreTokens()) {
        st = new StringTokenizer(br.readLine());
      }
      return Long.parseLong(st.nextToken());
    }

    public String next() throws IOException {
      while (st == null || !st.hasMoreTokens()) {
        st = new StringTokenizer(br.readLine());
      }
      return st.nextToken();
    }

    public double nextDouble() throws IOException {
      while (st == null || !st.hasMoreTokens()) {
        st = new StringTokenizer(br.readLine());
      }
      return Double.parseDouble(st.nextToken());
    }


  }

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

public class Main {
  static InputReader in;
  static PrintWriter out;

  static class Solution {
    void solve() throws IOException {
        int r = in.nextInt();
        int c = in.nextInt();
        int sum = 0;
        int[][] sheet = new int[r][c]; 
        int[] sumofrow = new int[r];
        int[] sumofcolumn = new int[c];
        
        for (int i = 0; i < r; i++) {
          for (int j = 0; j < c; j++) {
            sheet[i][j] = in.nextInt();
            sum += sheet[i][j];
          }
        }
        
        for (int i = 0; i < r; i++) {
          for (int j = 0; j < c; j++) {
            sumofrow[i] += sheet[i][j];
            sumofcolumn[j] += sheet[i][j];
          }
        }
        
        for (int i = 0; i < r; i++) {
          for (int j = 0; j < c; j++) {
            out.print(sheet[i][j] + " ");
          }
          out.println(sumofrow[i]);
        }
        
        for (int i = 0; i < c; i++) {
          out.print(sumofcolumn[i] + " ");
        }
        
        out.println(sum);
        
//      End solve()
    }
//    End Solution
}

  public static void main(String[] args) throws IOException {
    in = new InputReader(System.in);
    out = new PrintWriter(System.out);
    Solution solver = new Solution();
    solver.solve();
    out.close();
}

  static class InputReader {
    public BufferedReader br;
    public StringTokenizer st;

    public InputReader(InputStream stream) {
      br = new BufferedReader(new InputStreamReader(stream));
    }

    public int nextInt() throws IOException {
      while (st == null || !st.hasMoreTokens()) {
        st = new StringTokenizer(br.readLine());
      }
      return Integer.parseInt(st.nextToken());
    }

    public long nextLong() throws IOException {
      while (st == null || !st.hasMoreTokens()) {
        st = new StringTokenizer(br.readLine());
      }
      return Long.parseLong(st.nextToken());
    }

    public String next() throws IOException {
      while (st == null || !st.hasMoreTokens()) {
        st = new StringTokenizer(br.readLine());
      }
      return st.nextToken();
    }

    public double nextDouble() throws IOException {
      while (st == null || !st.hasMoreTokens()) {
        st = new StringTokenizer(br.readLine());
      }
      return Double.parseDouble(st.nextToken());
    }


  }

}