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

#include <iostream>
using namespace std;
int main() {
  int b[1000], a[1000][100], c, i = 1, x, g, y, h = 1, u = 0;
  cin >> x >> y;
  for (i = 1; i <= x; i++) {
    for (g = 1; g <= y; g++) {
      cin >> a[i][g];
    }
  }
  for (i = 1; i <= y; i++) {
    cin >> b[i];
  }
  for (i = 1; i <= x; i++) {
    u = 0;
    for (g = 1; g <= y; g++) {
      u += (a[i][g] * b[g]);
    }
    cout << u << endl;
  }
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int b[10], z, h, a[10][10], x, y, d[10][10], i, c = 0, n, m;
  cin >> n >> m;
  for (x = 1; x <= n; x++) {
    for (y = 1; x <= m; y++) {
      cin >> a[x][y];
    }
  }
  for (z = 1; z <= m; z++) {
    cin >> b[z];
  }
  for (x = 1; x <= n; x++) {
    for (y = 1; y <= m; y++) {
      d[x][y] = a[x][y] * b[y];
    }
  }
  for (x = 1; x <= n; x++) {
    for (y = 1; y <= m; y++) {
      c += d[x][y];
    }
    cout << " " << c << endl;
  }
}
Problem p02413 (C++) — buggy submission, verdict: Runtime Error

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

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

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

Error: 0

Fixed submission:

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

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

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

  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];
    cout << endl;
  }
  for (int j = 0; j < c; j++) {
    cout << a[r][j] << " ";
    a[r][c] += a[r][j];
  }
  cout << a[r][c] << endl;
  return 0;
}
Problem p02413 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

int main() {
  int r, c, sum, total;
  total = 0;
  cin >> r >> c;
  int **sheet = new int *[r + 1];
  for (int i = 0; i < r + 1; i++) {
    sheet[i] = new int[c + 1];
  }
  for (int y = 0; y < r; y++) {
    sum = 0;
    for (int x = 0; x < c; x++) {
      cin >> sheet[y][x];
      sum += sheet[y][x];
    }
    sheet[y][c] = sum;
  }
  for (int x = 0; x < c; x++) {
    sum = 0;
    for (int y = 0; y < r; y++) {
      sum += sheet[y][x];
      total += sheet[y][x];
    }
    sheet[r][x] = sum;
  }
  sheet[r][c] = total;
  for (int y = 0; y < r + 1; y++) {
    for (int x = 0; x < c + 1; x++) {
      if (x == c)
        cout << sheet[y][x];
      else
        cout << sheet[y][x] << " ";
    }
    cout << endl;
  }
  return 0;
}


Error: -11

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int r, c, sum, total;
  total = 0;
  cin >> r >> c;
  int **sheet = new int *[r + 1];
  for (int i = 0; i < r; i++) {
    sheet[i] = new int[c + 1];
  }
  for (int y = 0; y < r; y++) {
    sum = 0;
    for (int x = 0; x < c; x++) {
      cin >> sheet[y][x];
      sum += sheet[y][x];
    }
    sheet[y][c] = sum;
  }
  for (int x = 0; x < c; x++) {
    sum = 0;
    for (int y = 0; y < r; y++) {
      sum += sheet[y][x];
      total += sheet[y][x];
    }
    sheet[r][x] = sum;
  }
  sheet[r][c] = total;
  for (int y = 0; y < r + 1; y++) {
    for (int x = 0; x < c + 1; x++) {
      cout << sheet[y][x] << " ";
    }
    cout << endl;
  }
  return 0;
}
Problem p02413 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

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

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

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

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

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

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {

  int hyo[100][100];
  int r, c, n;
  while (1) {

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

    cin >> r >> c;

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

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

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

Error: 0

Fixed submission:

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

#include <iostream>
using namespace std;

int main() {
  int table[101][101] = {{}};
  int i, j, r, c;
  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];
      table[r][c] += table[i][j];
    }
  }

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


Error: 0

Fixed submission:

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

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

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

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

int main() {
  int n, m;
  cin >> n >> m;

  vector<int> v(m + 1, 0);
  vector<vector<int>> a(n + 1, v);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      // cout << "a[" << i << ", " << j << "] ?";
      cin >> a[i][j];
      a[i][m] += a[i][j];
      a[n][j] += a[i][j];
      a[n][m] += a[i][j];
    }
  }

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

  return 0;
}


Error: WA

Fixed submission:

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

int main() {
  int n, m;
  cin >> n >> m;

  int a[n + 1][m + 1];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> a[i][j];
      a[i][m + 1] += a[i][j];
      a[n + 1][j] += a[i][j];
    }
  }

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

  return 0;
}
Problem p02413 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
int main() {
  int r, c, sum;
  cin >> r >> c;
  int a[101][101] = {};

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

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

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

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

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


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int r, c, sum;
  cin >> r >> c;
  int a[100][100] = {};

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

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

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

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

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

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

Error: 0

Fixed submission:

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

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

Error: 0

Fixed submission:

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

#include <iostream>
using namespace std;

unsigned long long int i, j, k, counter, a, b;
unsigned long long int t, y;
unsigned long long int ef[110][110];
int main() {
  counter = 0;
  a = 0;
  b = 0;
  cin >> t >> y;
  for (i = 0; i < t; i++) {
    for (j = 0; j < y; j++) {
      cin >> ef[i][j];
      cout << ef[i][j] << ' ';
      a += ef[i][j];
    }
    ef[i][y] = a;
    cout << ef[i][y] << endl;
    a = 0;
  }
  ///////////////////
  for (j = 0; j <= y; j++) {
    for (i = 0; i < t; i++) {
      k += ef[i][j];
    }
    ef[t][j] = k;
    k = 0;
  }
  ////////////////
  for (i = 0; i < y; i++) {
    cout << ef[t][i] << ' ';
  }
  cout << ef[t][y] << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
using namespace std;

unsigned long long int i, j, k, counter, a, b;
unsigned long long int t, y;
unsigned long long int ef[100][100];
int main() {
  counter = 0;
  a = 0;
  b = 0;
  cin >> t >> y;
  for (i = 0; i < t; i++) {
    for (j = 0; j < y; j++) {
      cin >> ef[i][j];
      cout << ef[i][j] << ' ';
      a += ef[i][j];
    }
    ef[i][y] = a;
    cout << ef[i][y] << endl;
    a = 0;
  }
  ///////////////////
  for (j = 0; j <= y; j++) {
    for (i = 0; i < t; i++) {
      k += ef[i][j];
    }
    ef[t][j] = k;
    k = 0;
  }
  ////////////////
  for (i = 0; i < y; i++) {
    cout << ef[t][i] << ' ';
  }
  cout << ef[t][y] << endl;

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

#include <iostream>
using namespace std;

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

Error: WA

Fixed submission:

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

int main() {
  int i, j, r, c, a[101][101], sr[101] = {}, sc[101] = {}, s = 0;
  ifstream fin("ITP1_7_C-in5.txt");
  fin >> r >> c;
  for (i = 1; i <= r; i++) {
    for (j = 1; j <= c; j++) {
      fin >> a[i][j];
    }
  }
  for (i = 1; i <= r; i++) {
    for (j = 1; j <= c; j++) {
      sr[i] += a[i][j];
    }
  }
  for (j = 1; j <= c; j++) {
    for (i = 1; i <= r; i++) {
      sc[j] += a[i][j];
    }
  }
  for (i = 1; i <= r; i++) {
    s += sr[i];
  }
  for (i = 1; i <= r; i++) {
    for (j = 1; j <= c; j++) {
      cout << a[i][j] << " ";
    }
    cout << sr[i] << endl;
  }
  for (j = 1; j <= c; j++) {
    cout << sc[j] << " ";
  }
  cout << s << endl;
  fin.close();
  return 0;
}
Problem p02413 (C++) — buggy submission, verdict: Runtime Error

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

Error: 0

Fixed submission:

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

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

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

#include <cstdio>
#include <iostream>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int data[101][101] = {0};
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> data[i][j];
      data[i][m] += data[i][j];
      data[n][j] += data[i][j];
      data[n][m] += data[i][j];
    }
  }

  for (int i = 0; i < n + 1; i++) {
    for (int j = 0; j < m + 1; j++) {
      cout << data[i][j];
      if (j != m) {
        cout << " ";
      }
    }
    cout << endl;
  }
}

Error: TLE

Fixed submission:

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

int eval(int x, int y) {
  int i, j, k, cnt = 0;
  for (int i = 1; i <= x; i++) {
    for (int j = i + 1; j <= x; j++) {
      for (int k = j + 1; k <= x; k++) {
        if (i + j + k == y) {
          cnt++;
        }
      }
    }
  }
  return cnt;
}

int main() {

  int x, y;
  while (cin >> x >> y, x + y != 0) {
    cout << eval(x, y) << endl;
  }
}
Problem p02413 (C++) — buggy submission, verdict: Runtime Error

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

Error: 0

Fixed submission:

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

#include <iostream>
#include <vector>

int main() {

  int r, c;
  std::cin >> r >> c;

  std::vector<std::vector<int>> mat;

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

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

  // anticipating mat[i][c] == 0...
  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 + 1; j++) {
      mat[r][j] += mat[i][j];
    }
  }

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

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <vector>

int main() {

  while (true) {
    int r, c;
    std::cin >> r >> c;
    if (r == 0 && c == 0)
      break;

    std::vector<std::vector<int>> mat;
    // mat[r][c]

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

    for (int i = 0; i < r; i++) {
      for (int j = 0; j < c; j++) {
        std::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 + 1; j++) {
        mat[r][j] += mat[i][j];
      }
    }

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

#include <iostream>

using namespace std;

int main() {

  int r, c, 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];
      a[i][c] += a[i][j];
    }
  }

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

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

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

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

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

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

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

  // cin >> /*変数他*/;
  // cout << /*文字列*/ << endl;
  return 0;
}


Error: -11

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++) {

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

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

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

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

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

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

  // cin >> /*変数他*/;
  // cout << /*文字列*/ << endl;
  return 0;
}