alexjercan/bugnet huggingface dataset:
Problem p02413 (C++) — buggy submission, verdict: Time Limit Exceeded

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


Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  while (1) {
    int a[100][100];
    int r, c;
    cin >> r >> c;
    for (int i = 0; i < 100; i++) {
      for (int j = 0; j < 100; j++) {
        a[i][j] = 0;
      }
    }
    int b;
    int Wsum = 0, Hsum = 0, Asum = 0;
    for (int i = 0; i < r; i++) {
      for (int j = 0; j < c; j++) {
        cin >> b;
        a[i][j] = b;
        cout << a[i][j] << " ";
        Wsum += a[i][j];
      }
      cout << Wsum << endl;
      Asum += Wsum;
      Wsum = 0;
    }
    for (int i = 0; i < r + 1; i++) {
      for (int j = 0; j < c + 1; j++) {
        Hsum += a[i][j];
      }
      cout << Hsum << " ";
      Hsum = 0;
    }
    cout << Asum;
  }
}
Problem p02413 (C++) — buggy submission, verdict: Runtime Error

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


Error: 0

Fixed submission:

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

#include <stdio.h>
#define M 100 + 1
int main() {
  int r, c;
  int i, j;
  int yoko = 0;
  int tate = 0;
  int a[M][M];

  scanf("%d %d", &r, &c);

  for (i = 0; i < M; i++) {
    for (j = 0; j < M; j++) {
      a[i][j] = 0;
    }
  }

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

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

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

Error: TLE

Fixed submission:

#include <stdio.h>

int main() {
  int r, c;
  int i, j;
  int yoko = 0;
  int tate = 0;
  int a[101][101];

  scanf("%d %d", &r, &c);

  for (i = 0; i < 101; i++) {
    for (j = 0; j < 101; j++) {
      a[i][j] = 0;
    }
  }

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

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

  for (i = 0; i < r + 1; i++) {
    for (j = 0; j < c + 1; j++) {
      if (j = 0) {
        printf("%d", a[i][j]);
      } else {
        printf(" %d", a[i][j]);
      }
    }
    printf("\\n");
  }
}
Problem p02413 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>
int main() {
  int p[101][101];
  int n, m, x, w;
  for (int i = 0; i < 101; i++) {
    for (int j = 0; j < 101; j++) {
      p[i][j] = 0;
    }
  }
  w = 0;
  scanf("%d", &n);
  scanf("%d", &m);

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      scanf("%d", &x);
      p[i][j] = x;
      p[i][m] += x;
    }
  }

  for (int ii = 0; ii < n; ii++) {
    for (int jj = 0; jj <= m; jj++) {

      if (jj < m) {
        printf("%d ", p[ii][jj]);
      }

      else if (jj == m) {
        printf("%d\\n", p[ii][m]);
      }
    }
  }
  for (int j = 0; j < m; j++) {
    for (int i = 0; i < n; i++) {
      p[n][j] += p[i][j];
    }
    printf("%d ", p[n][j]);
    p[n][m] += p[n][j];
  }
  printf("%d\\n", p[n][m]);

  return 0;
}

Error: 0

Fixed submission:

#include <stdio.h>
int main() {
  int p[100][100];
  int n, m, x, w;
  for (int i = 0; i < 100; i++) {
    for (int j = 0; j < 100; j++) {
      p[i][j] = 0;
    }
  }
  w = 0;
  scanf("%d", &n);
  scanf("%d", &m);

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      scanf("%d", &x);
      p[i][j] = x;
      p[i][m] += x;
    }
  }

  for (int ii = 0; ii < n; ii++) {
    for (int jj = 0; jj <= m; jj++) {

      if (jj < m) {
        printf("%d ", p[ii][jj]);
      }

      else if (jj == m) {
        printf("%d\\n", p[ii][m]);
      }
    }
  }
  for (int j = 0; j < m; j++) {
    for (int i = 0; i < n; i++) {
      p[n][j] += p[i][j];
    }
    printf("%d ", p[n][j]);
    p[n][m] += p[n][j];
  }
  printf("%d\\n", p[n][m]);

  return 0;
}
Problem p02413 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
int main() {
  int r, c, i, ii, iii, g[200][200] = {};
  cin >> r >> c;
  for (i = 1; i <= r; i++) {
    for (ii = 1; ii <= c; ii++) {
      cin >> g[i][ii];
    }
  }
  for (i = 1; i <= r; i++) {
    for (ii = 1; ii <= c; ii++) {
      g[i][c + 1] += g[i][ii];
    }
  }
  for (i = 1; i <= r; i++) {
    for (ii = 1; ii <= c; ii++) {
      g[r + 1][ii] += g[i][ii];
    }
  }
  for (ii = 1; ii <= c; ii++) {
    g[r + 1][c + 1] += g[r + 1][ii];
  }
  for (i = 1; i <= r + 1; i++) {
    for (ii = 1; ii <= c + 1; ii++) {
      cout << g[i][ii];
      if (c + 1 == ii) {
        cout << endl;
      } else {
        cout << " ";
      }
    }
  }

  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int r, c, i, ii, iii, g[101][101] = {};
  cin >> r >> c;
  for (i = 1; i <= r; i++) {
    for (ii = 1; ii <= c; ii++) {
      cin >> g[i][ii];
    }
  }
  for (i = 1; i <= r; i++) {
    for (ii = 1; ii <= c; ii++) {
      g[i][c + 1] += g[i][ii];
    }
  }
  for (i = 1; i <= r; i++) {
    for (ii = 1; ii <= c; ii++) {
      g[r + 1][ii] += g[i][ii];
    }
  }
  for (ii = 1; ii <= c; ii++) {
    g[r + 1][c + 1] += g[r + 1][ii];
  }
  for (i = 1; i <= r + 1; i++) {
    for (ii = 1; ii <= c + 1; ii++) {
      cout << g[i][ii];
      if (c + 1 == ii) {
        cout << endl;
      } else {
        cout << " ";
      }
    }
  }

  return 0;
}
Problem p02413 (C++) — buggy submission, verdict: Runtime Error

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

Error: 0

Fixed submission:

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

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

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


Error: 0

Fixed submission:

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

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

Error: 0

Fixed submission:

#include <stdio.h>
int main() {
  int box[100][100], r, c, cour, couc, sumc, sumr = 0, suma = 0;
  scanf("%d %d", &r, &c);
  for (cour = 1; cour < r + 1; cour++) {
    for (couc = 1; couc < c + 1; couc++) {
      scanf("%d", &box[cour][couc]);
    }
  }
  for (cour = 1; cour < r + 1; cour++) {
    sumc = 0;
    for (couc = 1; couc < c + 2; couc++) {
      if (couc < c + 1) {
        printf("%d ", box[cour][couc]);
        sumc = sumc + box[cour][couc];
      }
    }
    printf("%d\\n", sumc);
  }
  for (couc = 1; couc < c + 1; couc++) {
    sumr = 0;
    for (cour = 1; cour < r + 2; cour++) {
      sumr = sumr + box[cour][couc];
    }
    printf("%d ", sumr);
    suma = suma + sumr;
  }
  printf("%d\\n", suma);
  return 0;
}
Problem p02413 (C++) — buggy submission, verdict: Time Limit Exceeded

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

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

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

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

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int r, c;
  cin >> r >> c;
  int a[100][100];
  for (int i = 0; i < 100; i++) {
    for (int j = 0; j < 100; j++) {
      a[i][j] = 0;
    }
  }
  for (int i = 0; i < r; i++) {
    for (int j = 0; j < c;) {
      cin >> a[i][j];
    }
  }
  for (int i = 0; i < r; i++) {
    for (int j = 0; j < c; j++) {
      a[i][c] += a[i][j];
    }
  }
  for (int i = 0; i < r; i++) {
    for (int j = 0; j < c; j++) {
      a[r][j] += a[i][j];
    }
  }
  for (int i = 0; i <= r; i++) {
    for (int j = 0; j <= c; j++) {
      cout << a[i][j];
      if (j != c)
        cout << ' ';
    }
    cout << endl;
  }
  return 0;
}
Problem p02413 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

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

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

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


Error: 0

Fixed submission:

#include <iostream>
using namespace std;

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

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

  for (int i = 0; i < r + 1; i++) {
    for (int j = 0; j < c; j++) {
      cout << table[i][j] << " ";
    }
    cout << table[i][c] << endl;
  }
  return 0;
}
Problem p02413 (C++) — buggy submission, verdict: Runtime Error

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

Error: 0

Fixed submission:

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

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

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

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

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

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

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

Error: 0

Fixed submission:

#include <stdio.h>

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

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

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

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

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

  for (int iiii = 0; iiii < t + 1; iiii++) {
    for (int jjjj = 0; jjjj < y + 1; jjjj++) {
      printf("%d", glaf[iiii][jjjj]);
      if (jjjj != y)
        printf(" ");
    }
    printf("\\n");
  }
  return 0;
}
Problem p02413 (C++) — buggy submission, verdict: Runtime Error

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

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

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

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

  cout << sumfin << endl;

  return 0;
}


Error: 0

Fixed submission:

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

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

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

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

  return 0;
}
Problem p02413 (C++) — buggy submission, verdict: Runtime Error

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


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

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

Error: 0

Fixed submission:

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

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

Error: 0

Fixed submission:

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

#include <stdio.h>
int a, s, d[1000][1000], f, g, h, i, j;
int main(void) {
  scanf("%d %d", &a, &s);
  for (i = 0; i < a; i++) {
    for (j = 0; j < s; j++)
      scanf("%d", &d[i][j]);
  }
  for (i = 0; i < a; i++) {
    for (j = 0; j < s; j++)
      d[i][s] += d[i][j];
    d[a][s] += d[i][j];
  }
  for (i = 0; i < s; i++) {
    for (j = 0; j < a; j++)
      d[a][i] += d[j][i];
  }
  for (i = 0; i <= a; i++) {
    for (j = 0; j <= s; j++) {
      printf("%d", d[i][j]);
      if (s != j) {
        printf(" ");
      }
    }
    printf("\\n");
  }
  return 0;
}

Error: 0

Fixed submission:

#include <stdio.h>
int main(void) {
  int a, s, d[100][100], f, g, h, i, j;
  scanf("%d %d", &a, &s);
  for (i = 0; i < a; i++) {
    for (j = 0; j < s; j++)
      scanf("%d", &d[i][j]);
  }
  for (i = 0; i < a; i++) {
    for (j = 0; j < s; j++)
      d[i][s] += d[i][j];
    d[a][s] += d[i][j];
  }
  for (i = 0; i < s; i++) {
    for (j = 0; j < a; j++)
      d[a][i] += d[j][i];
  }
  for (i = 0; i <= a; i++) {
    for (j = 0; j <= s; j++) {
      printf("%d", d[i][j]);
      if (s != j) {
        printf(" ");
      }
    }
    printf("\\n");
  }
  return 0;
}