alexjercan/bugnet huggingface dataset:
Problem p02413 (C++) — buggy submission, verdict: Runtime Error

#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;
}


Error: 0

Fixed submission:

#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;
}
Problem p02413 (C++) — buggy submission, verdict: Runtime Error

#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;
}

Error: 0

Fixed submission:

#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;
}
Problem p02413 (C++) — buggy submission, verdict: Runtime Error

#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;
}

Error: 0

Fixed submission:

#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;
}
Problem p02413 (C++) — buggy submission, verdict: 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++) {
      if (j < c) {
        printf("%d ", matrix[i][j]);
      } else {
        printf("%d", matrix[i][j]);
      }
    }
    printf("\\n");
  }
}


Error: -11

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++) {
      printf("%d%s", matrix[i][j]);
    }
    printf("\\n");
  }
}
Problem p02413 (C++) — buggy submission, verdict: Runtime Error

#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;
}

Error: 0

Fixed submission:

#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;
}
Problem p02413 (C++) — buggy submission, verdict: Runtime Error

#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;
}

Error: 0

Fixed submission:

#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;
}
Problem p02413 (C++) — buggy submission, verdict: 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[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;
    }
  }
}

Error: 0

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[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;
    }
  }
}
Problem p02413 (C++) — buggy submission, verdict: Runtime Error

#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;
}

Error: 0

Fixed submission:

#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;
}
Problem p02413 (C++) — buggy submission, verdict: Runtime Error

#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;
}


Error: 0

Fixed submission:

#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;
}
Problem p02413 (C++) — buggy submission, verdict: Time Limit Exceeded

#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;
}

Error: TLE

Fixed submission:

#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;
}
Problem p02413 (C++) — buggy submission, verdict: Runtime Error

#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;
}

Error: 0

Fixed submission:

#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;
}
Problem p02413 (C++) — buggy submission, verdict: Time Limit Exceeded

#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;
}


Error: TLE

Fixed submission:

#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;
}
Problem p02413 (C++) — buggy submission, verdict: Runtime Error

#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;
}

Error: 0

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int r, c, a[101][101];
  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 + 1] = 0;
    for (int j = 0; j < c; ++j) {
      cout << a[i][j] << " ";
      a[i][c + 1] += a[i][j];
    }
    cout << a[i][c + 1] << endl;
  }
  for (int j = 0; j < c; ++j) {
    a[r + 1][j] = 0;
    for (int i = 0; i < r; ++i) {
      a[r + 1][j] += a[i][j];
    }
    cout << a[r + 1][j] << " ";
  }
  a[r + 1][c + 1] = 0;
  for (int j = 0; j < c; ++j) {
    a[r + 1][c + 1] += a[r + 1][j];
  }
  cout << a[r + 1][c + 1] << endl;
  return 0;
}
Problem p02413 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int main() {
  int T, Y, a[1000][1000] = {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;
  }
}

Error: 0

Fixed submission:

#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;
  }
}
Problem p02413 (C++) — buggy submission, verdict: Runtime Error

#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;
}


Error: WA

Fixed submission:

#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;
}
Problem p02413 (C++) — buggy submission, verdict: Runtime Error

#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;
}


Error: -11

Fixed submission:

#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;
}
Problem p02413 (C++) — buggy submission, verdict: Runtime Error

#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;
}

Error: 0

Fixed submission:

#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;
}
Problem p02413 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int x, y;
  cin >> x >> y;

  int a[1000][1000] = {};
  for (int i = 1; i <= x; i++) {
    for (int g = 1; g <= y; g++) {
      cin >> a[i][g];
    }
  }

  for (int i = 1; i <= x; i++) {
    for (int g = 1; g <= y; g++) {
      a[i][y + 1] += a[i][g];
    }
  }
  for (int i = 1; i <= x; i++) {
    for (int g = 1; g <= y; g++) {
      a[x + 1][g] += a[i][g];
    }
  }
  for (int g = 1; g <= y; g++) {
    a[x + 1][y + 1] += a[x + 1][g];
  }

  for (int i = 1; i <= x + 1; i++) {
    for (int g = 1; g <= y + 1; g++) {
      cout << a[i][g];
      if (g <= y) {
        cout << " ";
      }
    }
    cout << endl;
  }

  return 0;
}


Error: TLE

Fixed submission:

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

int main() {
  int x, y;
  cin >> x >> y;

  int a[100][100] = {};
  for (int i = 1; i <= x; i++) {
    for (int g = 1; g <= y; y++) {
      cin >> a[i][g];
    }
  }

  for (int i = 1; i <= x; i++) {
    for (int g = 1; g <= y; y++) {
      a[i][y + 1] += a[i][g];
    }
  }
  for (int i = 1; i <= x; i++) {
    for (int g = 1; g <= y; y++) {
      a[x + 1][g] += a[i][g];
    }
  }

  for (int i = 1; i <= x + 1; i++) {
    for (int g = 1; g <= y + 1; y++) {
      cout << a[i][g];
      if (g <= y) {
        cout << " ";
      }
    }
    cout << endl;
  }

  return 0;
}