prithivMLmods/Coder-Stat huggingface dataset:
Problem p02413 (C++)

Buggy submission (status: Runtime Error):
#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;
}

Fixed submission:
#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;
}
Problem p02413 (C++)

Buggy submission (status: Runtime Error):
#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;
}

Fixed submission:
#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;
}
Problem p02413 (C++)

Buggy submission (status: Runtime Error):
#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;
}


Fixed submission:
#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;
}
Problem p02413 (C++)

Buggy submission (status: Runtime Error):
#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;
}

Fixed submission:
#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;
}
Problem p02413 (C++)

Buggy submission (status: Runtime Error):
#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;
}


Fixed submission:
#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;
}
Problem p02413 (C++)

Buggy submission (status: Runtime Error):
#include <cstdio>

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

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


Fixed submission:
#include <cstdio>

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

    for (j = 0; j < c; j++) {
      n[i][c] += n[i][j];
    }
  }
  for (j = 0; j < c; j++) {
    for (i = 0; i < r; i++) {
      n[r][j] += n[i][j];
    }
  }
  for (i = 0; i <= r; i++) {
    for (j = 0; j <= c; j++) {
      if (j == c) {
        printf("%d", n[i][j]);
      } else {
        printf("%d ", n[i][j]);
      }
    }
    printf("\n");
  }
  return 0;
}
Problem p02413 (C++)

Buggy submission (status: Runtime Error):
#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;
}

Fixed submission:
#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;
}
Problem p02413 (C++)

Buggy submission (status: Runtime Error):
#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;
}

Fixed submission:
#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;
}
Problem p02413 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;

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

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

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

  return 0;
}


Fixed submission:
#include <iostream>
using namespace std;

int main() {
  int r, c, a[1000][1000];

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

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

  return 0;
}
Problem p02413 (C++)

Buggy submission (status: Runtime Error):
#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;
}

Fixed submission:
#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;
}
Problem p02413 (C++)

Buggy submission (status: Runtime Error):
#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;
    }
  }
}

Fixed submission:
#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;
    }
  }
}
Problem p02413 (C++)

Buggy submission (status: Runtime Error):
#include <cstdio>
#include <iostream>
#include <string>

using namespace std;

int main(void) {

  int r, c;
  int hyo[100][100];
  int ans, final_ans;

  cin >> r >> c;

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

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

  final_ans = 0;

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

  hyo[r][c] = final_ans;

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

  return 0;
}

Fixed submission:
#include <cstdio>
#include <iostream>
#include <string>

using namespace std;

int main(void) {

  int r, c;
  int hyo[1000][1000];
  int ans, final_ans;

  cin >> r >> c;

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

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

  final_ans = 0;

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

  hyo[r][c] = final_ans;

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

  return 0;
}
Problem p02413 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;
int main() {
  int r, c;
  int a[100][100] = {0};
  int x = 0;
  int y = 0;

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


Fixed submission:
#include <iostream>
using namespace std;
int main() {
  int r, c;
  int a[101][101] = {0};
  int x = 0;
  int y = 0;

  cin >> r >> c;
  for (int i = 0; i < r; i++) {
    for (int j = 0; j < c; j++) {
      cin >> a[i][j];
      x += a[i][j];
    }
    a[i][c] = x;
    x = 0;
  }
  for (int j = 0; j <= c; j++) {
    for (int i = 0; i < r; i++) {
      y += a[i][j];
    }
    a[r][j] = y;
    y = 0;
  }
  for (int i = 0; i <= r; i++) {
    for (int j = 0; j <= c; j++) {
      cout << a[i][j];
      if (j < c)
        cout << " ";
    }
    cout << endl;
  }
}
Problem p02413 (C++)

Buggy submission (status: Runtime Error):
#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");
  }
}


Fixed submission:
#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");
  }
}
Problem p02413 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;

int main() {
  int r, c, e, sum, sum2, sheet[100][100];
  cin >> r >> c;

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

    sheet[i][c] = sum;
  }

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

    sheet[r][i] = sum;
    sum2 += sum;
  }

  sheet[r][c] = sum2;

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

  return 0;
}


Fixed submission:
#include <iostream>
using namespace std;

int main() {
  int r, c, e, sum, sum2, sheet[101][101];
  cin >> r >> c;

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

    sheet[i][c] = sum;
  }

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

    sheet[r][i] = sum;
    sum2 += sum;
  }

  sheet[r][c] = sum2;

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

  return 0;
}
Problem p02413 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;

int main() {

  int r, c, sum;
  int a[100][100] = {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++) {
    for (int j = 0; j < c; j++) {
      cout << a[i][j] << " ";
      a[i][c] += a[i][j];
      a[r][j] += a[i][j];
    }
    cout << a[i][c] << endl;
  }

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

Fixed submission:
#include <iostream>
using namespace std;

int main() {

  int r, c, sum;
  int a[101][101] = {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++) {
    for (int j = 0; j < c; j++) {
      cout << a[i][j] << " ";
      a[i][c] += a[i][j];
      a[r][j] += a[i][j];
    }
    cout << a[i][c] << endl;
  }

  for (int j = 0; j < c; j++) {
    cout << a[r][j] << " ";
    sum += a[r][j];
  }
  cout << sum << endl;
  return 0;
}
Problem p02413 (C++)

Buggy submission (status: Time Limit Exceeded):
#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;
}

Fixed submission:
#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;
}
Problem p02413 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;

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

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

  for (int m = 0; m <= r; m++) {
    for (int k = 0; k <= c; k++) {
      cout << arr[m][k];

      if (k == c) {
        cout << endl;
      } else {
        cout << ' ';
      }
    }
  }

  return 0;
}

Fixed submission:
#include <iostream>
using namespace std;

int main() {
  int r, c, arr[101][101] = {};
  cin >> r >> c;

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

  for (int m = 0; m <= r; m++) {
    for (int k = 0; k <= c; k++) {
      cout << arr[m][k];

      if (k == c) {
        cout << endl;
      } else {
        cout << ' ';
      }
    }
  }

  return 0;
}
Problem p02413 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;

int main(void) {
  int r, c, i, j, k;
  int a[101][101] = {};

  cin >> r >> c;

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

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

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

  return 0;
}

Fixed submission:
#include <iostream>
using namespace std;

int main(void) {
  int r, c, i, j, k;
  int a[102][102] = {};

  cin >> r >> c;

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

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

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

  return 0;
}
Problem p02413 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;
int main() {
  int r, c, a[100][100] = {}, i, j, N = 0, S = 0, M = 0;
  cin >> r >> c;
  for (i = 1; i <= r; i++) {
    for (j = 1; j <= c; j++) {
      cin >> a[i][j];
    }
  }
  for (i = 1; i <= r; i++) {
    N = 0;
    for (j = 1; j <= c; j++) {
      cout << a[i][j] << " ";
      N = N + a[i][j];
    }
    cout << N << endl;
  }
  for (j = 1; j <= c + 1; j++) {
    S = 0;
    for (i = 1; i <= r; i++) {
      S = S + a[i][j];
    }
    if (j == c + 1) {
      cout << M << endl;
      break;
    }
    cout << S << " ";
    M = M + S;
  }

  return 0;
}

Fixed submission:
#include <iostream>
using namespace std;
int main() {
  int r, c, a[150][150] = {}, i, j, N = 0, S = 0, M = 0;
  cin >> r >> c;
  for (i = 1; i <= r; i++) {
    for (j = 1; j <= c; j++) {
      cin >> a[i][j];
    }
  }
  for (i = 1; i <= r; i++) {
    N = 0;
    for (j = 1; j <= c; j++) {
      cout << a[i][j] << " ";
      N = N + a[i][j];
    }
    cout << N << endl;
  }
  for (j = 1; j <= c + 1; j++) {
    S = 0;
    for (i = 1; i <= r; i++) {
      S = S + a[i][j];
    }
    if (j == c + 1) {
      cout << M << endl;
      break;
    }
    cout << S << " ";
    M = M + S;
  }

  return 0;
}
Problem p02413 (Python)

Buggy submission (status: Runtime Error):
# -*- coding: utf-8 -*-

r, c = list(map(int, input().split()))
a = []
line_sum = 0

for i in range(r):
    a.append(list(map(int, input().split())))

for i in range(r):
    for j in range(c + 1):
        if j == c:
            print("{0}".format(sum(a[i])))
            line_sum += sum(a[i])
        else:
            print("{0} ".format(a[i][j]), end="")

for i in range(c + 1):
    column_sum = 0
    for j in range(r):
        column_sum += a[j][i]

    print("{0} ".format(column_sum), end="")

print(line_sum)


Fixed submission:
# -*- coding: utf-8 -*-

r, c = list(map(int, input().split()))
a = []
line_sum = 0

for i in range(r):
    a.append(list(map(int, input().split())))

for i in range(r):
    for j in range(c + 1):
        if j == c:
            print("{0}".format(sum(a[i])))
            line_sum += sum(a[i])
        else:
            print("{0} ".format(a[i][j]), end="")

for i in range(c):
    column_sum = 0
    for j in range(r):
        column_sum += a[j][i]

    print("{0} ".format(column_sum), end="")

print(line_sum)
Problem p02413 (C++)

Buggy submission (status: Runtime Error):
#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;
}

Fixed submission:
#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;
}
Problem p02413 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;

int main() {
  int r, c, i, j;

  int A[100][100];
  cin >> r >> c;

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

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

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

  return 0;
}


Fixed submission:
#include <iostream>
using namespace std;

int main() {
  int r, c, i, j;

  int A[101][101];
  cin >> r >> c;

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

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

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

  return 0;
}
Problem p02413 (C++)

Buggy submission (status: Runtime Error):
#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;
}


Fixed submission:
#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;
}
Problem p02413 (C++)

Buggy submission (status: Runtime Error):
#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;
}

Fixed submission:
#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;
}
Problem p02413 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;
int main() {
  int hyo[100][100] = {0};
  int r, c;
  cin >> r;
  cin >> c;
  for (int i = 0; i < r; i++) {
    for (int i2 = 0; i2 < c; i2++) {
      cin >> hyo[i][i2];
    }
  }
  for (int i = 0; i < r; i++) {
    for (int i2 = 0; i2 < c; i2++) {
      hyo[i][c] += hyo[i][i2];
    }
  }
  for (int i = 0; i < c; i++) {
    for (int i2 = 0; i2 < r; i2++) {
      hyo[r][i] += hyo[i2][i];
    }
  }
  for (int i = 0; i < r; i++) {
    hyo[r][c] += hyo[i][c];
  }
  for (int i = 0; i < r + 1; i++) {
    for (int i2 = 0; i2 < c; i2++) {
      cout << hyo[i][i2] << " ";
    }
    cout << hyo[i][c] << endl;
  }
  return 0;
}

Fixed submission:
#include <iostream>
using namespace std;
int main() {
  int hyo[1000][1000] = {0};
  int r, c;
  cin >> r;
  cin >> c;
  for (int i = 0; i < r; i++) {
    for (int i2 = 0; i2 < c; i2++) {
      cin >> hyo[i][i2];
    }
  }
  for (int i = 0; i < r; i++) {
    for (int i2 = 0; i2 < c; i2++) {
      hyo[i][c] += hyo[i][i2];
    }
  }
  for (int i = 0; i < c; i++) {
    for (int i2 = 0; i2 < r; i2++) {
      hyo[r][i] += hyo[i2][i];
    }
  }
  for (int i = 0; i < r; i++) {
    hyo[r][c] += hyo[i][c];
  }
  for (int i = 0; i < r + 1; i++) {
    for (int i2 = 0; i2 < c; i2++) {
      cout << hyo[i][i2] << " ";
    }
    cout << hyo[i][c] << endl;
  }
  return 0;
}
Problem p02413 (C++)

Buggy submission (status: Runtime Error):
#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";
    }
  }
}

Fixed submission:
#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";
    }
  }
}
Problem p02413 (C++)

Buggy submission (status: Runtime Error):
#include <stdio.h>
int main(void) {
  int r, c, i, j;
  scanf("%d%d", &r, &c);
  int a[100][100] = {};
  for (i = 0; i < r; i++) {
    for (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][j];
    }
  }
  for (i = 0; i <= r; i++) {
    printf("%d", a[i][0]);
    for (j = 1; j <= c; j++) {

      printf(" %d", a[i][j]);
    }
    printf("\n");
  }

  return 0;
}

Fixed submission:
#include <stdio.h>
int main(void) {
  int r, c, i, j;
  scanf("%d%d", &r, &c);
  int a[101][101] = {};
  for (i = 0; i < r; i++) {
    for (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][j];
    }
  }
  for (i = 0; i <= r; i++) {
    printf("%d", a[i][0]);
    for (j = 1; j <= c; j++) {

      printf(" %d", a[i][j]);
    }
    printf("\n");
  }

  return 0;
}
Problem p02413 (C++)

Buggy submission (status: Runtime Error):
#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;
}

Fixed submission:
#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;
}
Problem p02413 (C++)

Buggy submission (status: Runtime Error):
#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;
}

Fixed submission:
#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;
}
Problem p02413 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
using namespace std;
int main() {
  int r, c;
  cin >> r >> c;
  int num[101][101] = {};
  for (int i = 0; i < r; i++)
    for (int j = 0; j < c; j++)
      cin >> num[i][j];

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

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


Fixed submission:
#include <iostream>
using namespace std;
int main() {
  int r, c;
  cin >> r >> c;
  int num[101][101] = {};
  for (int i = 0; i < r; i++)
    for (int j = 0; j < c; j++)
      cin >> num[i][j];

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

  for (int i = 0; i < r; i++) {
    int sum = 0;
    for (int j = 0; j < c; j++)
      sum += num[i][j];
    num[i][c] = sum;
  }
  for (int j = 0; j < c; j++) {
    int sum = 0;
    for (int i = 0; i < r; i++)
      sum += num[i][j];
    num[r][j] = sum;
  }
  for (int i = 0; i <= r; i++) {
    for (int j = 0; j <= c; j++) {
      if (j)
        cout << " ";
      cout << num[i][j];
    }
    cout << endl;
  }
  return 0;
}
Problem p02413 (C++)

Buggy submission (status: Runtime Error):
#include <stdio.h>
int main() {
  int r, c;
  int i, j, a[100][100] = {0};
  scanf("%d %d", &r, &c);
  for (i = 1; i <= r; i++) {
    for (j = 1; j <= c; j++) {
      scanf("%d", &a[i][j]);
      a[i][c + 1] += a[i][j];
      a[r + 1][j] += a[i][j];
    }
  }
  for (j = 1; j <= c; j++) {
    a[r + 1][c + 1] += a[r + 1][j];
  }
  for (i = 1; i <= r + 1; i++) {
    for (j = 1; j <= c + 1; j++) {
      if (j == c + 1)
        printf("%d", a[i][j]);
      else
        printf("%d ", a[i][j]);
    }
    printf("\n");
  }
  return 0;
}

Fixed submission:
#include <stdio.h>
int main() {
  int r, c;
  int i, j, a[110][110] = {0};
  scanf("%d %d", &r, &c);
  for (i = 1; i <= r; i++) {
    for (j = 1; j <= c; j++) {
      scanf("%d", &a[i][j]);
      a[i][c + 1] += a[i][j];
      a[r + 1][j] += a[i][j];
    }
  }
  for (j = 1; j <= c; j++) {
    a[r + 1][c + 1] += a[r + 1][j];
  }
  for (i = 1; i <= r + 1; i++) {
    for (j = 1; j <= c + 1; j++) {
      if (j == c + 1)
        printf("%d", a[i][j]);
      else
        printf("%d ", a[i][j]);
    }
    printf("\n");
  }
  return 0;
}
Problem p02413 (C++)

Buggy submission (status: Runtime Error):
// ITP1_7_C
#include <iostream>
using namespace std;

int main() {
  int r, c, i, j, k = 0;

  cin >> r >> c;

  int irc[100][100];

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

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

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

  return 0;
}

Fixed submission:
// ITP1_7_C
#include <iostream>
using namespace std;

int main() {
  int r, c, i, j, k = 0;

  cin >> r >> c;

  int irc[101][101];

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

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

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

  return 0;
}
Problem p02413 (C++)

Buggy submission (status: Runtime Error):
#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] << " ";
    }
  }
}


Fixed submission:
#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] << " ";
    }
  }
}
Problem p02413 (C++)

Buggy submission (status: Runtime Error):
#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;
}

Fixed submission:
#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;
}
Problem p02413 (C++)

Buggy submission (status: Runtime Error):
#include <stdio.h>
int main() {
  int a[100][100] = {0};
  int r, c;
  scanf("%d %d", &r, &c);
  for (int i = 0; i < r; i++) {
    for (int j = 0; j < c; j++) {
      scanf("%d", &a[i][j]);
    }
  }
  for (int i = 0; i < r; i++) {
    for (int j = 0; j < c; j++) {
      a[i][c] = a[i][c] + a[i][j];
    }
  }
  for (int j = 0; j <= c; j++) {
    for (int i = 0; i < r; i++) {
      a[r][j] = 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)
        printf(" ");
    }
    printf("\n");
  }
  return 0;
}

Fixed submission:
#include <stdio.h>
int main() {
  int a[101][101] = {0};
  int r, c;
  scanf("%d %d", &r, &c);
  for (int i = 0; i < r; i++) {
    for (int j = 0; j < c; j++) {
      scanf("%d", &a[i][j]);
    }
  }
  for (int i = 0; i < r; i++) {
    for (int j = 0; j < c; j++) {
      a[i][c] = a[i][c] + a[i][j];
    }
  }
  for (int j = 0; j <= c; j++) {
    for (int i = 0; i < r; i++) {
      a[r][j] = 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)
        printf(" ");
    }
    printf("\n");
  }
  return 0;
}
Problem p02413 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;

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

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

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

Fixed submission:
#include <iostream>
using namespace std;

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

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

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