#include <iostream>
using namespace std;
int main() {
  int r, c;
  int x[100][100];
  cin >> r >> c;
  for (int yoko = 0; yoko < r; yoko++) {
    x[yoko][c] = 0;
    for (int tate = 0; tate < c; tate++) {
      cin >> x[yoko][tate];
      x[yoko][c] += x[yoko][tate];
    }
  }
  for (int tate = 0; tate <= c; tate++) {
    x[r][tate] = 0;
    for (int yoko = 0; yoko < r; yoko++) {
      x[r][tate] += x[yoko][tate];
    }
  }
  for (int yoko = 0; yoko <= r; yoko++) {
    for (int tate = 0; tate <= c; tate++) {
      if (tate < c) {
        cout << x[yoko][tate] << " ";
      } else {
        cout << x[yoko][tate];
      }
    }
    cout << endl;
  }
  return 0;
}

#include <iostream>
using namespace std;
int main() {
  int r, c;
  long long x[101][101];
  cin >> r >> c;
  for (int yoko = 0; yoko < r; yoko++) {
    x[yoko][c] = 0;
    for (int tate = 0; tate < c; tate++) {
      cin >> x[yoko][tate];
      x[yoko][c] += x[yoko][tate];
    }
  }
  for (int tate = 0; tate <= c; tate++) {
    x[r][tate] = 0;
    for (int yoko = 0; yoko < r; yoko++) {
      x[r][tate] += x[yoko][tate];
    }
  }
  for (int yoko = 0; yoko <= r; yoko++) {
    for (int tate = 0; tate <= c; tate++) {
      if (tate < c) {
        cout << x[yoko][tate] << " ";
      } else {
        cout << x[yoko][tate];
      }
    }
    cout << endl;
  }
  return 0;
}


#include <iostream>
using namespace std;
int main() {
  int r, c;
  cin >> r >> c;
  r++;
  c++;
  int a[r][c];

  for (int i = 0; i < r - 1; i++) {
    for (int j = 0; j < c - 1; j++) {
      cin >> a[i][j];
    }
  }

  for (int i = 0; i < r; i++) {
    int yokosum = 0;
    for (int j = 0; j < c; j++) {
      yokosum = yokosum + a[i][j];
    }
    a[i][c] = yokosum;
  }

  for (int j = 0; j <= c - 1; j++) {
    int tatesum = 0;
    for (int i = 0; i < r; i++) {
      tatesum = tatesum + a[i][j];
    }
    a[r][j] = tatesum;
  }

  for (int i = 0; i <= r - 1; i++) {
    for (int j = 0; j < c; j++) {
      cout << a[i][j];
      if (j == c) {
      } else {
        cout << endl;
      }
    }
    if (i == r) {
    } else {
      cout << endl;
    }
  }
  cout << endl;
}


#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) for (int i = (n)-1; (i) >= 0; --i)
#define SZ(n) (int)(n).size()
#define ALL(n) (n).begin(), (n).end()
#define MOD LL(1e9 + 7)
#define INF 1000000
using namespace std;
using LL = long long;

int main() {
  int r, c;
  cin >> r >> c;
  int a[100][100] = {};
  int sum = 0;
  for (int i = 0; i < r; i++) {
    for (int j = 0; j < c; j++) {
      cin >> a[i][j];
      sum += a[i][j];
    }
    a[i][c] = sum;
    sum = 0;
  }
  for (int i = 0; i < c + 1; i++) {
    for (int j = 0; j < r; j++) {
      sum += a[j][i];
    }
    a[r][i] = sum;
    sum = 0;
  }
  for (int i = 0; i < r + 1; i++) {
    for (int j = 0; j < c + 1; j++) {
      cout << a[i][j];
      if (j != c)
        cout << " ";
    }
    cout << endl;
  }
  return 0;
}

#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) for (int i = (n)-1; (i) >= 0; --i)
#define SZ(n) (int)(n).size()
#define ALL(n) (n).begin(), (n).end()
#define MOD LL(1e9 + 7)
#define INF 1000000
using namespace std;
using LL = long long;

int main() {
  int r, c;
  cin >> r >> c;
  int a[101][101] = {};
  int sum = 0;
  for (int i = 0; i < r; i++) {
    for (int j = 0; j < c; j++) {
      cin >> a[i][j];
      sum += a[i][j];
    }
    a[i][c] = sum;
    sum = 0;
  }
  for (int i = 0; i < c + 1; i++) {
    for (int j = 0; j < r; j++) {
      sum += a[j][i];
    }
    a[r][i] = sum;
    sum = 0;
  }
  for (int i = 0; i < r + 1; i++) {
    for (int j = 0; j < c + 1; j++) {
      cout << a[i][j];
      if (j != c)
        cout << " ";
    }
    cout << endl;
  }
  return 0;
}


#include <iostream>
using namespace std;

int main() {
  int r, c;
  cin >> r >> c;

  int **Data = new int *[r + 2]();
  for (int i = 0; i < c + 2; i++) {
    Data[i] = new int[c + 2]();
  }

  int *rowsum = new int[r + 2]();
  int *colsum = new int[c + 2]();
  int sum = 0;

  // Input Data
  for (int n = 1; n <= r; n++) {
    for (int m = 1; m <= c; m++) {
      cin >> Data[n][m];
    }
  }

  // Output Data
  for (int rn = 1; rn <= r; rn++) {
    for (int cn = 1; cn <= c; cn++) {
      cout << Data[rn][cn] << " ";
      rowsum[rn] += Data[rn][cn];
      colsum[cn] += Data[rn][cn];
    }
    cout << rowsum[rn] << endl;
  }
  for (int cn = 1; cn <= c; cn++) {
    cout << colsum[cn] << " ";
    sum += colsum[cn];
  }
  cout << sum << endl;

  return 0;
}

#include <iostream>
using namespace std;

int main() {
  int r, c;
  cin >> r >> c;

  int **Data = new int *[r + 2]();
  for (int i = 0; i < r + 2; i++) {
    Data[i] = new int[c + 2]();
  }

  int *rowsum = new int[r + 2]();
  int *colsum = new int[c + 2]();
  int sum = 0;

  // Input Data
  for (int n = 1; n <= r; n++) {
    for (int m = 1; m <= c; m++) {
      cin >> Data[n][m];
    }
  }

  // Output Data
  for (int rn = 1; rn <= r; rn++) {
    for (int cn = 1; cn <= c; cn++) {
      cout << Data[rn][cn] << " ";
      rowsum[rn] += Data[rn][cn];
      colsum[cn] += Data[rn][cn];
    }
    cout << rowsum[rn] << endl;
  }
  for (int cn = 1; cn <= c; cn++) {
    cout << colsum[cn] << " ";
    sum += colsum[cn];
  }
  cout << sum << endl;

  return 0;
}


/*
 * itikara.cpp
 *
 *  Created on: 2018/05/30
 *      Author: J01003
 */
#include <iostream>
#include <stdio.h>
using namespace std;
int main() {
  int k, b, n, c, r;
  cin >> r >> c;
  int hyou[101][101];
  hyou[101][101] = {};
  for (k = 1; k <= r; k++) {
    for (b = 1; b <= c; b++) {
      cin >> n;
      hyou[k][b] += n;
      hyou[r + 1][b] += n;
      hyou[k][c + 1] += n;
      hyou[r + 1][c + 1] += n;
    }
  }
  for (k = 1; k <= r + 1; k++) {
    for (b = 1; b <= c + 1; b++) {
      cout << hyou[k][b];
      if (b > c) {
        break;
      }
      cout << " ";
    }
    cout << endl;
  }
  return 0;
}

/*
 * itikara.cpp
 *
 *  Created on: 2018/05/30
 *      Author: J01003
 */
#include <iostream>
#include <stdio.h>
using namespace std;
int main() {
  int k, b, n, c, r;
  cin >> r >> c;
  int hyou[116][116];
  for (k = 1; k <= r; k++) {
    for (b = 1; b <= c; b++) {
      cin >> n;
      hyou[k][b] += n;
      hyou[r + 1][b] += n;
      hyou[k][c + 1] += n;
      hyou[r + 1][c + 1] += n;
    }
  }
  for (k = 1; k <= r + 1; k++) {
    for (b = 1; b <= c + 1; b++) {
      cout << hyou[k][b];
      if (b > c) {
        break;
      }
      cout << " ";
    }
    cout << endl;
  }
  return 0;
}


#include <algorithm>
#include <cstdio>
#include <iostream>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
int main() {
  int r, c;
  cin >> r >> c;
  vvi A(r + 1, vi(c + 1));
  for (int i = 0; i < r; i++) {
    for (int k = 0; k < c; k++) {
      cin >> A[i][k];
    }
  }
  for (int i = 0; i < r; i++) {
    A[i][c] = 0;
  }
  for (int i = 0; i < r; i++) {
    A[r][i] = 0;
  }
  A[r][c] = 0;
  for (int i = 0; i < r; i++) {
    for (int k = 0; k < c; k++) {
      A[i][c] += A[i][k];
    }
  }
  for (int i = 0; i < c; i++) {
    for (int k = 0; k < r; k++) {
      A[r][i] += A[k][i];
    }
  }
  for (int i = 0; i < r; i++) {
    A[r][c] += A[i][c];
  }
  for (int i = 0; i < r + 1; i++) {
    for (int k = 0; k < c + 1; k++) {
      if (k == c) {
        cout << A[i][k] << endl;
      } else {
        cout << A[i][k] << " ";
      }
    }
  }
}

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
int main() {
  int r, c;
  cin >> r >> c;
  vvi A(r + 1, vi(c + 1));
  for (int i = 0; i < r; i++) {
    for (int k = 0; k < c; k++) {
      cin >> A[i][k];
    }
  }
  for (int i = 0; i < r; i++) {
    A[i][c] = 0;
  }
  for (int i = 0; i < c; i++) {
    A[r][i] = 0;
  }
  A[r][c] = 0;
  for (int i = 0; i < r; i++) {
    for (int k = 0; k < c; k++) {
      A[i][c] += A[i][k];
    }
  }
  for (int i = 0; i < c; i++) {
    for (int k = 0; k < r; k++) {
      A[r][i] += A[k][i];
    }
  }
  for (int i = 0; i < r; i++) {
    A[r][c] += A[i][c];
  }
  for (int i = 0; i < r + 1; i++) {
    for (int k = 0; k < c + 1; k++) {
      if (k == c) {
        cout << A[i][k] << endl;
      } else {
        cout << A[i][k] << " ";
      }
    }
  }
}


#include <iostream>

using namespace std;

int main() {
  int r, c;
  cin >> r >> c;
  int A[100][100] = {0};

  for (int i = 0; i < r; i++) {
    for (int j = 0; j < c; j++) {
      int num;
      cin >> num;
      A[i][j] = num;
    }
  }

  // 計算処理
  for (int i = 0; i < r; i++) {
    for (int j = 0; j < c; j++) {
      A[r][c] += A[i][j];
      A[i][c] += A[i][j];
      A[r][j] += A[i][j];
    }
  }

  // 最後の表示
  for (int i = 0; i <= r; i++) {
    for (int j = 0; j <= c; j++) {
      if (j == c)
        cout << A[i][j];
      else
        cout << A[i][j] << ' ';
    }
    cout << endl;
  }

  return 0;
}

#include <iostream>

using namespace std;

int main() {
  int r, c;
  cin >> r >> c;
  int A[110][110] = {0};

  for (int i = 0; i < r; i++) {
    for (int j = 0; j < c; j++) {
      int num;
      cin >> num;
      A[i][j] = num;
    }
  }

  // 計算処理
  for (int i = 0; i < r; i++) {
    for (int j = 0; j < c; j++) {
      A[r][c] += A[i][j];
      A[i][c] += A[i][j];
      A[r][j] += A[i][j];
    }
  }

  // 最後の表示
  for (int i = 0; i <= r; i++) {
    for (int j = 0; j <= c; j++) {
      if (j == c)
        cout << A[i][j];
      else
        cout << A[i][j] << ' ';
    }
    cout << endl;
  }

  return 0;
}


#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <string>

#include <ctype.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

using namespace std;

int main() {

  int r, c;
  int sum = 0;
  int i, j;
  int m[100][100] = {0};

  cin >> r >> c;

  for (i = 0; i < r; i++) {
    for (j = 0; j < c; j++) {
      cin >> m[i][j];
    }
  }
  for (i = 0; i < r; i++) {
    for (j = 0; j < c; j++) {
      m[r][j] += m[i][j];
      m[i][c] += m[i][j];
    }
    sum += m[i][c];
  }

  m[r][c] = sum;

  for (i = 0; i < r + 1; i++) {
    for (j = 0; j < c; j++) {
      cout << m[i][j] << " ";
    }
    cout << m[i][c] << endl;
  }

  return 0;
}

#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <string>

#include <ctype.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

using namespace std;

int main() {

  int r, c;
  int sum = 0;
  int i, j;
  int m[256][256] = {0};

  cin >> r >> c;

  for (i = 0; i < r; i++) {
    for (j = 0; j < c; j++) {
      cin >> m[i][j];
    }
  }
  for (i = 0; i < r; i++) {
    for (j = 0; j < c; j++) {
      m[r][j] += m[i][j];
      m[i][c] += m[i][j];
    }
    sum += m[i][c];
  }

  m[r][c] = sum;

  for (i = 0; i < r + 1; i++) {
    for (j = 0; j < c; j++) {
      cout << m[i][j] << " ";
    }
    cout << m[i][c] << endl;
  }

  return 0;
}


#include <iostream>
using namespace std;
int main() {
  int retsu, gyou, count, count2, masu[100][100] = {0};
  cin >> retsu >> gyou;
  for (count = 0; count < retsu; count++) {
    for (count2 = 0; count2 < gyou; count2++) {
      cin >> masu[count][count2];
      masu[retsu][count2] += masu[count][count2];
      masu[count][gyou] += masu[count][count2];
    }
  }
  for (count = 0; count < retsu; count++) {
    masu[retsu][gyou] += masu[count][gyou];
  }
  for (count = 0; count <= retsu; count++) {
    for (count2 = 0; count2 <= gyou; count2++) {
      if (count2 != gyou) {
        cout << masu[count][count2] << ' ';
      } else {
        cout << masu[count][count2];
      }
    }
    cout << endl;
  }
  return 0;
}

#include <iostream>
using namespace std;
int main() {
  int retsu, gyou, count, count2, masu[101][101] = {0};
  cin >> retsu >> gyou;
  for (count = 0; count < retsu; count++) {
    for (count2 = 0; count2 < gyou; count2++) {
      cin >> masu[count][count2];
      masu[retsu][count2] += masu[count][count2];
      masu[count][gyou] += masu[count][count2];
    }
  }
  for (count = 0; count < retsu; count++) {
    masu[retsu][gyou] += masu[count][gyou];
  }
  for (count = 0; count <= retsu; count++) {
    for (count2 = 0; count2 <= gyou; count2++) {
      if (count2 != gyou) {
        cout << masu[count][count2] << ' ';
      } else {
        cout << masu[count][count2];
      }
    }
    cout << endl;
  }
  return 0;
}


#include <stdio.h>
using namespace std;

int main() {
  int r, c;
  scanf("%d%d", &r, &c);
  int matrix[101][101] = {};
  for (int i = 0; i < r; i++) {
    for (int j = 0; j < c; j++) {
      scanf("%d", &matrix[i][j]);
      matrix[i][c] += matrix[i][j];
      matrix[r][j] += matrix[i][j];
      matrix[r][c] += matrix[i][j];
    }
  }
  for (int i = 0; i < r + 1; i++) {
    for (int j = 0; j < c + 1; j++) {
      printf("%d%s", matrix[i][j]);
    }
    printf("\\n");
  }
}

#include <stdio.h>
using namespace std;

int main() {
  int r, c;
  scanf("%d%d", &r, &c);
  int matrix[101][101] = {};
  for (int i = 0; i < r; i++) {
    for (int j = 0; j < c; j++) {
      scanf("%d", &matrix[i][j]);
      matrix[i][c] += matrix[i][j];
      matrix[r][j] += matrix[i][j];
      matrix[r][c] += matrix[i][j];
    }
  }
  for (int i = 0; i < r + 1; i++) {
    for (int j = 0; j < c + 1; j++) {
      if (j < c) {
        printf("%d ", matrix[i][j]);
      } else {
        printf("%d", matrix[i][j]);
      }
    }
    printf("\\n");
  }
}


#include <iostream>

using namespace std;

int main(void) {

  int r, c;

  cin >> r >> c;

  int a[100][100] = {0};

  int i, j, b;

  for (i = 0; i < r; i++) {

    for (j = 0; j < c + 1; j++) {

      if (j != c) {

        cin >> a[i][j];

        a[i][c] = a[i][c] + a[i][j];

        a[r][j] = a[r][j] + a[i][j];

        cout << a[i][j] << ' ';
      }

      if (j == c)
        cout << a[i][c];
    }

    cout << endl;
  }

  for (j = 0; j < c + 1; j++) {

    if (j != c)
      cout << a[r][j] << ' ';

    else {
      cout << a[r][j];
    }

    a[r][c] = a[r][c] + a[r][j];
  }

  cout << endl;

  return 0;
}

#include <iostream>

using namespace std;

int main(void) {

  int r, c;

  cin >> r >> c;

  int a[101][101] = {0};

  int i, j, b;

  for (i = 0; i < r; i++) {

    for (j = 0; j < c + 1; j++) {

      if (j != c) {

        cin >> a[i][j];

        a[i][c] = a[i][c] + a[i][j];

        a[r][j] = a[r][j] + a[i][j];

        cout << a[i][j] << ' ';
      }

      if (j == c)
        cout << a[i][c];
    }

    cout << endl;
  }

  for (j = 0; j < c + 1; j++) {

    if (j != c)
      cout << a[r][j] << ' ';

    else {
      cout << a[r][j];
    }

    a[r][c] = a[r][c] + a[r][j];
  }

  cout << endl;

  return 0;
}


#include <bits/stdc++.h>
#define range(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, b) range(i, 0, b)
#define debug(x) cout << "debug" << x << endl;
using namespace std;

int main() {
  int n, m;
  while (cin >> n >> m) {
    int ans[100][100] = {0};
    rep(i, n) {
      rep(j, m) {
        int inp;
        cin >> inp;
        ans[i][j] = inp;
        ans[i][m] += inp;
        ans[n][j] += inp;
      }
      ans[n][m] += ans[i][m];
    }
    rep(i, n + 1) {
      rep(j, m + 1) {
        if (j)
          cout << ' ';
        cout << ans[i][j];
      }
      cout << endl;
    }
  }
}

#include <bits/stdc++.h>
#define range(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, b) range(i, 0, b)
#define debug(x) cout << "debug" << x << endl;
using namespace std;

int main() {
  int n, m;
  while (cin >> n >> m) {
    int ans[105][105] = {0};
    rep(i, n) {
      rep(j, m) {
        int inp;
        cin >> inp;
        ans[i][j] = inp;
        ans[i][m] += inp;
        ans[n][j] += inp;
      }
      ans[n][m] += ans[i][m];
    }
    rep(i, n + 1) {
      rep(j, m + 1) {
        if (j)
          cout << ' ';
        cout << ans[i][j];
      }
      cout << endl;
    }
  }
}


#include <iostream>

#define N 100
using namespace std;

int main() {

  int r, c;
  int ary[N][N];
  int ans_L[N] = {0}, ans_H[N] = {0};
  int sum = 0;

  cin >> r >> c;

  for (int i = 1; i <= r; i++) {
    for (int j = 1; j <= c; j++) {
      cin >> ary[i][j];
      ans_L[i] += ary[i][j];
    }
  }
  for (int j = 1; j <= r; j++) {
    for (int i = 1; i <= c; i++) {
      ans_H[i] += ary[j][i];
    }
  }

  for (int i = 1; i <= r; i++) {
    for (int j = 1; j <= c; j++) {
      cout << ary[i][j] << " ";
    }
    cout << ans_L[i] << endl;
    sum += ans_L[i];
  }
  for (int i = 1; i <= c; i++) {
    cout << ans_H[i] << " ";
  }
  cout << sum << endl;

  return 0;
}

#include <iostream>

#define N 101
using namespace std;

int main() {

  int r, c;
  int ary[N][N];
  int ans_L[N] = {0}, ans_H[N] = {0};
  int sum = 0;

  cin >> r >> c;

  for (int i = 1; i <= r; i++) {
    for (int j = 1; j <= c; j++) {
      cin >> ary[i][j];
      ans_L[i] += ary[i][j];
    }
  }
  for (int j = 1; j <= r; j++) {
    for (int i = 1; i <= c; i++) {
      ans_H[i] += ary[j][i];
    }
  }

  for (int i = 1; i <= r; i++) {
    for (int j = 1; j <= c; j++) {
      cout << ary[i][j] << " ";
    }
    cout << ans_L[i] << endl;
    sum += ans_L[i];
  }
  for (int i = 1; i <= c; i++) {
    cout << ans_H[i] << " ";
  }
  cout << sum << endl;

  return 0;
}


#include "iostream"
using namespace std;

int main() {
  int r, c;
  cin >> r >> c;
  int in, box = 0;
  int under[100] = {0};

  for (int i = 0; i < c; i++) {
    for (int j = 0; j < r; j++) {
      cin >> in;
      box += in;
      under[j] += in;
      cout << in << " ";
    }
    cout << box << endl;
    box = 0;
  }
  for (int i = 0; i < c; c++) {
    cout << under[i] << " ";
    box += under[i];
  }
  cout << box;
}

#include "iostream"
using namespace std;

int main() {
  int r, c, box = 0;
  int under[100] = {0};
  cin >> r >> c;
  int number[100][100];
  for (int i = 0; i < r; i++) {
    for (int j = 0; j < c; j++) {
      cin >> number[i][j];
    }
  }

  for (int i = 0; i < r; i++) {
    for (int j = 0; j < c; j++) {
      cout << number[i][j] << " ";
      box += number[i][j];
      under[j] += number[i][j];
    }
    cout << box << endl;
    box = 0;
  }
  for (int i = 0; i < c; i++) {
    cout << under[i] << " ";
    box += under[i];
  }
  cout << box << endl;
}


#include <iostream>
using namespace std;

int main() {
  int r, c, i, j;
  int table[100][100] = {0};

  cin >> r >> c;
  for (i = 0; i < r; i++) {
    for (j = 0; j < c; j++) {
      cin >> table[i][j];
    }
  }
  for (i = 0; i < r; i++) {
    for (j = 0; j < c; j++) {
      table[i][c] += table[i][j];
      table[r][j] += table[i][j];
    }
  }
  for (i = 0; i < r; i++) {
    table[r][c] += table[i][c];
  }
  for (i = 0; i <= r; i++) {
    for (j = 0; j < c; j++) {
      cout << table[i][j] << " ";
    }
    cout << table[i][c] << endl;
  }
  return 0;
}

#include <iostream>
using namespace std;

int main() {
  int r, c, i, j;
  int table[101][101] = {0};

  cin >> r >> c;
  for (i = 0; i < r; i++) {
    for (j = 0; j < c; j++) {
      cin >> table[i][j];
    }
  }
  for (i = 0; i < r; i++) {
    for (j = 0; j < c; j++) {
      table[i][c] += table[i][j];
      table[r][j] += table[i][j];
    }
  }
  for (i = 0; i < r; i++) {
    table[r][c] += table[i][c];
  }
  for (i = 0; i <= r; i++) {
    for (j = 0; j < c; j++) {
      cout << table[i][j] << " ";
    }
    cout << table[i][c] << endl;
  }
  return 0;
}


#include <iostream>
using namespace std;

int main() {
  int A[101][101];

  int r, c;
  cin >> r >> c;
  for (int i = 0; i < r; i++) {
    for (int j = 0; j < c; j++) {
      cin >> A[i][j];
    }
  }

  for (int i = 0; i < r; i++) {
    A[i][c] = 0;
  }
  for (int j = 0; j < c; j++) {
    A[r][j = 0];
  }

  for (int i = 0; i < r; i++) {
    for (int j = 0; j < c; j++) {
      A[i][c] += A[i][j];
      A[r][j] += A[i][j];
      A[r][c] += A[i][j];
    }
  }

  for (int i = 0; i <= r; i++) {
    for (int j = 0; j <= c; j++) {
      if (j)
        cout << " ";
    }
    cout << endl;
  }
  return 0;
}

#include <iostream>
using namespace std;

int main() {
  int A[101][101];

  int r, c;
  cin >> r >> c;
  for (int i = 0; i < r; i++) {
    for (int j = 0; j < c; j++) {
      cin >> A[i][j];
    }
  }

  for (int i = 0; i <= r; i++) {
    A[i][c] = 0;
  }
  for (int j = 0; j <= c; j++) {
    A[r][j] = 0;
  }

  for (int i = 0; i < r; i++) {
    for (int j = 0; j < c; j++) {
      A[i][c] += A[i][j];
      A[r][j] += A[i][j];
      A[r][c] += A[i][j];
    }
  }

  for (int i = 0; i <= r; i++) {
    for (int j = 0; j <= c; j++) {
      if (j)
        cout << " ";
      cout << A[i][j];
    }
    cout << endl;
  }
  return 0;
}


#include <iostream>
using namespace std;
int main() {
  int r, c, a[100][100], sum = 0, haji = 0;
  cin >> r >> c;
  for (int i = 0; i < r; ++i) {
    for (int j = 0; j < c; ++j) {
      cin >> a[i][j];
    }
  }
  for (int i = 0; i < r; ++i) {
    sum = 0;
    for (int j = 0; j < c; ++j) {
      cout << a[i][j] << " ";
      sum += a[i][j];
    }
    cout << sum << endl;
  }
  for (int j = 0; j < c; ++j) {
    sum = 0;
    for (int i = 0; i < r; ++i) {
      sum += a[i][j];
    }
    cout << sum << " ";
    haji += sum;
  }
  cout << haji << endl;
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main() {
  int T, Y, a[100][100] = {0};
  cin >> T >> Y;
  for (int i = 0; i < T; i++) {
    for (int j = 0; j < Y; j++) {
      cin >> a[i][j];
      a[T][j] += a[i][j];
    }
  }
  for (int i = 0; i <= T; i++) {
    for (int j = 0; j < Y; j++)
      a[i][Y] += a[i][j];
  }
  for (int i = 0; i <= T; i++) {
    for (int j = 0; j < Y; j++)
      cout << a[i][j] << " ";
    cout << a[i][Y] << endl;
  }
}


#include <iostream>
using namespace std;

int main() {

  int r, c, n;
  cin >> r >> c;
  int views[r + 1][c + 1];
  // 入力と横の合計
  for (int i = 0; i < r; i++) {
    int sum = 0;
    for (int j = 0; i < c; j++) {

      cin >> n;
      views[i][j] = n;
      sum += n;
      if (j == c - 1) {
        views[i][c] = sum;
      }
    }
  }
  for (int j = 0; j < c; j++) {
    int sum = 0;
    for (int i = 0; i < r; i++) {
      sum += views[i][j];
    }
    views[r][j] = sum;
  }
  for (int i = 0; i <= r; i++) {
    for (int j = 0; j <= c; j++) {
      if (j != 0)
        cout << " ";
      cout << views[i][j];
    }
    cout << endl;
  }

  return 0;
}

#include <iostream>
using namespace std;

int main() {

  int r, c, n;
  cin >> r >> c;
  int views[r + 1][c + 1];
  // 入力と横の合計
  for (int i = 0; i < r; i++) {
    int sum = 0;
    for (int j = 0; j < c; j++) {

      cin >> n;
      views[i][j] = n;
      sum += n;
      if (j == c - 1) {
        views[i][c] = sum;
        // cout << sum << endl;
      }
    }
  }
  for (int j = 0; j <= c; j++) {
    int sum = 0;
    for (int i = 0; i < r; i++) {
      sum += views[i][j];
    }
    views[r][j] = sum;
  }
  for (int i = 0; i <= r; i++) {
    for (int j = 0; j <= c; j++) {
      if (j != 0)
        cout << " ";
      cout << views[i][j];
    }
    cout << endl;
  }

  return 0;
}


#include <cstdio>
#include <vector>
using namespace std;

int main() {
  int r, c, sum, tmp;
  scanf("%d %d\\n", &r, &c);
  vector<vector<int>> sh;
  sh = vector<vector<int>>(r + 1, vector<int>(c + 1, 0));
  for (int i = 0; i < r; i++) {
    sum = 0;
    for (int j = 0; i < c; i++) {
      if (j == c - 1)
        scanf("%d\\n", &tmp);
      else
        scanf("%d ", &tmp);
      sh[i][j] = tmp;
      sum += sh[i][j];
    }
    sh[i][c] = sum;
  }
  for (int i = 0; i < c + 1; i++) {
    sum = 0;
    for (int j = 0; i < r + 1; i++) {
      sum += sh[j][i];
    }
    sh[r][i] = sum;
  }
  for (int i = 0; i < r + 1; i++) {
    for (int j = 0; i < c + 1; i++) {
      if (j == c)
        printf("%d\\n", sh[i][j]);
      else
        printf("%d ", sh[i][j]);
    }
  }
  return 0;
}

#include <cstdio>
#include <vector>
using namespace std;

int main() {
  int r, c, sum, total_sum;
  total_sum = 0;
  scanf("%d %d\\n", &r, &c);
  int sh[r + 1][c + 1];
  for (int i = 0; i < r + 1; i++) {
    for (int j = 0; i < c + 1; i++) {
      sh[i][j] = 0;
    }
  }
  for (int i = 0; i < r; i++) {
    sum = 0;
    for (int j = 0; j < c; j++) {
      scanf("%d", &sh[i][j]);
      sum += sh[i][j];
    }
    sh[i][c] = sum;
    total_sum += sum;
  }
  sh[r][c] = total_sum;
  for (int i = 0; i < c; i++) {
    sum = 0;
    for (int j = 0; j < r; j++) {
      sum += sh[j][i];
    }
    sh[r][i] = sum;
  }
  for (int i = 0; i < r + 1; i++) {
    for (int j = 0; j < c + 1; j++) {
      if (j == c)
        printf("%d\\n", sh[i][j]);
      else
        printf("%d ", sh[i][j]);
    }
  }
  return 0;
}


#include <cstdio>
#include <iostream>

using namespace std;

int main() {

  int r, c;
  cin >> r >> c;

  int a[100][100] = {};
  int r_total = 0;

  for (int i = 0; i < r; i++) {
    for (int j = 0; j < c; j++) {
      cin >> a[i][j];
      r_total += a[i][j];
    }
    a[i][c] = r_total;
    r_total = 0;
  }

  int c_total = 0;
  for (int j = 0; j <= c; j++) {
    for (int i = 0; i <= r; i++) {
      c_total += a[i][j];
    }
    a[r][j] = c_total;
    c_total = 0;
  }

  int total;

  for (int i = 0; i <= r; i++) {
    for (int j = 0; j <= c; j++) {
      printf("%d%c", a[i][j], j < c ? ' ' : '\\n');
    }
  }

  return 0;
}

#include <cstdio>
#include <iostream>

using namespace std;

int main() {

  int r, c;
  cin >> r >> c;

  int a[101][101] = {};
  int r_total = 0;

  for (int i = 0; i < r; i++) {
    for (int j = 0; j < c; j++) {
      cin >> a[i][j];
      r_total += a[i][j];
    }
    a[i][c] = r_total;
    r_total = 0;
  }

  int c_total = 0;
  for (int j = 0; j <= c; j++) {
    for (int i = 0; i <= r; i++) {
      c_total += a[i][j];
    }
    a[r][j] = c_total;
    c_total = 0;
  }

  int total;

  for (int i = 0; i <= r; i++) {
    for (int j = 0; j <= c; j++) {
      printf("%d%c", a[i][j], j < c ? ' ' : '\\n');
    }
  }

  return 0;
}


#include <iostream>
using namespace std;
int main() {
  while (1) {
    int a[100][100];
    int r, c;
    cin >> r >> c;
    for (int i = 0; i < 100; i++) {
      for (int j = 0; j < 100; j++) {
        a[i][j] = 0;
      }
    }
    int b;
    int Wsum = 0, Hsum = 0, Asum = 0;
    for (int i = 0; i < r; i++) {
      for (int j = 0; j < c; j++) {
        cin >> b;
        a[i][j] = b;
        cout << a[i][j] << " ";
        Wsum += a[i][j];
      }
      cout << Wsum << endl;
      Asum += Wsum;
      Wsum = 0;
    }
    for (int i = 0; i < r + 1; i++) {
      for (int j = 0; j < c + 1; j++) {
        Hsum += a[i][j];
      }
      cout << Hsum << " ";
      Hsum = 0;
    }
    cout << Asum;
  }
}

#include <iostream>
using namespace std;
int main() {
  int a[100][100];
  int r, c, b;
  int Wsum = 0, Hsum = 0, Asum = 0;
  cin >> r >> c;
  for (int i = 0; i < 100; i++) {
    for (int j = 0; j < 100; j++) {
      a[i][j] = 0;
    }
  }
  for (int i = 0; i < r; i++) {
    for (int j = 0; j < c; j++) {
      cin >> b;
      a[i][j] = b;
      cout << a[i][j] << " ";
      Wsum += a[i][j];
    }
    cout << Wsum << endl;
    Asum += Wsum;
    Wsum = 0;
  }
  for (int i = 0; i < c; i++) {
    for (int j = 0; j < r; j++) {
      Hsum += a[j][i];
    }
    cout << Hsum << " ";
    Hsum = 0;
  }
  cout << Asum << endl;
}


#include <bits/stdc++.h>
using namespace std;
int main() {
  int a[100][100], r, c, sum = 0;
  scanf("%d %d", &r, &c);
  for (int i = 0; i < r; i++) {
    for (int j = 0; j < c; j++) {
      scanf("%d", &a[i][j]);
      a[i][c] += a[i][j];
      a[r][j] += a[i][j];
    }
    a[r][c] += a[i][c];
  }
  for (int i = 0; i <= r; i++) {
    for (int j = 0; j <= c; j++) {
      printf("%d", a[i][j]);
      if (j == c)
        printf("\\n");
      else
        printf(" ");
    }
  }
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
int main() {
  int r, c, l = 0, s = 0;
  int ans[101][101];
  cin >> r >> c;
  for (int i = 0; i < r; i++) {
    for (int j = 0; j < c; j++) {
      cin >> ans[i][j];
      s += ans[i][j];
    }
    ans[i][c] = s;
    s = 0;
  }
  for (int j = 0; j <= c; j++) {
    for (int i = 0; i < r; i++) {
      l += ans[i][j];
    }
    ans[r][j] = l;
    l = 0;
  }
  for (int i = 0; i <= r; i++) {
    for (int j = 0; j <= c; j++) {
      cout << ans[i][j];
      if (j != c)
        cout << " ";
      else
        cout << endl;
    }
  }
}


#include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

int main() {
  int a, b, t[100][100]{0};
  cin >> a >> b;
  for (int i = 0; i < a; i++) {
    for (int j = 0; j < b; j++) {
      cin >> t[i][j];
      t[a][j] += t[i][j];
      t[i][b] += t[i][j];
      t[a][b] += t[i][j];
    }
  }
  for (int i = 0; i < a + 1; i++) {
    for (int j = 0; j < b + 1; j++) {
      if (j == 0)
        cout << t[i][j];
      else
        cout << " " << t[i][j];
    }
    cout << endl;
  }
  return 0;
}

#include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

int main() {
  int a, b, t[101][101]{0};
  cin >> a >> b;
  for (int i = 0; i < a; i++) {
    for (int j = 0; j < b; j++) {
      cin >> t[i][j];
      t[a][j] += t[i][j];
      t[i][b] += t[i][j];
      t[a][b] += t[i][j];
    }
  }
  for (int i = 0; i < a + 1; i++) {
    for (int j = 0; j < b + 1; j++) {
      if (j == 0)
        cout << t[i][j];
      else
        cout << " " << t[i][j];
    }
    cout << endl;
  }
  return 0;
}


#include <cstdio>

int main() {
  int r, c;
  scanf("%d %d", &r, &c);

  int array[100][100] = {0};

  for (int i = 0; i < r; i++) {
    for (int j = 0; j < c; j++) {
      scanf("%d", &array[i][j]);
      array[i][c] += array[i][j];
      array[r][j] += array[i][j];
      array[r][c] += array[i][j];
    }
  }

  /* test */
  for (int i = 0; i <= r; i++) {
    for (int j = 0; j <= c; j++) {
      printf("%d", array[i][j]);
      if (j != c)
        printf(" ");
    }
    printf("\\n");
  }

  return 0;
}

#include <cstdio>

int main() {
  int r, c;
  scanf("%d %d", &r, &c);

  int array[101][101] = {0};

  for (int i = 0; i < r; i++) {
    for (int j = 0; j < c; j++) {
      scanf("%d", &array[i][j]);
      array[i][c] += array[i][j];
      array[r][j] += array[i][j];
      array[r][c] += array[i][j];
    }
  }

  /* test */
  for (int i = 0; i <= r; i++) {
    for (int j = 0; j <= c; j++) {
      printf("%d", array[i][j]);
      if (j != c)
        printf(" ");
    }
    printf("\\n");
  }

  return 0;
}


#include <stdio.h>
int main() {
  int box[100][100], r, c, cour, couc, sumc, sumr = 0, suma = 0;
  scanf("%d %d", &r, &c);
  for (cour = 1; cour < r + 1; cour++) {
    for (couc = 1; couc < c + 1; couc++) {
      scanf("%d", &box[cour][couc]);
    }
  }
  for (cour = 1; cour < r + 1; cour++) {
    sumc = 0;
    for (couc = 1; couc < c + 2; couc++) {
      if (couc < c + 1) {
        printf("%d ", box[cour][couc]);
        sumc = sumc + box[cour][couc];
      }
    }
    printf("%d\\n", sumc);
  }
  for (couc = 1; couc < c + 1; couc++) {
    sumr = 0;
    for (cour = 1; cour < r + 2; cour++) {
      sumr = sumr + box[cour][couc];
    }
    printf("%d ", sumr);
    suma = suma + sumr;
  }
  printf("%d\\n", suma);
  return 0;
}

#include <stdio.h>
int main() {
  int box[101][101], r, c, cour, couc, sumc, sumr = 0, suma = 0;
  scanf("%d %d", &r, &c);
  for (cour = 1; cour < r + 1; cour++) {
    for (couc = 1; couc < c + 1; couc++) {
      scanf("%d", &box[cour][couc]);
    }
  }
  for (cour = 1; cour < r + 1; cour++) {
    sumc = 0;
    for (couc = 1; couc < c + 2; couc++) {
      if (couc < c + 1) {
        printf("%d ", box[cour][couc]);
        sumc = sumc + box[cour][couc];
      }
    }
    printf("%d\\n", sumc);
  }
  for (couc = 1; couc < c + 1; couc++) {
    sumr = 0;
    for (cour = 1; cour < r + 1; cour++) {
      sumr = sumr + box[cour][couc];
    }
    printf("%d ", sumr);
    suma = suma + sumr;
  }
  printf("%d\\n", suma);
  return 0;
}


#include <iostream>
using namespace std;
int main() {
  int r, c;
  cin >> r >> c;
  int a[100][100];
  for (int i = 0; i < 100; i++) {
    for (int j = 0; j < 100; j++) {
      a[i][j] = 0;
    }
  }
  for (int i = 0; i < r; i++) {
    for (int j = 0; j < c;) {
      cin >> a[i][j];
    }
  }
  for (int i = 0; i < r; i++) {
    for (int j = 0; j < c; j++) {
      a[i][c] += a[i][j];
    }
  }
  for (int i = 0; i < r; i++) {
    for (int j = 0; j < c; j++) {
      a[r][j] += a[i][j];
    }
  }
  for (int i = 0; i <= r; i++) {
    for (int j = 0; j <= c; j++) {
      cout << a[i][j];
      if (j != c)
        cout << ' ';
    }
    cout << endl;
  }
  return 0;
}

#include <iostream>
using namespace std;
int main() {
  int r, c;
  cin >> r >> c;
  int a[110][110];
  for (int i = 0; i < 110; i++) {
    for (int j = 0; j < 110; j++) {
      a[i][j] = 0;
    }
  }

  for (int i = 0; i < r; i++) {
    for (int j = 0; j < c; j++) {
      cin >> a[i][j];
    }
  }

  for (int i = 0; i < r; i++) {
    for (int j = 0; j < c; j++) {
      a[i][c] += a[i][j];
    }
  }
  for (int i = 0; i < r; i++) {
    for (int j = 0; j < c + 1; j++) {
      a[r][j] += a[i][j];
    }
  }
  // cout << endl;

  for (int i = 0; i <= r; i++) {
    for (int j = 0; j <= c; j++) {
      cout << a[i][j];
      if (j != c)
        cout << ' ';
    }
    cout << endl;
  }
  return 0;
}


#include <iostream>
using namespace std;

int main() {
  int r, c, sum, t_sum = 0;
  cin >> r >> c;
  int table[100][100] = {{}};

  for (int i = 0; i < r; i++) {
    sum = 0;
    for (int j = 0; j < c; j++) {
      cin >> table[i][j];
      sum += table[i][j];
      table[r][j] += table[i][j];
    }
    table[i][c] = sum;
    t_sum += sum;
  }
  table[r][c] = t_sum;

  for (int i = 0; i < r + 1; i++) {
    for (int j = 0; j < c; j++) {
      cout << table[i][j] << " ";
    }
    cout << table[i][c] << endl;
  }
  return 0;
}

#include <iostream>
using namespace std;

int main() {
  int r, c, sum, t_sum = 0;
  cin >> r >> c;
  int table[101][101] = {{}};

  for (int i = 0; i < r; i++) {
    sum = 0;
    for (int j = 0; j < c; j++) {
      cin >> table[i][j];
      sum += table[i][j];
      table[r][j] += table[i][j];
    }
    table[i][c] = sum;
    t_sum += sum;
  }
  table[r][c] = t_sum;

  for (int i = 0; i < r + 1; i++) {
    for (int j = 0; j < c; j++) {
      cout << table[i][j] << " ";
    }
    cout << table[i][c] << endl;
  }
  return 0;
}


#include <iostream>
using namespace std;

int main() {
  int i, j, r, c;
  int array[101][101];

  cin >> r >> c;

  for (i = 1; i <= r + 1; i++) {
    for (j = 1; j <= c + 1; j++) {
      array[i][j] = 0;
    }
  }

  for (i = 1; i <= r; i++) {
    for (j = 1; j <= c; j++) {
      cin >> array[i][j];
      array[i][c + 1] += array[i][j];
      array[r + 1][j] += array[i][j];
      array[r + 1][c + 1] += array[i][j];
    }
  }

  for (i = 1; i <= r + 1; i++) {
    for (j = 1; j <= c + 1; j++) {
      if (j != 1)
        cout << " ";
      cout << array[i][j];
    }
    cout << endl;
  }

  return 0;
}

#include <iostream>
using namespace std;

int main() {
  int i, j, r, c;
  int array[102][102];

  cin >> r >> c;

  for (i = 1; i <= r + 1; i++) {
    for (j = 1; j <= c + 1; j++) {
      array[i][j] = 0;
    }
  }

  for (i = 1; i <= r; i++) {
    for (j = 1; j <= c; j++) {
      cin >> array[i][j];
      array[i][c + 1] += array[i][j];
      array[r + 1][j] += array[i][j];
      array[r + 1][c + 1] += array[i][j];
    }
  }

  for (i = 1; i <= r + 1; i++) {
    for (j = 1; j <= c + 1; j++) {
      if (j != 1)
        cout << " ";
      cout << array[i][j];
    }
    cout << endl;
  }

  return 0;
}


#include <stdio.h>

int main() {
  int t = 0;
  int y = 0;
  int glaf[100][100] = {0};

  scanf("%d %d", &t, &y);
  for (int i = 0; i < t; i++) {
    for (int j = 0; j < y; j++) {
      scanf("%d", &glaf[i][j]);
    }
  }

  for (int ii = 0; ii < t; ii++) {
    for (int jj = 0; jj < y; jj++) {
      glaf[ii][y] += glaf[ii][jj];
    }
  }

  for (int iii = 0; iii < y; iii++) {
    for (int jjj = 0; jjj < t; jjj++) {
      glaf[t][iii] += glaf[jjj][iii];
    }
  }

  for (int a = 0; a < y; a++) {
    glaf[t][y] += glaf[t][a];
  }

  for (int iiii = 0; iiii < t + 1; iiii++) {
    for (int jjjj = 0; jjjj < y + 1; jjjj++) {
      printf("%d", glaf[iiii][jjjj]);
      if (jjjj != y)
        printf(" ");
    }
    printf("\\n");
  }
  return 0;
}

#include <stdio.h>
int main() {
  int t = 0;
  int y = 0;
  int glaf[110][110] = {0};

  scanf("%d %d", &t, &y);
  for (int i = 0; i < t; i++) {
    for (int j = 0; j < y; j++) {
      scanf("%d", &glaf[i][j]);
    }
  }

  for (int ii = 0; ii < t; ii++) {
    for (int jj = 0; jj < y; jj++) {
      glaf[ii][y] += glaf[ii][jj];
    }
  }

  for (int iii = 0; iii < y; iii++) {
    for (int jjj = 0; jjj < t; jjj++) {
      glaf[t][iii] += glaf[jjj][iii];
    }
  }

  for (int a = 0; a < y; a++) {
    glaf[t][y] += glaf[t][a];
  }

  for (int iiii = 0; iiii < t + 1; iiii++) {
    for (int jjjj = 0; jjjj < y + 1; jjjj++) {
      printf("%d", glaf[iiii][jjjj]);
      if (jjjj != y)
        printf(" ");
    }
    printf("\\n");
  }
  return 0;
}


#include <cstdio>
#include <cstring>
#include <iostream>
#include <stdio.h>
using namespace std;

int main() {
  int r, c, a[100][100], sumfin = 0;

  cin >> r >> c;
  for (int i = 0; i < r; i++) {
    for (int j = 0; j < c; j++) {
      cin >> a[i][j];
      a[r][j] += a[i][j];
      a[i][c] += a[i][j];
      cout << a[i][j] << " ";
    }
    cout << a[i][c] << endl;
  }

  for (int i = 0; i < c; i++) {
    cout << a[r][i] << " ";
    sumfin = sumfin + a[r][i];
  }
  cout << sumfin << endl;

  return 0;
}

#include <cstdio>
#include <cstring>
#include <iostream>
#include <stdio.h>
using namespace std;

int main() {
  int r, c, a[100][100], sumfin = 0;
  int sumi[100] = {};
  int sumj[100] = {};
  cin >> r >> c;
  for (int i = 0; i < r; i++) {
    for (int j = 0; j < c; j++) {
      cin >> a[i][j];
      sumj[i] = sumj[i] + a[i][j];
    }
  }

  for (int i = 0; i < c; i++) {
    for (int j = 0; j < r; j++) {
      sumi[i] = sumi[i] + a[j][i];
    }
  }

  for (int i = 0; i < r; i++) {
    for (int j = 0; j < c; j++)
      cout << a[i][j] << " ";
    cout << sumj[i] << endl;
    sumfin += sumj[i];
  }
  for (int i = 0; i < c; i++)
    cout << sumi[i] << " ";

  cout << sumfin << endl;

  return 0;
}


#include <ctype.h>
#include <iostream>
#include <stdio.h>
using namespace std;

int main(void) {
  int r, c;
  cin >> r >> c;
  int A[100][100];
  for (int i = 0; i < 100; i++) {
    for (int j = 0; j < 100; j++) {
      A[i][j] = 0;
    }
  }
  for (int i = 0; i < r; i++) {
    for (int j = 0; j < c; j++) {
      cin >> A[i][j];
      A[i][c] += A[i][j];
    }
  }
  for (int j = 0; j <= c; j++) {
    for (int i = 0; i < r; i++) {
      A[r][j] += A[i][j];
    }
  }
  for (int i = 0; i <= r; i++) {
    for (int j = 0; j <= c; j++) {
      printf("%d", A[i][j]);
      if (j != c) {
        putchar(' ');
      }
    }
    putchar('\\n');
  }

  return 0;
}

#include <ctype.h>
#include <iostream>
#include <stdio.h>
using namespace std;

int main(void) {
  int r, c;
  cin >> r >> c;
  int A[101][101];
  for (int i = 0; i <= 100; i++) {
    for (int j = 0; j <= 100; j++) {
      A[i][j] = 0;
    }
  }
  for (int i = 0; i < r; i++) {
    for (int j = 0; j < c; j++) {
      cin >> A[i][j];
      A[i][c] += A[i][j];
    }
  }
  for (int j = 0; j <= c; j++) {
    for (int i = 0; i < r; i++) {
      A[r][j] += A[i][j];
    }
  }
  for (int i = 0; i <= r; i++) {
    for (int j = 0; j <= c; j++) {
      printf("%d", A[i][j]);
      if (j != c) {
        putchar(' ');
      }
    }
    putchar('\\n');
  }

  return 0;
}


#include <iostream>
using namespace std;
int main() {
  int h, w, i, j, x, y, number[101][101];
  cin >> h >> w;
  for (i = 1; i <= h; i++) {
    for (j = 1; j <= w; j++) {
      cin >> number[i][j];
      number[i][w + 1] += number[i][j];
      number[h + 1][j] += number[i][j];
      number[h + 1][w + 1] += number[i][j];
    }
  }
  for (i = 1; i <= h; i++) {
    for (j = 1; j <= w; j++) {
      cout << number[i][j] << " ";
    }
    cout << number[i][w + 1];
    cout << endl;
  }
  for (j = 1; j <= w; j++) {
    cout << number[h + 1][j] << " ";
  }
  cout << number[h + 1][w + 1] << endl;
}

#include <iostream>
using namespace std;
int main() {
  long long h, w, i, j, x, y, number[400][400];
  cin >> h >> w;
  for (i = 1; i <= h; i++) {
    for (j = 1; j <= w; j++) {
      cin >> number[i][j];
      number[i][w + 1] += number[i][j];
      number[h + 1][j] += number[i][j];
      number[h + 1][w + 1] += number[i][j];
    }
  }
  for (i = 1; i <= h; i++) {
    for (j = 1; j <= w; j++) {
      cout << number[i][j] << " ";
    }
    cout << number[i][w + 1];
    cout << endl;
  }
  for (j = 1; j <= w; j++) {
    cout << number[h + 1][j] << " ";
  }
  cout << number[h + 1][w + 1] << endl;
}


#include <iostream>
using namespace std;

int main() {
  int table[100][100] = {0};
  int r, c;
  cin >> r >> c;
  for (int i = 0; i < r; i++) {
    for (int j = 0; j < c; j++) {
      cin >> table[i][j];
      table[i][c] += table[i][j];
      table[r][j] += table[i][j];
    }
    table[r][c] += table[i][c];
  }
  for (int i = 0; i <= r; i++) {
    for (int j = 0; j <= c; j++) {
      if (j != c) {
        cout << table[i][j] << " ";
      } else {
        cout << table[i][j] << endl;
      }
    }
  }
  return 0;
}

#include <iostream>
using namespace std;

int main() {
  int table[101][101] = {0};
  int r, c;
  cin >> r >> c;
  for (int i = 0; i < r; i++) {
    for (int j = 0; j < c; j++) {
      cin >> table[i][j];
      table[i][c] += table[i][j];
      table[r][j] += table[i][j];
    }
    table[r][c] += table[i][c];
  }
  for (int i = 0; i <= r; i++) {
    for (int j = 0; j <= c; j++) {
      if (j != c) {
        cout << table[i][j] << " ";
      } else {
        cout << table[i][j] << endl;
      }
    }
  }
  return 0;
}


#include <iostream>
#include <stdio.h>
using namespace std;

int main() {
  int r, c, graph[101][101];
  cin >> r >> c;

  for (int i = 0; i < r + 1; i++) {
    for (int j = 0; j < c + 1; j++) {
      graph[i][j] = 0;
    }
  }

  for (int i = 0; i < r; i++) {
    for (int j = 0; j < c; j++) {
      cin >> graph[i][j];
    }
    for (int j = 0; j < c; j++) {
      graph[i][c] += graph[i][j];
    }
  }

  for (int j = 0; j < c + 1; j++) {
    for (int i = 0; i < r; i++) {
      graph[r][j] += graph[i][j];
    }
  }

  for (int i = 0; i < r + 1; i++) {
    for (int j = 0; j < c + 1; j++) {
      printf("%d", graph[i][j]);
      if (j != c)
        printf(" ");
    }
    printf("\\n");
  }

  while (1) {
  }
  return 0;
}

#include <iostream>
#include <stdio.h>
using namespace std;

int main() {
  int r, c, graph[101][101];
  cin >> r >> c;

  for (int i = 0; i < r + 1; i++) {
    for (int j = 0; j < c + 1; j++) {
      graph[i][j] = 0;
    }
  }

  for (int i = 0; i < r; i++) {
    for (int j = 0; j < c; j++) {
      cin >> graph[i][j];
    }
    for (int j = 0; j < c; j++) {
      graph[i][c] += graph[i][j];
    }
  }

  for (int j = 0; j < c + 1; j++) {
    for (int i = 0; i < r; i++) {
      graph[r][j] += graph[i][j];
    }
  }

  for (int i = 0; i < r + 1; i++) {
    for (int j = 0; j < c + 1; j++) {
      printf("%d", graph[i][j]);
      if (j != c)
        printf(" ");
    }
    printf("\\n");
  }

  return 0;
}


#include <iostream>

using namespace std;

int main() {
  int r, c, i, j;
  int table[100][100] = {0};
  cin >> r >> c;
  for (i = 0; i < r; i++) {
    for (j = 0; j < c; j++) {
      cin >> table[i][j];
      table[i][c] += table[i][j];
      table[r][j] += table[i][j];
      table[r][c] += table[i][j];
    }
  }
  for (i = 0; i <= r; i++) {
    for (j = 0; j <= c; j++) {
      cout << table[i][j];
      if (j < c)
        cout << " ";
      else
        cout << "\\n";
    }
  }
}

#include <iostream>

using namespace std;

int main() {
  int r, c, i, j;
  int table[101][101] = {0};
  cin >> r >> c;
  for (i = 0; i < r; i++) {
    for (j = 0; j < c; j++) {
      cin >> table[i][j];
      table[i][c] += table[i][j];
      table[r][j] += table[i][j];
      table[r][c] += table[i][j];
    }
  }
  for (i = 0; i <= r; i++) {
    for (j = 0; j <= c; j++) {
      cout << table[i][j];
      if (j < c)
        cout << " ";
      else
        cout << "\\n";
    }
  }
}


#include <iostream>

using namespace std;

int main() {
  int r, c;
  cin >> r >> c;

  int a[100][100] = {{}};

  for (int i = 0; i < r; i++) {
    for (int j = 0; j < c; j++) {
      cin >> a[i][j];
      a[i][c] += a[i][j];
      a[r][j] += a[i][j];
      a[r][c] += a[i][j];
    }
  }

  for (int i = 0; i <= r; i++) {
    for (int j = 0; j <= c; j++) {
      cout << a[i][j];
      if (j != c)
        cout << " ";
      else
        cout << endl;
    }
  }

  return 0;
}

#include <iostream>

using namespace std;

int main() {
  int r, c;
  cin >> r >> c;

  int a[101][101] = {{}};

  for (int i = 0; i < r; i++) {
    for (int j = 0; j < c; j++) {
      cin >> a[i][j];
      a[i][c] += a[i][j];
      a[r][j] += a[i][j];
      a[r][c] += a[i][j];
    }
  }

  for (int i = 0; i <= r; i++) {
    for (int j = 0; j <= c; j++) {
      cout << a[i][j];
      if (j != c)
        cout << " ";
      else
        cout << endl;
    }
  }

  return 0;
}


#include <iostream>
using namespace std;

int main(int argc, char const *argv[]) {
  int r, c, M[100][100];

  cin >> r >> c;
  for (int i = 0; i < r; i++)
    for (int j = 0; j < c; j++)
      cin >> M[i][j];

  for (int i = 0; i < r; i++)
    for (int j = 0; j < c; j++) {
      M[i][c] += M[i][j];
      M[r][j] += M[i][j];
      M[r][c] += M[i][j];
    }

  for (int i = 0; i <= r; i++) {
    for (int j = 0; j <= c; j++) {
      if (j)
        cout << " ";
      cout << M[i][j];
    }
    cout << endl;
  }

  return 0;
}

#include <iostream>
using namespace std;

int main() {
  int r, c, M[101][101];

  cin >> r >> c;
  for (int i = 0; i < r; i++)
    for (int j = 0; j < c; j++)
      cin >> M[i][j];

  for (int i = 0; i < r; i++)
    M[i][c] = 0;
  for (int j = 0; j < c; j++)
    M[r][j] = 0;
  M[r][c] = 0;

  for (int i = 0; i < r; i++)
    for (int j = 0; j < c; j++) {
      M[i][c] += M[i][j];
      M[r][j] += M[i][j];
      M[r][c] += M[i][j];
    }

  for (int i = 0; i <= r; i++) {
    for (int j = 0; j <= c; j++) {
      if (j)
        cout << " ";
      cout << M[i][j];
    }

    cout << endl;
  }

  return 0;
}


#include <iostream>
using namespace std;
#define M 100

int main() {
  int r, c, mat[M][M];

  for (int i = 0; i < M; i++)
    for (int j = 0; j < M; j++)
      mat[i][j] = 0;

  cin >> r >> c;
  for (int i = 0; i < r; i++)
    for (int j = 0; j < c; j++)
      cin >> mat[i][j];

  for (int i = 0; i < r; i++) {
    for (int j = 0; j < c; j++) {
      mat[i][c] += mat[i][j];
    }
  }

  for (int i = 0; i < r; i++) {
    for (int j = 0; j < c; j++) {
      mat[r][j] += mat[i][j];
    }
  }

  for (int i = 0; i < r; i++) {
    for (int j = 0; j < c; j++) {
      mat[r][c] += mat[i][j];
    }
  }

  for (int i = 0; i <= r; i++) {
    for (int j = 0; j <= c; j++) {
      if (!j)
        cout << mat[i][j];
      else
        cout << ' ' << mat[i][j];
    }
    cout << endl;
  }

  return 0;
}

#include <iostream>
using namespace std;
#define M 1000

int main() {
  int r, c, mat[M][M];

  for (int i = 0; i < M; i++)
    for (int j = 0; j < M; j++)
      mat[i][j] = 0;

  cin >> r >> c;
  for (int i = 0; i < r; i++)
    for (int j = 0; j < c; j++)
      cin >> mat[i][j];

  for (int i = 0; i < r; i++) {
    for (int j = 0; j < c; j++) {
      mat[i][c] += mat[i][j];
    }
  }

  for (int i = 0; i < r; i++) {
    for (int j = 0; j < c; j++) {
      mat[r][j] += mat[i][j];
    }
  }

  for (int i = 0; i < r; i++) {
    for (int j = 0; j < c; j++) {
      mat[r][c] += mat[i][j];
    }
  }

  for (int i = 0; i <= r; i++) {
    for (int j = 0; j <= c; j++) {
      if (!j)
        cout << mat[i][j];
      else
        cout << ' ' << mat[i][j];
    }
    cout << endl;
  }

  return 0;
}


#include <iostream>
#include <stdio.h>
using namespace std;

int main() {
  int r, c;
  int i, j;
  int d[100][100];
  int cc = 0;
  int cr = 0;

  cin >> r >> c;

  for (i = 0; i < r; i++) {
    for (j = 0; j < c; j++) {
      cin >> d[i][j];
      cc = cc + d[i][j];
      if (j == c - 1)
        d[i][j + 1] = cc;
    }
    cc = 0;
  }

  for (j = 0; j < c + 1; j++) {
    for (i = 0; i < r; i++) {
      cr = cr + d[i][j];
      if (i == r - 1)
        d[i + 1][j] = cr;
    }
    cr = 0;
  }

  for (i = 0; i < r + 1; i++) {
    for (j = 0; j < c + 1; j++) {
      if (j == c) {
        cout << d[i][j] << endl;
        ;
      } else {
        cout << d[i][j] << ' ';
      }
    }
  }

  return 0;
}

#include <iostream>
#include <stdio.h>
using namespace std;

int main() {
  int r, c;
  int i, j;
  int d[101][101];
  int cc = 0;
  int cr = 0;

  cin >> r >> c;

  for (i = 0; i < r; i++) {
    for (j = 0; j < c; j++) {
      cin >> d[i][j];
      cc = cc + d[i][j];
      if (j == c - 1)
        d[i][j + 1] = cc;
    }
    cc = 0;
  }

  for (j = 0; j < c + 1; j++) {
    for (i = 0; i < r; i++) {
      cr = cr + d[i][j];
      if (i == r - 1)
        d[i + 1][j] = cr;
    }
    cr = 0;
  }

  for (i = 0; i < r + 1; i++) {
    for (j = 0; j < c + 1; j++) {
      if (j == c) {
        cout << d[i][j] << endl;
        ;
      } else {
        cout << d[i][j] << ' ';
      }
    }
  }

  return 0;
}


#include <iostream>
using namespace std;

int main() {
  int r, c, i, j;
  int n = 0;
  int s = 0;
  int sum = 0;

  cin >> r >> c;

  int a[r][c];

  for (i = 0; i < r; i++) {
    for (j = 0; j < c; j++) {
      cin >> a[i][j];
    }
  }

  for (i = 0; i < r; i++) {
    for (j = 0; j < c; j++) {
      n = n + a[i][j];
      cout << a[i][j] << " ";
    }
    cout << n << endl;
  }

  for (j = 0; j < c; j++) {
    for (i = 0; i < r; j++) {
      s = s + a[i][j];
    }
    cout << s << " ";
  }
  for (i = 0; i < r; i++) {
    for (j = 0; j < c; j++) {
      sum = sum + a[i][j];
    }
  }
  cout << sum << endl;
}

#include <iostream>
using namespace std;

int main() {
  int r, c, i, j;
  int n, s;
  int w = 0;

  cin >> r >> c;

  int a[r][c];

  for (i = 0; i < r; i++) {
    for (j = 0; j < c; j++) {
      cin >> a[i][j];
    }
  }

  for (i = 0; i < r; i++) {
    n = 0;
    for (j = 0; j < c; j++) {
      n = n + a[i][j];
      cout << a[i][j] << " ";
    }
    cout << n << endl;
    ;
  }

  for (j = 0; j < c; j++) {
    s = 0;
    for (i = 0; i < r; i++) {
      s = s + a[i][j];
    }
    w = w + s;
    cout << s << " ";
  }

  cout << w << endl;
}


#include <iostream>
using namespace std;

int main() {
  int r, c, a[100][100] = {0};

  cin >> r >> c;
  // DWORD start = GetTickCount();//スタート時間

  for (int i = 0; i < r; i++) {
    for (int j = 0; j < c; j++) {
      cin >> a[i][j];
      a[i][c] += a[i][j];
      a[r][j] += a[i][j];
    }
    a[r][c] += a[i][c];
  }

  for (int i = 0; i <= r; i++) {
    for (int j = 0; j <= c; j++) {
      cout << a[i][j];
      if (j < c) {
        cout << ' ';
      }
    }
    cout << endl;
  }

  // DWORD end = GetTickCount();//終了時間
  // cout << "time = " << (double)(end - start) / 1000 << "sec.\\n";

  return 0;
}

#include <iostream>
using namespace std;

int main() {
  int r, c, a[101][101] = {0};

  cin >> r >> c;
  // DWORD start = GetTickCount();//スタート時間

  for (int i = 0; i < r; i++) {
    for (int j = 0; j < c; j++) {
      cin >> a[i][j];
      a[i][c] += a[i][j];
      a[r][j] += a[i][j];
    }
    a[r][c] += a[i][c];
  }

  for (int i = 0; i <= r; i++) {
    for (int j = 0; j <= c; j++) {
      cout << a[i][j];
      if (j < c) {
        cout << ' ';
      }
    }
    cout << endl;
  }

  // DWORD end = GetTickCount();//終了時間
  // cout << "time = " << (double)(end - start) / 1000 << "sec.\\n";

  return 0;
}


#include <iostream>
#include <vector>
using namespace std;

int main() {
  long r, c;
  cin >> r >> c;
  vector<vector<long>> sp(r);
  for (long i = 0; i < r; i++) {
    sp[i].resize(c);
  }
  vector<long> rsum(r, 0);
  vector<long> csum(c, 0);
  for (long i = 0; i < r; i++) {
    for (long j = 0; j < c; j++) {
      rsum[i] += sp[i][j];
    }
  }
  for (long i = 0; i < c; i++) {
    for (long j = 0; j < r; j++) {
      csum[i] += sp[j][i];
    }
  }
  long sum = 0;
  for (long i = 0; i < r; i++) {
    sum += rsum[i];
  }
  vector<vector<long>> newsp(r + 1);
  for (long i = 0; i < r + 1; i++) {
    newsp[i].resize(c + 1);
  }
  for (long i = 0; i < r + 1; i++) {
    for (long j = 0; j < c + 1; j++) {
      if (i < r && j < c)
        newsp[i][j] = sp[i][j];
      else if (i = r && j < c)
        newsp[i][j] = csum[j];
      else if (j = c && i < r)
        newsp[i][j] = rsum[i];
      else
        newsp[i][j] = sum;
    }
  }
  for (long i = 0; i < r + 1; i++) {
    for (long j = 0; j < c + 1; j++) {
      cout << newsp[i][j];
    }
    cout << endl;
  }
  return 0;
}

#include <iostream>
#include <vector>
using namespace std;

int main() {
  long r, c;
  cin >> r >> c;
  // r = 2;
  // c = 2;
  vector<vector<long>> sp(r);
  for (long i = 0; i < r; i++) {
    sp[i].resize(c);
  }
  for (long i = 0; i < r; i++) {
    for (long j = 0; j < c; j++) {
      cin >> sp[i][j];
    }
  }
  vector<long> rsum(r, 0);
  vector<long> csum(c, 0);
  for (long i = 0; i < r; i++) {
    for (long j = 0; j < c; j++) {
      rsum[i] += sp[i][j];
    }
  }
  for (long i = 0; i < c; i++) {
    for (long j = 0; j < r; j++) {
      csum[i] += sp[j][i];
    }
  }
  long sum = 0;
  for (long i = 0; i < r; i++) {
    sum += rsum[i];
  }
  for (long i = 0; i < r; i++) {
    for (long j = 0; j < c; j++) {
      cout << sp[i][j] << " ";
    }
    cout << rsum[i] << endl;
  }
  for (long i = 0; i < c; i++) {
    cout << csum[i] << " ";
  }
  cout << sum << endl;
  /*
  vector< vector<long> > newsp(r + 1);
  for (long i = 0; i < r + 1; i++){
          newsp[i].resize(c + 1);
  }
  for (long i = 0; i < r + 1; i++){
          for (long j = 0; j < c + 1; j++){
                  if (i < r && j < c) newsp[i][j] = sp[i][j];
                  else if (i = r && j < c) newsp[i][j] = csum[j];
                  else if (j = c && i < r) newsp[i][j] = rsum[i];
                  else newsp[i][j] = sum;
          }
  }
  for (long i = 0; i < r + 1; i++){
          for (long j = 0; j < c + 1; j++){
                  cout << newsp[i][j];
          }
          cout << endl;
  }
  */
  return 0;
}


#include <iostream>
using namespace std;
int main() {
  int r, c, s;
  int **a;
  cin >> r >> c;
  a = new int *[r + 1];
  for (int i = 0; i < r; ++i) {
    a[i] = new int[c + 1];
    s = 0;
    for (int j = 0; j < c; ++j) {
      cin >> a[i][j];
      s += a[i][j];
    }
    a[i][c] = s;
  }

  for (int j = 0; j < c; ++j) {
    s = 0;
    for (int i = 0; i < r; ++i)
      s += a[i][j];
    a[r][j] = s;
  }

  for (int i = 0; i < r; ++i) {
    for (int j = 0; j <= c; ++j)
      cout << a[i][j] << " ";
    cout << endl;
  }

  s = 0;
  for (int i = 0; i < c; ++i) {
    s += a[r][i];
    cout << a[r][i] << " ";
  }
  cout << s << endl;
  return 0;
}

#include <iostream>
using namespace std;
int main() {
  int r, c, s;
  int **a;
  cin >> r >> c;
  a = new int *[r + 1];
  for (int i = 0; i < r; ++i) {
    a[i] = new int[c + 1];
    s = 0;
    for (int j = 0; j < c; ++j) {
      cin >> a[i][j];
      s += a[i][j];
    }
    a[i][c] = s;
  }
  a[r] = new int[c + 1];
  for (int j = 0; j < c; ++j) {
    s = 0;
    for (int i = 0; i < r; ++i)
      s += a[i][j];
    a[r][j] = s;
  }

  for (int i = 0; i < r; ++i) {
    for (int j = 0; j <= c; ++j) {
      cout << a[i][j];
      if (j != c)
        cout << " ";
    }
    cout << endl;
  }

  s = 0;
  for (int i = 0; i < c; ++i) {
    s += a[r][i];
    cout << a[r][i] << " ";
  }
  cout << s << endl;
  return 0;
}


#include <iostream>
using namespace std;

int main() {
  int r, c;
  cin >> r >> c;

  int mat[100][100];

  for (int i = 0; i < r; i++) {
    for (int j = 0; j < c; j++) {
      cin >> mat[i][j];
      mat[i][c] += mat[i][j];
      mat[r][j] += mat[i][j];
      mat[r][c] += mat[i][j];
    }
  }

  for (int i = 0; i < r + 1; i++) {
    for (int j = 0; j < c + 1; j++) {
      if (j == c)
        cout << mat[i][j] << endl;
      else
        cout << mat[i][j] << " ";
    }
  }
}

#include <iostream>
using namespace std;

int main() {
  int r, c;
  cin >> r >> c;

  int mat[101][101] = {};

  for (int i = 0; i < r; i++) {
    for (int j = 0; j < c; j++) {
      cin >> mat[i][j];
      mat[i][c] += mat[i][j];
      mat[r][j] += mat[i][j];
      mat[r][c] += mat[i][j];
    }
  }

  for (int i = 0; i < r + 1; i++) {
    for (int j = 0; j < c + 1; j++) {
      if (j == c)
        cout << mat[i][j] << endl;
      else
        cout << mat[i][j] << " ";
    }
  }
}


#include <iostream>

int main() {
  int r, c, i;
  std::cin >> r >> c;
  int list[100][100] = {0};
  for (int a = 0; a < r; a++) {
    for (int b = 0; b < c; b++) {
      std::cin >> i;
      list[a][b] = i;
      list[a][c] = list[a][c] + i;
      list[r][b] = list[r][b] + i;
      list[r][c] = list[r][c] + i;
    }
  }
  for (int d = 0; d <= r; d++) {
    for (int e = 0; e <= c; e++) {
      if (e < c) {
        std::cout << list[d][e] << " ";
      } else {
        std::cout << list[d][e];
      }
    }
    std::cout << std::endl;
  }
  return 0;
}

#include <iostream>

int main() {
  int r, c, i;
  std::cin >> r >> c;
  int list[101][101] = {0};
  for (int a = 0; a < r; a++) {
    for (int b = 0; b < c; b++) {
      std::cin >> i;
      list[a][b] = i;
      list[a][c] = list[a][c] + i;
      list[r][b] = list[r][b] + i;
      list[r][c] = list[r][c] + i;
    }
  }
  for (int d = 0; d <= r; d++) {
    for (int e = 0; e <= c; e++) {
      if (e < c) {
        std::cout << list[d][e] << " ";
      } else {
        std::cout << list[d][e];
      }
    }
    std::cout << std::endl;
  }
  return 0;
}


#include <cmath>
#include <cstdio>
#include <iostream>
using namespace std;
int main() {
  freopen("input.txt", "r", stdin);
  int n, f, k = 0, m = 0, max = 0;
  cin >> n >> f;
  int a[n + 1][f + 1];
  for (int i = 0; i < n; i++) {
    k = 0;
    for (int j = 0; j < f; j++) {
      cin >> a[i][j];
      k += a[i][j];
    }
    a[i][f] = k;
  }
  for (int i = 0; i < f; i++) {
    m = 0;
    for (int j = 0; j < n; j++) {
      m += a[j][i];
    }
    a[n][i] = m;
  }
  for (int i = 0; i < f; i++) {
    max += a[n][i];
  }
  a[n][f] = max;
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j <= f; j++) {
      cout << a[i][j] << " ";
    }
    cout << endl;
  }
}

#include <bits/stdc++.h>
using namespace std;

int arr[199][199];
int reg[199];

int main() {
  int a, b;
  cin >> a >> b;
  for (int i = 0; i < a; i++) {
    for (int j = 0; j < b; j++) {
      cin >> arr[i][j];
    }
  }
  for (int i = 0; i < a; i++) {
    int sum = 0, c = 0;
    for (int j = 0; j < b; j++) {
      if (c != 0)
        cout << " ";
      cout << arr[i][j];
      sum += arr[i][j];
      reg[j] += arr[i][j];
      c++;
    }
    cout << " " << sum;
    reg[b] += sum;
    cout << endl;
  }
  int c = 0;
  for (int i = 0; i <= b; i++) {
    if (c != 0)
      cout << " ";
    cout << reg[i];
    c++;
  }
  cout << endl;
}


#include <iostream>
#include <vector>
using namespace std;

int main() {
  int r, c;
  cin >> r >> c;
  vector<vector<int>> v(r + 1, vector<int>(c + 1, 0));
  for (int i = 0; i < r; i++) {
    for (int j = 0; j < c; j++) {
      cin >> v[i][j];
    }
  }

  for (int i = 0; i < r; i++) {

    for (int j = 0; j < c; j++) {
      v[i][c] += v[i][j];
    }
  }

  for (int i = 0; i < c + 1; i++) {
    for (int j = 0; j < r; j++) {
      v[r][i] += v[i][j];
    }
  }

  for (int i = 0; i < r + 1; i++) {
    for (int j = 0; j < c + 1; j++) {
      cout << v[i][j] << " ";
    }
    cout << endl;
  }

  return 0;
}

#include <iostream>
#include <vector>
using namespace std;

int main() {
  int r, c;
  cin >> r >> c;
  vector<vector<int>> v(r + 1, vector<int>(c + 1, 0));
  for (int i = 0; i < r; i++) {
    for (int j = 0; j < c; j++) {
      cin >> v[i][j];
    }
  }

  for (int i = 0; i < r; i++) {

    for (int j = 0; j < c; j++) {
      v[i][c] += v[i][j];
    }
  }

  for (int i = 0; i < c + 1; i++) {
    for (int j = 0; j < r; j++) {
      v[r][i] += v[j][i];
    }
  }

  for (int i = 0; i < r + 1; i++) {
    for (int j = 0; j < c + 1; j++) {
      cout << v[i][j];
      if (j < c) {
        cout << " ";
      }
    }
    cout << endl;
  }

  return 0;
}


#include <iostream>
#include <string>

int main() {
  bool break_key = true;
  while (break_key || std::cin.eof()) {

    std::string str = "";
    std::cin >> str;
    std::string ans = str;
    std::string period = ".";
    for (int i = 0; i < str.length(); i++) {

      if (str[i] == tolower(str[i])) {
        ans[i] = toupper(str[i]);
      } else if (str[i] == toupper(str[i])) {
        ans[i] = tolower(str[i]);
      }
    }

    std::cout << ans;
    if ((char)ans[ans.length() - 1] == '.') {
      std::cout << std::endl;
      break_key = false;
    } else if (!std::cin.eof()) {
      std::cout << " ";
    }
  }
}

#include <iostream>
#include <stdio.h>
#include <string>
int main() {
  std::string input;
  std::string output;
  std::cin >> input;
  int temp;
  while (1) {
    temp = getchar();
    if (temp == '\\n') {
      break;
    }
    input += temp;
  }

  output = input;

  for (int i = 0; i < input.length(); i++) {
    if (97 <= input[i] && input[i] <= 122) {
      output[i] = input[i] - 32;
    } else if (65 <= input[i] && input[i] <= 90) {
      output[i] = input[i] + 32;
    } else {
      output[i] = input[i];
    }
  }
  std::cout << output;
  std::cout << std::endl;
}


#include <cctype>
#include <iostream>

using namespace std;

int main(int argc, char const *argv[]) {
  char ch;
  while (1) {
    cin >> ch;
    if (ch == '\\n')
      break;
    if (isupper(ch))
      cout << tolower(ch);
    else if (islower(ch))
      cout << toupper(ch);
    else
      cout << ch;
  }
  cout << endl;
  return 0;
}

#include <cctype>
#include <cstdio>

using namespace std;

int main(int argc, char const *argv[]) {
  char ch;
  while (1) {
    scanf("%c", &ch);
    if (isalpha(ch)) {
      if (islower(ch)) {
        printf("%c", toupper(ch));
      } else
        printf("%c", tolower(ch));
    } else
      printf("%c", ch);
    if (ch == '\\n')
      break;
  }
  return 0;
}


#include <cstdio>
#include <iostream>
#include <string>

using namespace std;

int main(void) {

  string komozi("abcdefghijklmnopqrstuvwxyz");
  string oomozi("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
  char inp;
  char retsu[1000000];

  for (int i = 0;; i++) {
    inp = getchar();
    if (inp == '.') {
      retsu[i] = '.';
      retsu[i + 1] = '\\0';
      break;
    }
    if (komozi.find(inp) != -1)
      retsu[i] = oomozi[komozi.find(inp)];
    else if (oomozi.find(inp) != -1)
      retsu[i] = komozi[oomozi.find(inp)];
    else
      retsu[i] = inp;
  }

  cout << retsu << endl;

  return 0;
}

#include <cstdio>
#include <iostream>
#include <string>

using namespace std;

int main(void) {

  string komozi("abcdefghijklmnopqrstuvwxyz");
  string oomozi("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
  char inp;
  char retsu[1000000];

  for (int i = 0;; i++) {
    inp = getchar();
    if (inp == '\\n') {
      retsu[i + 1] = '\\0';
      break;
    }
    if (komozi.find(inp) != -1)
      retsu[i] = oomozi[komozi.find(inp)];
    else if (oomozi.find(inp) != -1)
      retsu[i] = komozi[oomozi.find(inp)];
    else
      retsu[i] = inp;
  }

  cout << retsu << endl;

  return 0;
}


#include <cctype>
#include <iostream>

using namespace std;

int main() {
  char ch;

  while (1) {
    cin >> ch;

    if (islower(ch))
      ch = toupper(ch);
    else if (isupper(ch))
      ch = tolower(ch);
    cout << ch;
    if (ch == '\\n')
      break;
  }

  return 0;
}

#include <cctype>
#include <cstdio>
#include <iostream>

using namespace std;

int main() {
  char ch;

  while (1) {
    scanf("%c", &ch);

    if (islower(ch))
      ch = toupper(ch);
    else if (isupper(ch))
      ch = tolower(ch);
    printf("%c", ch);
    if (ch == '\\n')
      break;
  }

  return 0;
}


#include <cctype>
#include <cstdio>
#include <iostream>
using namespace std;

int main() {
  while (1) {
    char ch;
    cin >> ch;

    if (ch == '\\n')
      break;

    if (islower(ch))
      cout << toupper(ch);
    else if (isupper(ch))
      cout << tolower(ch);
    else
      cout << ch;
  }
  cout << endl;
  return 0;
}

#include <cctype>
#include <cstdio>
#include <iostream>
using namespace std;

int main() {
  char ch;

  while (1) {
    scanf("%c", &ch);

    if (islower(ch))
      printf("%c", toupper(ch));
    else if (isupper(ch))
      printf("%c", tolower(ch));
    else
      printf("%c", ch);

    if (ch == '\\n')
      break;
  }
  return 0;
}


#include <algorithm>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;

int main() {
  char str[1300];
  int word = 0;
  while (1) {
    char s;
    cin >> s;

    char output;
    output = s;
    if (isalpha(s)) {
      if (islower(s)) {
        output = toupper(s);
      } else {
        output = tolower(s);
      }
    }
    str[word] = output;
    word += 1;
    if (s == '\\n') {
      break;
    }
  }
  int count = 0;
  while (1) {
    cout << str[count];
    if (str[count] == '\\n') {
      break;
    } else {
      count += 1;
    }
  }

  return 0;
}

#include <algorithm>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;

int main() {
  char str[1300];
  int word = 0;
  while (1) {
    char s;
    scanf("%c", &s);
    char output;
    output = s;
    if (isalpha(s)) {
      if ('a' <= s && s <= 'z') {
        output = toupper(s);
      } else {
        output = tolower(s);
      }
    }
    str[word] = output;
    word += 1;
    if (s == '\\n') {
      break;
    }
  }
  int count = 0;
  // cout << "convert"<< endl;
  while (1) {

    if (str[count] == '\\n') {
      cout << '\\n';
      break;
    } else {
      cout << str[count];
      count += 1;
    }
  }

  return 0;
}


#include <cctype>
#include <iostream>
using namespace std;

int main() {
  char ch;

  while (1) {
    cin >> ch;
    if (islower(ch))
      ch = toupper(ch);
    else if (isupper(ch))
      ch = tolower(ch);
    cout << ch;
    if (ch == '\\n')
      break;
  }
  return 0;
}

#include <cctype>
#include <cstdio>
#include <iostream>

using namespace std;

int main() {

  char ch;

  while ((ch = getchar()) != EOF) {
    if (islower(ch))
      ch = toupper(ch);
    else
      ch = tolower(ch);
    cout << ch;
  }

  return 0;
}


#include <iostream>

using namespace std;

int main() {
  char ch;

  while (1) {
    cin >> ch;

    if (islower(ch)) {
      ch = toupper(ch);
    }

    else if (isupper(ch)) {
      ch = tolower(ch);
    }

    cout << ch;
    if (ch == '\\n')
      break;
  }
  return 0;
}

#include <ctype.h>
#include <stdio.h>
main() {
  char ch;

  while (1) {
    scanf("%c", &ch);
    if (islower(ch)) {
      ch = toupper(ch);
    } else if (isupper(ch)) {
      ch = tolower(ch);
    }
    printf("%c", ch);

    if (ch == '\\n')
      break;
  }
  return 0;
}


#include <cctype>
#include <iostream>

int main() {
  char word[1200];

  for (int i = 0;; i++) {
    std::cin >> word[i];

    if (std::islower(word[i])) {
      word[i] = std::toupper(word[i]);
    }

    else if (std::isupper(word[i])) {
      word[i] = std::tolower(word[i]);
    }
    std::cout << word[i];
  }
}

#include <algorithm>
#include <cctype>
#include <iostream>
#include <string>

int main() {
  std::string word;
  std::getline(std::cin, word);
  for (int i = 0; i < word.size(); i++) {
    if (std::islower(word[i])) {
      word[i] = std::toupper(word[i]);
    } else if (std::isupper(word[i])) {
      word[i] = std::tolower(word[i]);
    }
    std::cout << word[i];
  }
  std::cout << std::endl;
}


#include <iostream>
using namespace std;

int main() {
  char c;
  while (1) {
    cin >> c;
    if (c == '\\n')
      break;
    else if ('A' <= c && c <= 'Z')
      c += 'a' - 'A';
    else if ('a' <= c && c <= 'z')
      c -= 'a' - 'A';
    cout << c;
  }
  cout << endl;
  return 0;
}

#include <iostream>
using namespace std;

int main() {
  char c;
  while (1) {
    cin.get(c);
    if (c == '\\n')
      break;
    else if ('A' <= c && c <= 'Z')
      c += 'a' - 'A';
    else if ('a' <= c && c <= 'z')
      c -= 'a' - 'A';
    cout.put(c);
  }
  cout << endl;
  return 0;
}


#include <cctype>
#include <cstdio>

int main() {
  char ch;

  while (1) {
    scanf("%c", &ch);
    if (islower(ch))
      printf("%c", toupper(ch));
    else if (isupper(ch))
      printf("%c", tolower(ch));
    else if (!isalpha(ch))
      printf("%c", ch);
    else if (ch == '\\n')
      break;
  }

  return 0;
}

#include <cctype>
#include <cstdio>

int main() {
  char ch;

  while (1) {
    scanf("%c", &ch);
    if (islower(ch))
      printf("%c", toupper(ch));
    else if (isupper(ch))
      printf("%c", tolower(ch));
    else if (!isalpha(ch))
      printf("%c", ch);
    if (ch == '\\n')
      break;
  }

  return 0;
}


#include <cctype>
#include <iostream>
using namespace std;

int main() {
  char ch;
  while (1) {
    cin >> ch;
    if (ch == '\\n')
      break;
    if (islower(ch))
      ch = toupper(ch);
    else if (isupper(ch))
      ch = tolower(ch);
    cout << ch;
  }
  return 0;
}

#include <cctype>
#include <iostream>
using namespace std;

int main() {
  char ch;
  while (1) {
    cin.get(ch);
    if (ch == '\\n')
      break;
    if (islower(ch))
      ch = toupper(ch);
    else if (isupper(ch))
      ch = tolower(ch);
    cout << ch;
  }
  cout << endl;
  return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main() {
  bool a;
  string s;
  cin >> s;
  for (int i = 0; i < s.size(); i++) {
    a = false;
    if (s[i] != ',' && s[i] != ' ' && s[i] != '.') {
      for (char c = 'a'; i <= 'z'; c++) {
        if (s[i] == c) {
          a = true;
        }
      }
      if (a == true) {
        s[i] -= 32;
      } else {
        s[i] += 32;
      }
    }
  }
  cout << s << endl;
  return 0;
}

#include <bits/stdc++.h>
using namespace std;

int main() {
  string s;
  getline(cin, s);
  for (int i = 0; i < s.size(); i++) {
    if (s[i] >= 'a' && s[i] <= 'z') {
      s[i] -= 32;
    } else if (s[i] >= 'A' && s[i] <= 'Z') {
      s[i] += 32;
    }
  }
  cout << s << endl;
  return 0;
}


#define _USE_MATH_DEFINES
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <sstream>
#include <string>
#include <vector>

using namespace std;
int main() {
  while (true) {
    string x;
    cin >> x;
    for (int i = 0; i < x.size(); i++) {
      if ('a' <= x[i] && x[i] <= 'z')
        cout << (char)(x[i] + ('A' - 'a'));
      else if ('A' <= x[i] && x[i] <= 'Z')
        cout << (char)(x[i] + ('a' - 'A'));
      else
        cout << x[i];
    }
    cout << endl;
  }
  return 0;
}

#define _USE_MATH_DEFINES
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <sstream>
#include <string>
#include <vector>

using namespace std;
int main() {
  string x;
  getline(cin, x);
  for (int i = 0; i < x.size(); i++) {
    if ('a' <= x[i] && x[i] <= 'z')
      cout << (char)(x[i] + ('A' - 'a'));
    else if ('A' <= x[i] && x[i] <= 'Z')
      cout << (char)(x[i] + ('a' - 'A'));
    else
      cout << x[i];
  }
  cout << endl;
  return 0;
}


#include <cctype>
#include <cstdio>
#include <iostream>
#include <string.h>

using namespace std;

int main() {
  char c[1200];
  cin.getline(c, sizeof(c));

  for (int i = 0; isspace(c[i]) != 1; i++) {
    if (islower(c[i])) {
      putchar(toupper(c[i]));
    } else if (isupper(c[i])) {
      putchar(tolower(c[i]));
    } else if (c[i] == ',') {
      cout << ",";
    } else if (c[i] == '.') {
      cout << ".";
    } else {
      cout << " ";
    }
  }

  cout << "." << endl;
}

#include <cctype>
#include <cstdio>
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;

int main() {
  char a[1300];
  cin.getline(a, sizeof(a));
  char c[strlen(a)];
  strcpy(c, a);

  for (int i = 0; i < strlen(c); i++) {

    if (islower(c[i])) {
      putchar(toupper(c[i]));
    } else if (isupper(c[i])) {
      putchar(tolower(c[i]));
    } /*else if(c[i]==','){
         cout<<",";
     }else if(c[i]=='.'){
         cout<<".";
     }else if(isspace(c)){
         cout<<" ";
     }*/
    else {
      cout << c[i];
    }
  }

  cout << endl;
}

Fair, later, occasionally cloudy.  Q       Q                                                                                Q                       Q     P      x        P                                         Q    xQ              X                        A      H  Q    h   cv                                                             Q                    H  Q     v              h   cv  IS                              X                                                                                Y       Z                                                                                Z      H       X                                                                                X                N       I                         Q                                  j          O      hN       Q       P      o        O               P      hN       I            j           b      O       R  cv          x  Q    x  Q    IS b  Os        H  Q    h   cv          IS l g  IS  T                                   x  Q          j           b      R  cv  h   cv                           Q  cv  p  Q                     Q  cv  h  Q                       Q            K  Q       Q       Q       Q       Q    J  Q    T  Q       Q       Q       Q       Q       Q       Q       Q       Q    N  Q    V  Q       Q       Q       Q       Q       Q       Q    c  Q    A  Q       Q       Q       Q       Q       Q       Q       Q       Q       Q    n  Q       Q    U  Q       Q       Q       Q       Q    r  Q    a  Q    u  Q    L  Q    W  Q       Q       Q       Q       Q       Q       Q       Q    h  Q    X  Q       Q       Q                     P Q                                                            D                   cv                                                                           Q  cv                                                                                Q                               Q               Q                           j         X                                                                                TMP   B BCAA       DAD B            F   .OUT pwd  HOME ALEX dOCUMENTS BUG DETECTION openai api key SK nhK yMu NvBw WTlupxPt bLBKfjr l fK l  rQRRBfWafZ virtual env prompt  .VENV    old fish prompt override  HOME ALEX dOCUMENTS BUG DETECTION .VENV dbus session bus address UNIX PATH  RUN USER      BUS gtk csd   home  HOME ALEX tmux pane    tmux plugin manager path  HOME ALEX .TMUX PLUGINS  lc measurement EN us.utf   logname ALEX qt qpa platform WAYLAND XCB path  HOME ALEX .LOCAL BIN  HOME ALEX .CARGO BIN   HOME ALEX .LOCAL SHARE GEM RUBY  . .  BIN  HOME ALEX .LOCAL SHARE JOH


#include <iostream>
using namespace std;

int main() {
  char x, a;
  while (1) {
    cin >> x;
    if (islower(x)) {
      a = toupper(x);
      cout << a;
    } else if (isupper(x)) {
      a = tolower(x);
      cout << a;
    } else {
      cout << x;
    }
    if (x == '\\n') {
      break;
    }
  }
  return 0;
}

#include <cstdio>
#include <iostream>
using namespace std;

int main() {
  char x, a;
  while (1) {
    scanf("%c", &x);
    if (islower(x)) {
      a = toupper(x);
      cout << a;
    } else if (isupper(x)) {
      a = tolower(x);
      cout << a;
    } else {
      cout << x;
    }
    if (x == '\\n') {
      break;
    }
  }
  return 0;
}


#include <stdio.h>
int main(void) {
  char sentence[1200];
  char temp, i;
  scanf("%s", sentence);

  i = 0;
  do {
    char temp = sentence[i];

    if ('a' <= temp && temp <= 'z') {
      sentence[i] += 'A' - 'a';
      printf("%c", sentence[i]);
    } else if ('A' <= temp && temp <= 'Z') {
      sentence[i] -= 'A' - 'a';
      printf("%c", sentence[i]);
    } else {
      printf("%c", sentence[i]);
    }
    i++;
  } while (sentence[i - 1] != EOF || sentence[i - 1] != '\\n');

  puts("");

  return 0;
}

#include <ctype.h>
#include <stdio.h>
int main(void) {
  char ch;
  char temp, i;

  i = 0;
  while (1) {
    scanf("%c", &ch);

    if (islower(ch)) {
      printf("%c", toupper(ch));
    } else if (isupper(ch)) {
      printf("%c", tolower(ch));
    } else if (ch == '\\n') {
      break;
    } else {
      printf("%c", ch);
    }
  }

  puts("");

  return 0;
}


#include <cctype>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
typedef vector<int> vec;

int main() {
  char ch;
  while (1) {
    scanf("%c", &ch);
    if (islower(ch))
      printf("%c", toupper(ch));
    else
      printf("%c", tolower(ch));
    if (ch == '\\0')
      break;
  }
}

#include <cctype>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
typedef vector<int> vec;

int main() {
  char ch;
  while (1) {
    scanf("%c", &ch);
    if (islower(ch))
      printf("%c", toupper(ch));
    else
      printf("%c", tolower(ch));
    if (ch == '\\n')
      break;
  }
}


#include <cctype>
#include <iostream>
using namespace std;
int main() {
  char a;

  for (;;) {
    cin >> a;
    if (a == '\\n') {
      cout << endl;
      break;
    } else {
      if (islower(a)) {
        cout << (char)toupper(a);
      } else if (isupper(a)) {
        cout << (char)tolower(a);
      } else {
        cout << a;
      }
    }
  }
  cout << endl;
  return 0;
}

#include <cctype>
#include <iostream>
#include <stdio.h>
using namespace std;
int main() {
  char a;

  for (;;) {
    scanf("%c", &a);
    /* cin >> a; */
    if (a == '\\n') {
      cout << endl;
      break;
    } else {
      if (islower(a)) {
        printf("%c", toupper(a));
        /*cout <<  (char)toupper(a);*/
      } else if (isupper(a)) {
        printf("%c", tolower(a));
        /*cout <<  (char)tolower(a);*/
      } else {
        printf("%c", a);
        /*cout << a;*/
      }
    }
  }
  return 0;
}


#include <cctype>
#include <cstdio>
#include <iostream>
using namespace std;

int main() {
  char ch;
  while (1) {
    scanf("%c", &ch); // scanf???' '???????????????
    if (ch == '\\n')
      break;
    if (islower(ch) != 0) { //?°???????????????°true
      ch = toupper(ch);     //?°?????????? ??§??????
      cout << ch;
    } else if (isupper(ch) != 0) { //??§??????????????°true
      ch = tolower(ch);            //??§????????? ?°???????
      cout << ch;
    } else {
      cout << ch;
    }
  }
  cout << endl;
  return 0;
}


#include <cctype>
#include <cstdio>
using namespace std;
int main() {
  char ch;
  while (1) {
    scanf("%c", &ch);
    if (isalpha(ch)) {
      if (islower(ch))
        printf("%c", toupper(ch));
      else
        printf("%c", tolower(ch));
    } else
      printf("%c", ch);
  }
  return 0;
}

#include <cctype>
#include <cstdio>
using namespace std;
int main() {
  char ch;
  while (1) {
    scanf("%c", &ch);
    if (isalpha(ch)) {
      if (islower(ch))
        printf("%c", toupper(ch));
      else
        printf("%c", tolower(ch));
    } else
      printf("%c", ch);
    if (ch == '\\n')
      break;
  }
  return 0;
}


#include <cctype>
#include <cstdio>
#include <iostream>
using namespace std;

int main() {
  char ch;
  while (1) {
    cin >> ch; // scanf???' '???????????????
    if (ch == '\\n')
      break;
    if (islower(ch) != 0) { //?°???????????????°true
      ch = toupper(ch);     //?°?????????? ??§??????
      cout << ch;
    } else if (isupper(ch) != 0) { //??§??????????????°true
      ch = tolower(ch);            //??§????????? ?°???????
      cout << ch;
    } else {
      cout << ch;
    }
  }
  cout << endl;
  return 0;
}


#include <ctype.h>
#include <iostream>

using namespace std;

int main() {
  char c;
  while (true) {
    cin >> c;

    if (c == '\\n')
      break;

    if (isalpha(c)) {
      if (islower(c))
        cout << (char)toupper(c);
      if (isupper(c))
        cout << (char)tolower(c);
    } else
      cout << c;
  }
  cout << endl;
}

#include <ctype.h>
#include <iostream>
#include <stdio.h>

using namespace std;

int main() {
  char c;
  while (true) {
    scanf("%c", &c);

    if (isalpha(c)) {
      if (islower(c))
        cout << (char)toupper(c);
      else
        cout << (char)tolower(c);
    } else
      cout << c;

    if (c == '\\n')
      break;
  }
}


#include <cctype>
#include <cstdio>
#include <iostream>
using namespace std;
int main() {
  char ch;
  while (1) {
    scanf("%c", &ch);
    if (isalpha(ch)) {
      if (islower(ch))
        printf("%c", toupper(ch));
      else
        printf("%c", tolower(ch));
    } else
      printf("%c", ch);
  }
}

#include <cctype>
#include <cstdio>
#include <iostream>
using namespace std;
int main() {
  char ch;
  while (1) {
    scanf("%c", &ch);
    if (isalpha(ch)) {
      if (islower(ch))
        printf("%c", toupper(ch));
      else
        printf("%c", tolower(ch));
    } else
      printf("%c", ch);

    if (ch == '\\n')
      break;
  }
}


#include <cctype>
#include <cstdio>
#include <iostream>
using namespace std;
int main() {
  char ch;
  while (1) {
    cin >> ch;
    if (isalpha(ch)) {
      if (islower(ch))
        cout << (char)toupper(ch);
      if (isupper(ch))
        cout << (char)tolower(ch);
    } else {
      cout << ch;
    }
    if (ch == '\\n')
      break;
  }
  return 0;
}

#include <cctype>
#include <cstdio>
#include <iostream>
using namespace std;
int main() {
  char ch;
  while (1) {
    scanf("%c", &ch);
    if (isalpha(ch)) {
      if (islower(ch))
        cout << (char)toupper(ch);
      else if (isupper(ch))
        cout << (char)tolower(ch);
    } else {
      cout << ch;
    }
    if (ch == '\\n')
      break;
  }
  return 0;
}


#include <cctype>
#include <iostream>
using namespace std;

int main() {
  char ch;
  while (1) {
    cin >> ch;
    if (islower(ch))
      ch = toupper(ch);
    else if (isupper(ch))
      ch = tolower(ch);
    if (ch == '\\n')
      break;
    cout << ch;
  }

  return 0;
}

#include <cctype>
#include <iostream>
using namespace std;

int main() {
  int count = 0;
  string ch;
  getline(cin, ch);
  while (count < ch.size()) {
    if (ch[count] == ' ') {
      cout << ' ';
    } else if (islower(ch[count])) {
      ch[count] = toupper(ch[count]);
      cout << ch[count];
    } else if (isupper(ch[count])) {
      ch[count] = tolower(ch[count]);
      cout << ch[count];
    } else
      cout << ch[count];
    count++;
  }
  cout << endl;
  return 0;
}


#include <iostream>
using namespace std;
int main(void) {
  char c;

  while (1) {
    cin >> c;
    if ('a' <= c && c <= 'z') {
      c = c - 'a' + 'A';
    } else if ('A' <= c && c <= 'Z') {
      c = c - 'A' + 'a';
    }

    cout << c;
    if (c == '\\n')
      break;
  }

  return 0;
}

#include <bits/stdc++.h>
using namespace std;
int main(void) {
  char c;
  while (1) {
    scanf("%c", &c);
    if (isalpha(c)) {
      if ("%c", isupper(c))
        printf("%c", tolower(c));
      else if ("%c", islower(c))
        printf("%c", toupper(c));
    } else
      printf("%c", c);

    if (c == '\\n')
      break;
  }
  return 0;
}


#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;

int main() {
  char a;
  cin >> a;
  while (a != EOF) {
    if ('a' <= a && a <= 'z') {
      a = toupper(a);
      //	cout<<a;
    } else if ('A' <= a && a <= 'Z') {
      a = tolower(a);
      //	cout<<a;
    }
    ////else
    ////{
    //		if (a != ',' && a != '.')
    //			cout<<" ";
    //		else
    //			cout<<a;
    //}
    cout << a;
    cin >> a;
  }
  cout << endl;
  return 0;
}

#include <cctype>
#include <cstdio>
#include <iostream>

using namespace std;

int main() {

  char ch;
  ch = getchar();
  while (ch != EOF) {
    if (islower(ch))
      ch = toupper(ch);
    else
      ch = tolower(ch);
    cout << ch;
    ch = getchar();
  }
  return 0;
}


#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <string>
using namespace std;

int main() {
  char s[] = "Hello467";
  for (int i = 0; i < 1200; i++) {
    // s[i] = toupper(s[i]);
    if (islower(s[i]) != 0) {
      s[i] = toupper(s[i]);
    } else if (isupper(s[i]) != 0) {
      s[i] = tolower(s[i]);
    }
    cout << s[i];
  }

  return 0;
}

#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <stdio.h>
#include <string>
using namespace std;

int main() {

  char s;

  while (1) {
    scanf("%c", &s);
    if (islower(s) != 0) {
      s = toupper(s);
    } else if (isupper(s) != 0) {
      s = tolower(s);
    }
    printf("%c", s);
    if (s == '\\n')
      break;
  }

  return 0;
}

*** stack smashing detected ***: terminated


#include <iostream>
using namespace std;
int main() {
  // a-z 97-122
  // A-Z 65-90
  // a-A 32

  char ch;
  cin >> ch;
  while (ch != '\\n') {
    if (ch >= 97 && ch <= 122) {
      ch = (char)(ch - 32);
    } else if (ch >= 65 && ch <= 90) {
      ch = (char)(ch + 32);
    }
    cout << ch;
    cin >> ch;
  }

  return 0;
}

#include <iostream>
#include <stdio.h>
using namespace std;
int main() {
  // a-z 97-122
  // A-Z 65-90
  // a-A 32

  char ch;
  scanf("%c", &ch);
  while (ch != '\\n') {
    if (ch >= 97 && ch <= 122) {
      ch = (char)(ch - 32);
    } else if (ch >= 65 && ch <= 90) {
      ch = (char)(ch + 32);
    }
    printf("%c", ch);
    scanf("%c", &ch);
  }
  cout << endl;
  return 0;
}


#include <cctype>
#include <cstdio>
using namespace std;

int main() {
  char s;

  while (1) {
    scanf("%c", &s);
    if (isalpha(s)) {
      if (islower(s))
        printf("%c", toupper(s));
      else
        printf("%c", tolower(s));
    } else
      printf("%c", s);
    if (s == '\\0')
      break;
  }
  return 0;
}

#include <cctype>
#include <cstdio>
using namespace std;

int main() {
  char ch;
  while (1) {
    scanf("%c", &ch);
    if (isalpha(ch)) {
      if (islower(ch))
        printf("%c", toupper(ch));
      else
        printf("%c", tolower(ch));

    } else
      printf("%c", ch);
    if (ch == '\\n')
      break;
  }
  return 0;
}


#include <cctype>
#include <iostream>
using namespace std;
int main() {
  char ch;
  while (true) {
    cin >> ch;
    if (islower(ch))
      ch = toupper(ch);
    else
      ch = tolower(ch);
    cout << ch;
    if (ch == '\\n')
      break;
  }
  return 0;
}

#include <cctype>
#include <iostream>
#include <stdio.h>
using namespace std;
int main() {
  char ch;
  while (true) {
    scanf("%c", &ch);
    if (isupper(ch))
      ch = tolower(ch);
    else
      ch = toupper(ch);
    cout << ch;
    if (ch == '\\n')
      break;
  }
  return 0;
}


#include <cctype>
#include <iostream>
using namespace std;

int main() {
  char ch;

  for (int i = 0; 1; i++) {
    cin >> ch;
    if (islower(ch))
      ch = toupper(ch);
    else if (isupper(ch))
      ch = tolower(ch);
    cout << ch;
  }

  return 0;
}

#include <cctype>
#include <cstdio>

int main() {
  char ch;

  while (1) {
    scanf("%c", &ch);
    if (isalpha(ch)) {
      if (islower(ch))
        ch = toupper(ch);
      else
        ch = tolower(ch);
    }
    printf("%c", ch);
    if (ch == '\\n')
      break;
  }

  return 0;
}


#include <cctype>
#include <cstdio>
#include <iostream>
using namespace std;

int main() {
  char ch;

  while (1) {
    cin >> ch;
    if (isalpha(ch)) {
      if (islower(ch))
        printf("%c", toupper(ch));
      else
        printf("%c", tolower(ch));
    } else
      printf("%c", ch);

    if (ch == '\\n')
      break;
  }
  return 0;
}

#include <cctype>
#include <cstdio>
#include <iostream>
using namespace std;

int main() {
  char ch;

  while (1) {
    scanf("%c", &ch);
    if (isalpha(ch)) {
      if (islower(ch))
        printf("%c", toupper(ch));
      else
        printf("%c", tolower(ch));
    } else
      printf("%c", ch);

    if (ch == '\\n')
      break;
  }
  return 0;
}


#include <cctype>
#include <cstdio>
int main() {
  char ch;
  while (1) {
    scanf("%c", &ch);
    if (isalpha(ch)) {
      if (islower(ch))
        printf("%c", toupper(ch));
      else
        printf("%c", tolower(ch));
    } else
      printf("%c", ch);
    if (ch == '\\n')
      break;
  }
  return 0;
}


#include <iostream>
using namespace std;
int main() {
  char ch;
  while (1) {
    cin >> ch;
    if (ch == '\\n')
      break;
    if ('a' <= ch && ch <= 'z') {
      cout << ch - 32;
    } else if ('A' <= ch && ch <= 'Z') {
      cout << ch + 32;
    } else {
      cout << ch;
    }
  }
  cout << endl;
  return 0;
}

#include <iostream>
#include <stdio.h>
using namespace std;
int main() {
  char ch;
  while (ch != '\\n') {
    scanf("%c", &ch);
    if (isalpha(ch)) {
      if (islower(ch))
        printf("%c", toupper(ch));
      else if (isupper(ch))
        printf("%c", tolower(ch));
    } else
      printf("%c", ch);
  }
  return 0;
}


#include <ctype.h>
#include <iostream>
#include <stdio.h>
using namespace std;

int main() {
  char a;
  while (1) {
    scanf("%c", &a);
    if (a == EOF) {
      break;
    } else if (islower(a)) {
      printf("%c", toupper(a));
    } else if (isupper(a)) {
      printf("%c", tolower(a));
    }
  }

  return 0;
}

#include <ctype.h>
#include <stdio.h>

int main() {
  char ch;
  while (1) {
    scanf("%c", &ch);
    if (ch == '\\n') {
      printf("\\n");
      break;
    } else if (islower(ch)) {
      printf("%c", toupper(ch));
    } else if (isupper(ch)) {
      printf("%c", tolower(ch));
    } else {
      printf("%c", ch);
    }
  }

  return 0;
}


#include <cctype>
#include <iostream>
using namespace std;

int main() {
  char a;
  while (1) {
    cin >> a;
    if (a == '\\n')
      break;
    if (islower(a)) {
      cout << toupper(a);
    } else if (isupper(a)) {
      cout << tolower(a);
    } else {
      cout << a;
    }
  }
}

#include <cctype>
#include <iostream>
#include <stdio.h>
using namespace std;

int main() {
  char a;
  while (1) {

    scanf("%c", &a);
    if (a == '\\n')
      break;
    if (islower(a)) {
      printf("%c", toupper(a));
    } else if (isupper(a)) {
      printf("%c", tolower(a));
    } else {
      printf("%c", a);
    }
  }
  cout << endl;
}


#include <cctype>
#include <cstdio>
#include <iostream>

using namespace std;

int main() {

  char c;

  while (1) {

    cin >> c;
    if (c == '\\n')
      break;
    else if (islower(c))
      c = toupper(c);
    else if (isupper(c))
      c = tolower(c);

    cout << c;
  }
  cout << endl;

  return 0;
}

#include <cctype>
#include <cstdio>
#include <iostream>

using namespace std;

int main() {

  char ch;

  while ((ch = getchar()) != EOF) {
    if (islower(ch))
      ch = toupper(ch);
    else
      ch = tolower(ch);
    cout << ch;
  }

  return 0;
}


#include <cctype>
#include <iostream>
using namespace std;

int main() {

  char data;
  for (;;) {

    cin >> data;
    if (data == '\\n')
      break;

    if (islower(data)) {
      data = toupper(data);
    } else {
      data = tolower(data);
    }
    cout << data;

    if (data == ',')
      cout << " ";
  }
  cout << endl;

  return 0;
}

#include <ctype.h>
#include <iostream>
#include <string>

using namespace std;

int main() {

  string data;

  getline(cin, data);

  for (int i = 0; data[i]; i++) {

    if (islower(data[i])) {
      cout << (char)toupper(data[i]);
    } else if (isupper(data[i])) {
      cout << (char)tolower(data[i]);
    } else {
      cout << data[i];
    }
  }
  cout << endl;

  return 0;
}


#include <iostream>
#include <string>
using namespace std;

int main() {
  char letter;
  cin >> letter;
  while (letter != '.') {
    if (islower(letter)) {
      letter = toupper(letter);
    } else {
      letter = tolower(letter);
    }
    cout << letter;
  }

  return 0;
}

#include <iostream>

using namespace std;

int main() {
  char letter;
  while (cin >> noskipws >> letter) {
    if (islower(letter)) {
      letter = toupper(letter);
    } else {
      letter = tolower(letter);
    }
    cout << letter;
  }

  return 0;
}


#include <ctype.h>
#include <stdio.h>
int main() {
  char a[1200];
  int i;
  while (1) {
    scanf("%c", &a[i]);
    if (isupper(a[i])) {
      printf("%c", tolower(a[i]));
    } else if (islower(a[i])) {
      printf("%c", toupper(a[i]));
    } else {
      printf("%c", a[i]);
    }
  }
  return 0;
}

#include <ctype.h>
#include <stdio.h>
int main() {
  char a[1200];
  int i;
  while (1) {
    scanf("%c", &a[i]);
    if (a[i] == '\\n') {
      printf("\\n");
      break;
    }
    if (isupper(a[i])) {
      printf("%c", tolower(a[i]));
    } else if (islower(a[i])) {
      printf("%c", toupper(a[i]));
    } else {
      printf("%c", a[i]);
    }
  }
  return 0;
}


#include <cctype>
#include <cstdio>
#include <iostream>
using namespace std;

int main() {
  while (true) {
    char ch;
    cin >> ch;
    if (ch == '\\n') {
      break;
    }
    if (isupper(ch)) {
      ch = tolower(ch);
    } else if (islower(ch)) {
      ch = toupper(ch);
    }
    cout << ch << flush;
  }
  printf("\\n");
  return 0;
}

#include <cstdio>
#include <iostream>
using namespace std;

int main() {
  char ch;
  while (true) {
    scanf("%c", &ch);
    if (islower(ch)) {
      ch = toupper(ch);
    } else if (isupper(ch)) {
      ch = tolower(ch);
    }
    cout << ch << flush;
    if (ch == '\\n') {
      break;
    }
  }
  return 0;
}


#include <cctype>
#include <iostream>
#include <string>

using namespace std;

string toupper(string s) {
  string t = s;
  for (int i = 0; i < s.size(); i++) {
    t[i] = toupper(s[i]);
  }
  return t;
}

int main() {
  string target, source;

  cin >> target;
  target = toupper(target);

  int cnt = 0;

  while (1) {
    cin >> source;
    if (source == "END_OF_TEXT")
      break;
    source = toupper(source);
    if (target == source)
      cnt++;
  }
  cout << cnt << endl;

  return 0;
}

#include <cctype>
#include <cstdio>
using namespace std;

int main() {
  char ch;

  while (1) {
    scanf("%c", &ch);
    if (isalpha(ch)) {
      if (islower(ch))
        printf("%c", toupper(ch));
      else
        printf("%c", tolower(ch));
    } else
      printf("%c", ch);

    if (ch == '\\n')
      break;
  }

  return 0;
}


#include <cctype>
#include <iostream>
using namespace std;

int main() {
  while (1) {
    char ch;
    cin >> ch;
    if (ch == '/n') {
      break;
    } else if (islower(ch)) {
      cout << toupper(ch);
    } else {
      cout << tolower(ch);
    }
  }
  return 0;
}

#include <cctype>
#include <cstdio>
#include <iostream>
using namespace std;

int main() {
  int i = 0;
  char ch[1200];
  while (++i < 1200) {

    scanf("%c", &ch[i]);
    if (ch[i] == '\\n') {
      printf("%c", ch[i]);
      break;
    } else if (isalpha(ch[i])) {
      if (islower(ch[i])) {
        ch[i] = toupper(ch[i]);

      } else if (isupper(ch[i])) {
        ch[i] = tolower(ch[i]);
      }
    }
    printf("%c", ch[i]);
  }

  return 0;
}


#include <iostream>
#include <string>
using namespace std;

int main() {
  while (1) {
    string word; // string型直接代入できる
    char change[1200] = {0};

    getline(cin, word); // 空白が入ってても1行分読み込める

    for (int i = 0; i < word.length(); i++) {
      if (word[i] >= 'A' && word[i] <= 'Z')
        change[i] = word[i] + 32;
      if (word[i] >= 'a' && word[i] <= 'z')
        change[i] = word[i] - 32;
      else
        change[i] = word[i];
      cout << change[i];
    }
  }
  return 0;
}

#include <iostream>
#include <string>
using namespace std;

int main() {
  string word; // string型直接代入できる
  char change[1200] = {0};

  getline(cin, word); // 空白が入ってても1行分読み込める

  for (int i = 0; i < word.length(); i++) {
    if (word[i] >= 'A' && word[i] <= 'Z')
      change[i] = word[i] + 32;
    else if (word[i] >= 'a' && word[i] <= 'z')
      change[i] = word[i] - 32;
    else
      change[i] = word[i];
    cout << change[i];
  }
  cout << "\\n";
  return 0;
}


#include <cctype>
#include <iostream>
#include <stdio.h>
using namespace std;

int main() {
  char s;
  while (1) {
    cin >> s;
    if (isalpha(s)) {
      if (islower(s)) {
        s = toupper(s);
        cout << s;
      } else if (isupper(s)) {
        s = tolower(s);
        cout << s;
      }
    } else
      cout << s;
    if (s == '\\n')
      break;
  }
  return 0;
}

#include <cctype>
#include <stdio.h>
using namespace std;

int main() {
  char s;
  while (1) {
    scanf("%c", &s);
    if (isalpha(s)) {
      if (islower(s)) {
        printf("%c", toupper(s));
      } else
        printf("%c", tolower(s));
    } else
      printf("%c", s);
    if (s == '\\n')
      break;
  }
  return 0;
}


#include <cctype>
#include <iostream>
using namespace std;

int main() {
  while (1) {
    char c;
    cin >> c;
    if (c == '\\n') {
      cout << c;
      break;
    }
    if (islower(c))
      cout << toupper(c);
    else if (isupper(c))
      cout << tolower(c);
    else
      cout << c;
  }
  return 0;
}

#include <cctype>
#include <iostream>
using namespace std;

int main() {
  string s;
  getline(cin, s);
  int l = s.length();
  for (int i = 0; i < l; i++) {
    if (islower(s[i]))
      cout << (char)toupper(s[i]);
    else if (isupper(s[i]))
      cout << (char)tolower(s[i]);
    else
      cout << s[i];
  }
  cout << endl;
  return 0;
}


#include <cctype>
#include <iostream>
#include <stdio.h>
using namespace std;

int main() {

  char ch;

  while (1) {
    scanf("%c", &ch);
    if (isalpha(ch)) {

      if (isupper(ch)) {

        printf("%c", tolower(ch));
      }

      if (islower(ch)) {

        printf("%c", toupper(ch));
      }

      if (ch == '\\n')
        break;
    }

    else
      cout << ch;
  }
}

#include <cctype>
#include <iostream>
#include <stdio.h>
using namespace std;

int main() {

  char ch;

  while (1) {
    scanf("%c", &ch);
    if (isalpha(ch)) {

      if (isupper(ch)) {

        printf("%c", tolower(ch));
      }

      else if (islower(ch)) {

        printf("%c", toupper(ch));
      }
    } else
      cout << ch;

    if (ch == '\\n')
      break;
  }
}


//
// Created by ?????°?????? on 2016/02/08.
//

#include <cctype>
#include <iostream>
using namespace std;
int main() {
  char ch;
  while (1) {
    cin >> ch;
    if (isalpha(ch)) {
      if (islower(ch)) {
        cout << toupper(ch);
      } else {
        cout << tolower(ch);
      }
    } else
      cout << ch;
    if (ch == '\\n')
      break;
  }
  return 0;
}

#include <iostream>
#include <string>
using namespace std;

int main() {
  string a;
  getline(cin, a);
  for (int i = 0; i < 1200; i++) {
    if (a[i] == '\\0')
      break;
    if (a[i] >= 'a' && a[i] <= 'z') {
      a[i] -= 0x20;
    } else if (a[i] >= 'A' && a[i] <= 'Z') {
      a[i] += 0x20;
    }
    if (a[i] == ' ') {
      cout << " ";
    } else {
      cout << a[i];
    }
  }
  cout << endl;
  return 0;
}