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

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

Error: 0

Fixed submission:

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

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

Error: 0

Fixed submission:

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

#include <iostream>
using namespace std;

int main(void) {
  int r, c, a[101][101], sum_r = 0, sum_c = 0, sum_all = 0;
  cin >> r >> c;
  for (int i = 0; i < r; i++) {
    for (int j = 0; j < c; j++) {
      cin >> a[i][j];
      cout << a[i][j] << " ";
      sum_r += a[i][j];
      sum_all += a[i][j];
    }
    cout << sum_r << endl;
    sum_r = 0;
  }
  for (int j = 0; j < c; j++) {
    for (int i = 0; i < r; i++) {
      sum_c += a[i][j];
    }
    cout << sum_c << " ";
    sum_c = 0;
  }
  cout << sum_all << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main(void) {
  int r, c, a[101][101], sum_r = 0, sum_c = 0, sum_all = 0;
  while (1) {
    cin >> r >> c;
    for (int i = 0; i < r; i++) {
      for (int j = 0; j < c; j++) {
        cin >> a[i][j];
        cout << a[i][j] << " ";
        sum_r += a[i][j];
        sum_all += a[i][j];
      }
      cout << sum_r << endl;
      sum_r = 0;
    }
    for (int j = 0; j < c; j++) {
      for (int i = 0; i < r; i++) {
        sum_c += a[i][j];
        cout << sum_c << " ";
      }
      sum_c = 0;
    }
    cout << sum_all << endl;
  }
  return 0;
}
Problem p02413 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using std::cin;
using std::cout;
using std::endl;

int *numArray;

void createArray(int row, int column) {
  int i;
  numArray = new int[row * column];
  for (i = 0; i < (row * column); i++)
    numArray[i] = 0;
}

void populateArray(int row, int column) {
  int i, j;
  for (i = 0; i < row - 1; i++)
    for (j = 0; j < column - 1; j++)
      cin >> numArray[i * column + j];
}

void sumArray(int row, int column) {
  int i, j, rsum = 0, csum = 0;
  for (i = 0; i < row - 1; i++) {
    for (j = 0; j < column - 1; j++)
      rsum += numArray[i * column + j];
    numArray[i * column + column - 1] = rsum;
    rsum = 0;
  }

  for (j = 0; j < column; j++) {
    for (i = 0; i < row - 1; i++)
      csum += numArray[i * column + j];
    numArray[(row - 1) * column + j] = csum;
    csum = 0;
  }
}

void drawArray(int row, int column) {
  int i, j;
  for (i = 0; i < row; i++) {
    for (j = 0; j < column - 1; j++)
      cout << numArray[i * column + j] << " ";
    cout << numArray[i * column + column - 1] << endl;
  }
}

int main() {
  int row, column;
  cin >> row >> column;
  createArray(row + 1, column + 1);
  populateArray(row + 1, column + 1);
  sumArray(row + 1, column + 1);
  drawArray(row + 1, column + 1);
  delete[] numArray;
  return 0;
}

Error: 0

Fixed submission:

#include <cstdlib>
#include <iostream>
using std::cin;
using std::cout;
using std::endl;

int **numArray;

void createArray(int row, int column) {
  int i;
  numArray = (int **)calloc(column, sizeof(int *));
  for (i = 0; i < column; i++)
    numArray[i] = (int *)calloc(row, sizeof(int));
}

void populateArray(int row, int column) {
  int i, j;
  for (i = 0; i < row - 1; i++)
    for (j = 0; j < column - 1; j++)
      cin >> numArray[i][j];
}

void sumArray(int row, int column) {
  int i, j, k, rsum = 0, csum = 0, fsum = 0;
  for (i = 0; i < row; i++) {
    for (j = 0; j < column; j++) {
      if (j < column - 1)
        csum += numArray[i][j];
      else
        numArray[i][j] = csum;

      if (j < row - 1)
        rsum += numArray[j][i];
      else
        numArray[j][i] = rsum;
    }
    csum = 0;
    rsum = 0;
  }

  numArray[row - 1][column - 1] = 0;
  for (k = 0; k < row; k++)
    fsum += numArray[k][column - 1];
  numArray[row - 1][column - 1] = fsum;
}

void drawArray(int row, int column) {
  int i, j;
  for (i = 0; i < row; i++) {
    for (j = 0; j < column - 1; j++)
      cout << numArray[i][j] << " ";
    cout << numArray[i][column - 1] << endl;
  }
}

int main() {
  int i, r, c;
  cin >> r >> c;
  createArray(r + 1, c + 1);
  populateArray(r + 1, c + 1);
  sumArray(r + 1, c + 1);
  drawArray(r + 1, c + 1);

  for (i = 0; i < c + 1; i++)
    free(numArray[i]);
  free(numArray);
  return 0;
}
Problem p02413 (C++) — buggy submission, verdict: 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; 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;
}


Error: TLE

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

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


Error: 0

Fixed submission:

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

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


Error: 0

Fixed submission:

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

#include <iostream>
using namespace std;
int main() {
  int a[200][200], r, c, sum;
  sum = 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] << " ";
      sum += a[i][j];
    }
    a[i][c] = sum;
    cout << sum << endl;
    sum = 0;
  }
  for (int j = 0; j < c; j++) {
    for (int i = 0; i < r; i++) {
      sum += a[i][j];
      if (i == r - 1) {
        a[i + 1][j] = sum;
        cout << sum << " ";
        sum = 0;
      }
    }
  }
  for (int i = 0; i < r; i++) {
    for (int j = 0; j < c; j++) {
      sum += a[i][j];
    }
  }

  cout << sum << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int a[200][200], r, c, sum;
  sum = 0;
  cin >> r >> c;
  for (int i = 0; i < r; i++) {
    for (int j = 0; j < c; c++) {
      cin >> a[i][j];
    }
  }
  for (int i = 0; i < r; i++) {
    for (int j = 0; j < c; c++) {
      cout << a[i][j] << " ";
      sum += a[i][j];
      if (j = c - 1) {
        a[i][j + 1] = sum;
        cout << sum << endl;
        sum = 0;
      }
    }
  } // r行まで入力終了
  for (int j = 0; j < c; j++) {
    for (int i = 0; i < r; i++) {
      sum += a[i][j];
      if (i == r - 1) {
        a[i + 1][j] = sum;
        cout << sum << " ";
        sum = 0;
      }
    }
  } // 最後以外全部終わり
  for (int i = 0; i < r + 1; i++) {
    for (int j = 0; j < c + 1; j++) {
      sum += a[i][j];
    }
  }
  cout << sum << endl;
  return 0;
}
Problem p02413 (C++) — buggy submission, verdict: Runtime Error

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

Error: 0

Fixed submission:

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

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

Error: 0

Fixed submission:

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

#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 - 1; i++) {
    int y = 0;
    for (int j = 0; j < c - 1; j++) {
      y = y + a[i][j];
    }
    a[i][c - 1] = y;
  }

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

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


Error: WA

Fixed submission:

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


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

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

Error: 0

Fixed submission:

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

/*
 * 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;
}


Error: 0

Fixed submission:

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

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

Error: 0

Fixed submission:

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