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

Buggy submission (status: Time Limit Exceeded):
#include <iostream>

using namespace std;

int main() {
  int m, f, r;

  char grade;

  while (true) {
    cin >> m >> f >> r;

    if (m == 0 && f == 0) {
      break;
    }

    if (m == -1 || f == -1) {
      grade = 'F';
    } else if (m + f >= 80) {
      grade = 'A';
    } else if (m + f >= 65) {
      grade = 'B';
    } else if (m + f >= 50) {
      grade = 'C';
    } else if (m + f >= 30) {
      if (r >= 50) {
        grade = 'C';
      } else {
        grade = 'D';
      }
    } else {
      grade = 'F';
    }

    cout << grade << endl;
  }

  return 0;
}

Fixed submission:
#include <iostream>

using namespace std;

int main() {
  int m, f, r;

  char grade;

  while (true) {
    cin >> m >> f >> r;

    if (m == -1 && f == -1 && r == -1) {
      break;
    }

    if (m == -1 || f == -1) {
      grade = 'F';
    } else if (m + f >= 80) {
      grade = 'A';
    } else if (m + f >= 65) {
      grade = 'B';
    } else if (m + f >= 50) {
      grade = 'C';
    } else if (m + f >= 30) {
      if (r >= 50) {
        grade = 'C';
      } else {
        grade = 'D';
      }
    } else {
      grade = 'F';
    }

    cout << grade << endl;
  }

  return 0;
}
Problem p02411 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using std::cin;
using std::cout;
using std::endl;

int main() {
  int m, f, r, sum;
  while (1) {
    cin >> m >> f >> r;
    sum = m + f;
    if ((m == -1) & (f == -1) & (r == -1)) {
      return -1;
    } else if (m * f < 0) {
      cout << "F" << endl;
    } else {
      if (sum >= 80)
        cout << "A" << endl;
      else if (sum >= 65)
        cout << "B" << endl;
      else if (sum >= 50)
        cout << "C" << endl;
      else if (sum >= 30) {
        if (r >= 50)
          cout << "C" << endl;
        else
          cout << "D" << endl;
      } else
        cout << "F" << endl;
    }
  }
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using std::cin;
using std::cout;
using std::endl;

int main() {
  int m, f, r, sum;
  while (1) {
    cin >> m >> f >> r;
    sum = m + f;
    if ((m == -1) & (f == -1) & (r == -1)) {
      return 0;
    } else if (m * f < 0) {
      cout << "F" << endl;
    } else {
      if (sum >= 80)
        cout << "A" << endl;
      else if (sum >= 65)
        cout << "B" << endl;
      else if (sum >= 50)
        cout << "C" << endl;
      else if (sum >= 30) {
        if (r >= 50)
          cout << "C" << endl;
        else
          cout << "D" << endl;
      } else
        cout << "F" << endl;
    }
  }
  return 0;
}
Problem p02411 (C++)

Buggy submission (status: Time Limit Exceeded):
#include "iostream"
using namespace std;

int main() {
  int m, f, r = 0;
  bool flag = true;

  while (flag == true) {
    cin >> m >> f >> r;
    if (m == -1 && f == -1 && r == -1)
      flag == false;
    else {
      if (m == -1 || f == -1)
        cout << "F";
      else if (m + f >= 80)
        cout << "A";
      else if (m + f >= 65)
        cout << "B";
      else if (m + f >= 50)
        cout << "C";
      else if (m + f >= 30 && r >= 50)
        cout << "C";
      else if (m + f >= 30)
        cout << "D";
      else
        cout << "F";

      cout << endl;
    }
  }
}

Fixed submission:
#include "iostream"
using namespace std;

int main() {
  int m, f, r = 0;
  bool flag = true;

  while (flag == true) {
    cin >> m >> f >> r;
    if (m == -1 && f == -1 && r == -1)
      flag = false;
    else {
      if (m == -1 || f == -1)
        cout << "F";
      else if (m + f >= 80)
        cout << "A";
      else if (m + f >= 65)
        cout << "B";
      else if (m + f >= 50)
        cout << "C";
      else if (m + f >= 30 && r >= 50)
        cout << "C";
      else if (m + f >= 30)
        cout << "D";
      else
        cout << "F";

      cout << endl;
    }
  }
}
Problem p02411 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;
int main() {
  while (1) {
    int m, f, r;
    if (m == -1 && f == -1 && r == -1) {
      break;
    }
    if (m == -1 or f == -1) {
      cout << "F" << endl;
    } else if (m + f > 79) {
      cout << "A" << endl;
    } else if (m + f < 80 && m + f > 64) {
      cout << "B" << endl;
    } else if (m + f < 65 && m + f > 49) {
      cout << "C" << endl;
    } else if (m + f < 50 && m + f > 29 && r > 49) {
      cout << "C" << endl;
    } else if (m + f < 50 && m + f > 29) {
      cout << "D" << endl;
    } else {
      cout << "F" << endl;
    }
  }
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;
int main() {
  while (1) {
    int m, f, r;
    cin >> m >> f >> r;
    if (m == -1 && f == -1 && r == -1) {
      break;
    }
    if (m == -1 or f == -1) {
      cout << "F" << endl;
    } else if (m + f > 79) {
      cout << "A" << endl;
    } else if (m + f < 80 && m + f > 64) {
      cout << "B" << endl;
    } else if (m + f < 65 && m + f > 49) {
      cout << "C" << endl;
    } else if (m + f < 50 && m + f > 29 && r > 49) {
      cout << "C" << endl;
    } else if (m + f < 50 && m + f > 29) {
      cout << "D" << endl;
    } else {
      cout << "F" << endl;
    }
  }
  return 0;
}
Problem p02411 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>

using namespace std;

int main() {
  int m, f, r;
  while (cin >> m >> f >> r, m != 0 || f != 0 || r != 0) {
    if (m + f >= 80)
      cout << 'A';
    else if (m + f >= 65)
      cout << 'B';
    else if (m + f >= 50)
      cout << 'C';
    else if (m + f >= 30) {
      if (r >= 50)
        cout << 'C';
      else
        cout << 'D';
    } else
      cout << 'F';
    cout << endl;
  }
}

Fixed submission:
#include <iostream>

using namespace std;

int main() {
  int m, f, r;
  while (cin >> m >> f >> r, m != -1 || f != -1 || r != -1) {
    if (m == -1 || f == -1)
      cout << 'F';
    else if (m + f >= 80)
      cout << 'A';
    else if (m + f >= 65)
      cout << 'B';
    else if (m + f >= 50)
      cout << 'C';
    else if (m + f >= 30) {
      if (r >= 50)
        cout << 'C';
      else
        cout << 'D';
    } else
      cout << 'F';
    cout << endl;
  }
}
Problem p02411 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>

using namespace std;

int main() {
  int m, f, r;
  while (true) {
    cin >> m >> f >> r;
    if (m == f == r == -1)
      break;
    if (m == -1 || f == -1)
      cout << 'F' << endl;
    else if (m + f >= 80)
      cout << 'A' << endl;
    else if (m + f >= 65)
      cout << 'B' << endl;
    else if (m + f >= 50)
      cout << 'C' << endl;
    else if (m + f >= 30) {
      if (r >= 50)
        cout << 'C' << endl;
      else
        cout << 'D' << endl;
    } else
      cout << 'F' << endl;
  }
  return 0;
}


Fixed submission:
#include <iostream>

using namespace std;

int main() {
  int m, f, r;
  while (true) {
    cin >> m >> f >> r;
    if (m == -1 && f == -1 && r == -1)
      break;
    if (m == -1 || f == -1)
      cout << 'F' << endl;
    else if (m + f >= 80)
      cout << 'A' << endl;
    else if (m + f >= 65)
      cout << 'B' << endl;
    else if (m + f >= 50)
      cout << 'C' << endl;
    else if (m + f >= 30) {
      if (r >= 50)
        cout << 'C' << endl;
      else
        cout << 'D' << endl;
    } else
      cout << 'F' << endl;
  }
  return 0;
}
Problem p02411 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
using namespace std;

int main(void) {
  int m, f, r;
  while (1) {
    cin >> m >> f >> r;
    if (m == -2 && f == -1 && r == -1)
      break;
    if (m == -1 || f == -1)
      cout << 'F' << endl;
    else if (m + f >= 80)
      cout << 'A' << endl;
    else if (m + f >= 65)
      cout << 'B' << endl;
    else if (m + f >= 50)
      cout << 'C' << endl;
    else if (m + f >= 30) {
      if (r >= 50)
        cout << 'C' << endl;
      else
        cout << 'D' << endl;
    } else
      cout << 'F' << endl;
  }
  return 0;
}

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

int main(void) {
  int m, f, r;
  while (1) {
    cin >> m >> f >> r;
    if (m == -1 && f == -1 && r == -1)
      break;
    if (m == -1 || f == -1)
      cout << 'F' << endl;
    else if (m + f >= 80)
      cout << 'A' << endl;
    else if (m + f >= 65)
      cout << 'B' << endl;
    else if (m + f >= 50)
      cout << 'C' << endl;
    else if (m + f >= 30) {
      if (r >= 50)
        cout << 'C' << endl;
      else
        cout << 'D' << endl;
    } else
      cout << 'F' << endl;
  }
  return 0;
}
Problem p02411 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;

int main() {
  while (true) {
    char grade;
    int m, f, r;
    cin >> m >> f >> r;
    if (m == 0 && f == 0 && r == 0)
      break;
    if (m == -1 || f == -1) {
      grade = 'F';
    } else if (m + f >= 80) {
      grade = 'A';
    } else if (m + f >= 65) {
      grade = 'B';
    } else if (m + f >= 50) {
      grade = 'C';
    } else if (m + f >= 30) {
      (r >= 50) ? grade = 'C' : grade = 'D';
    } else {
      grade = 'F';
    }
    cout << grade << endl;
  }
}


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

int main() {
  while (true) {
    char grade;
    int m, f, r;
    cin >> m >> f >> r;
    if (m == -1 && f == -1 && r == -1)
      break;
    if (m == -1 || f == -1) {
      grade = 'F';
    } else if (m + f >= 80) {
      grade = 'A';
    } else if (m + f >= 65) {
      grade = 'B';
    } else if (m + f >= 50) {
      grade = 'C';
    } else if (m + f >= 30) {
      (r >= 50) ? grade = 'C' : grade = 'D';
    } else {
      grade = 'F';
    }
    cout << grade << endl;
  }
}
Problem p02411 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>

int main() {
  while (1) {

    int m, f, r;

    std::cin >> m >> f >> r;

    if (m == -1 || f == -1) {
      std::cout << "F" << std::endl;
    } else if (m + f < 30) {
      std::cout << "F" << std::endl;
    } else if (m + f < 50 && r >= 50) {
      std::cout << "C" << std::endl;
    } else if (m + f < 50) {
      std::cout << "D" << std::endl;
    } else if (m + f < 65) {
      std::cout << "C" << std::endl;
    } else if (m + f < 80) {
      std::cout << "B" << std::endl;
    } else {
      std::cout << "A" << std::endl;
    }
  }

  return 0;
}

Fixed submission:
#include <iostream>

int main() {
  while (1) {

    int m, f, r;

    std::cin >> m >> f >> r;

    if (m == -1 && f == -1 && r == -1) {
      break;
    }
    if (m == -1 || f == -1) {
      std::cout << "F" << std::endl;
    } else if (m + f < 30) {
      std::cout << "F" << std::endl;
    } else if (m + f < 50 && r >= 50) {
      std::cout << "C" << std::endl;
    } else if (m + f < 50) {
      std::cout << "D" << std::endl;
    } else if (m + f < 65) {
      std::cout << "C" << std::endl;
    } else if (m + f < 80) {
      std::cout << "B" << std::endl;
    } else {
      std::cout << "A" << std::endl;
    }
  }

  return 0;
}
Problem p02411 (C++)

Buggy submission (status: Runtime Error):
#include <stdio.h>
typedef struct GRADE {
  int m; //??????????¨?????????°???
  int f; //??????????¨?????????°
  int r; //???????¨?????????°

  char grad; //??????
};
int main() {
  GRADE std[10];
  int i = 0, j;
  int sum, sum2;
  while (1) {
    scanf("%d %d %d", &std[i].m, &std[i].f, &std[i].r);
    if (std[i].m == -1 && std[i].f == -1 && std[i].r == -1) {
      break;
    }
    i++;
  }

  for (j = 0; j < i; j++) {

    sum = std[j].m + std[j].f;

    sum2 = std[j].r;
    if (sum < 30 || std[j].m == -1 || std[j].f == -1) {
      std[j].grad = 'F';
    } else if (sum >= 80) {
      std[j].grad = 'A';
    } else if (sum >= 65 && sum < 80) {
      std[j].grad = 'B';
    } else if ((sum >= 50 && sum < 65) || sum2 >= 50) {
      std[j].grad = 'C';
    } else if (sum >= 30 && sum < 50) {
      std[j].grad = 'D';
    }

    printf("%c\n", std[j].grad);
  }

  return 0;
}

Fixed submission:
#include <stdio.h>
typedef struct GRADE {
  int m; //??????????¨?????????°???
  int f; //??????????¨?????????°
  int r; //???????¨?????????°

  char grad; //??????
};
int main() {
  GRADE std[100];
  int i = 0, j;
  int sum, sum2;
  while (1) {
    scanf("%d %d %d", &std[i].m, &std[i].f, &std[i].r);
    if (std[i].m == -1 && std[i].f == -1 && std[i].r == -1) {
      break;
    }
    i++;
  }

  for (j = 0; j < i; j++) {

    sum = std[j].m + std[j].f;

    sum2 = std[j].r;
    if (sum < 30 || std[j].m == -1 || std[j].f == -1) {
      std[j].grad = 'F';
    } else if (sum >= 80) {
      std[j].grad = 'A';
    } else if (sum >= 65 && sum < 80) {
      std[j].grad = 'B';
    } else if ((sum >= 50 && sum < 65) || sum2 >= 50) {
      std[j].grad = 'C';
    } else if (sum >= 30 && sum < 50) {
      std[j].grad = 'D';
    }

    printf("%c\n", std[j].grad);
  }

  return 0;
}
Problem p02411 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>

int main(int argc, char const *argv[]) {
  int m, f, r;
  std::cin >> m >> f >> r;
  while (!(m == -1 && m == f && m == r)) {
    if (m == -1 || f == -1 || m + f < 30) {
      std::cout << "F";
    } else if (m + f >= 80) {
      std::cout << "A";
    } else if (m + f >= 65) {
      std::cout << "B";
    } else if (m + f >= 50) {
      std::cout << "C";
    } else {
      if (r >= 50) {
        std::cout << "C";
      } else {
        std::cout << "D";
      }
    }
    std::cout << std::endl;
  }
}

Fixed submission:
#include <iostream>

int main(int argc, char const *argv[]) {
  int m, f, r;
  std::cin >> m >> f >> r;
  while (!(m == -1 && m == f && m == r)) {
    if (m == -1 || f == -1 || m + f < 30) {
      std::cout << "F";
    } else if (m + f >= 80) {
      std::cout << "A";
    } else if (m + f >= 65) {
      std::cout << "B";
    } else if (m + f >= 50) {
      std::cout << "C";
    } else {
      if (r >= 50) {
        std::cout << "C";
      } else {
        std::cout << "D";
      }
    }
    std::cin >> m >> f >> r;
    std::cout << std::endl;
  }
}
Problem p02411 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
using namespace std;

int main() {
  int m, f, r;

  while (1) {
    cin >> m >> f >> r;

    if (m == -1 || f == -1) {
      cout << 'F' << endl;
    } else if (m + f >= 80) {
      cout << 'A' << endl;
    } else if (m + f >= 65) {
      cout << 'B' << endl;
    } else if (m + f >= 50) {
      cout << 'C' << endl;
    } else if (m + f >= 30) {
      if (r >= 50) {
        cout << 'C' << endl;
      } else {
        cout << 'D' << endl;
      }
    } else {
      cout << 'F' << endl;
    }
  }

  return 0;
}

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

int main() {
  int m, f, r;

  while (1) {
    cin >> m >> f >> r;
    if (m == -1 && f == -1 && r == -1) {
      break;
    }

    if (m == -1 || f == -1) {
      cout << 'F' << endl;
    } else if (m + f >= 80) {
      cout << 'A' << endl;
    } else if (m + f >= 65) {
      cout << 'B' << endl;
    } else if (m + f >= 50) {
      cout << 'C' << endl;
    } else if (m + f >= 30) {
      if (r >= 50) {
        cout << 'C' << endl;
      } else {
        cout << 'D' << endl;
      }
    } else {
      cout << 'F' << endl;
    }
  }

  return 0;
}
Problem p02412 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cctype>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>

using namespace std;

int arr[100 + 5];
int n, sum;
int count1;

void dfs(int i, int x, int m) {
  if (x > sum)
    return;
  if ((i == n)) {
    // for(int i=0;i<n;i++) cout<<arr[i]<<" ";
    // cout<<endl;
    if (sum == x && m == 3) {
      count1++;
      // for(int i=0;i<n;i++) cout<<arr[i]<<" ";
      // cout<<endl;
    }
    return;
  }
  dfs(i + 1, x + arr[i], m + 1);
  dfs(i + 1, x, m);
  return;
}

int main() {
  while (cin >> n >> sum && (n || sum)) {
    count1 = 0;
    for (int i = 0; i < n; i++)
      arr[i] = i + 1;
    dfs(0, 0, 0);
    cout << count1 << endl;
  }
  // while(1);
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cctype>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>

using namespace std;

int arr[100 + 5];
int n, sum;
int count1;

void dfs(int i, int x, int m) {
  if (x > sum)
    return;
  if ((i == n)) {
    // for(int i=0;i<n;i++) cout<<arr[i]<<" ";
    // cout<<endl;
    if (sum == x && m == 3) {
      count1++;
      // for(int i=0;i<n;i++) cout<<arr[i]<<" ";
      // cout<<endl;
    }
    return;
  }
  dfs(i + 1, x + arr[i], m + 1);
  dfs(i + 1, x, m);
  return;
}

int main() {
  while (cin >> n >> sum && (n || sum)) {
    count1 = 0;
    for (int i = 0; i < n; i++)
      arr[i] = i + 1;
    for (int i = 0; i < n; i++) {
      for (int j = i + 1; j < n; j++) {
        for (int k = j + 1; k < n; k++) {
          if ((arr[i] + arr[j] + arr[k]) == sum)
            count1++;
        }
      }
    }
    cout << count1 << endl;
  }
  // while(1);
  return 0;
}
Problem p02412 (C++)

Buggy submission (status: Runtime Error):
#include <cstdio>
#include <iostream>
using namespace std;
int main() {
  int a, n, c = 0;
  while (1) {
    c = 0;
    cin >> a >> n;
    if (a == 0 && n == 0)
      break;
    for (int i = 1; i <= a; i++)
      for (int j = i + 1; j <= a; j++)
        for (int k = j + 1; k <= a; k++)
          if (i + j + k == n)
            c++;
    cout << c << '\n';
  }
  return 4;
}

Fixed submission:
#include <cstdio>
#include <iostream>
using namespace std;
int main() {
  int a, n, c = 0;
  while (1) {
    c = 0;
    cin >> a >> n;
    if (a == 0 && n == 0)
      break;
    for (int i = 1; i <= a; i++)
      for (int j = i + 1; j <= a; j++)
        for (int k = j + 1; k <= a; k++)
          if (i + j + k == n)
            c++;
    cout << c << '\n';
  }
  return 0;
}
Problem p02412 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;

int main(void) {

  int n, x;
  while (cin >> n >> x) {
    if (n == 0 && x == 0)
      break;

    long long int cnt = 0;
    for (int i = 1; i <= n; i++) {
      for (int j = i + 1; j <= n; j++) {
        if (i >= x - i - j || j >= x - i - j)
          continue;
        if (x - i - j <= n && x - i - j > 0)
          cnt++;
        if (x - i - j <= n && x - i - j > 0)
          cerr << i << " " << j << " " << x - i - j << endl;
      }
    }
    cout << cnt << endl;
  }

  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;

int main(void) {

  int n, x;
  while (cin >> n >> x) {
    if (n == 0 && x == 0)
      break;

    long long int cnt = 0;
    for (int i = 1; i <= n; i++) {
      for (int j = i + 1; j <= n; j++) {
        if (i >= x - i - j || j >= x - i - j)
          continue;
        if (x - i - j <= n && x - i - j > 0)
          cnt++;
      }
    }
    cout << cnt << endl;
  }

  return 0;
}
Problem p02412 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
using namespace std;

int main() {
  int n, x;
  while (1) {
    int cnt = 0;
    cin >> n >> x;
    for (int i = 1; i <= n - 2; i++) {
      for (int j = i + 1; j <= n - 1; j++) {
        for (int k = j + 1; k <= n; k++) {
          int sum = i;
          sum += k;
          sum += j;
          if (sum == x)
            cnt++;
        }
      }
    }
    cout << cnt << endl;
  }

  return 0;
}

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

int main() {
  int n, x;
  while (1) {
    int cnt = 0;
    cin >> n >> x;
    if (n == 0 && x == 0)
      break;
    for (int i = 1; i <= n - 2; i++) {
      for (int j = i + 1; j <= n - 1; j++) {
        for (int k = j + 1; k <= n; k++) {
          int sum = i;
          sum += k;
          sum += j;
          if (sum == x)
            cnt++;
        }
      }
    }
    cout << cnt << endl;
  }

  return 0;
}
Problem p02412 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
using namespace std;
int main() {
  int n, x;

  while (true) {
    int d = 0;
    cin >> n >> x;

    for (int i = 1; i <= n; i++) {
      for (int j = i + 1; j <= n; j++) {
        for (int k = j + 1; k <= n; k++) {

          if ((i + j + k) == x)
            d++;
          if ((i + j + k) > x)
            break;
        }
      }
    }
    cout << d << endl;
  }
}

Fixed submission:
#include <iostream>
using namespace std;
int main() {
  int n, x;

  while (true) {
    int d = 0;
    cin >> n >> x;
    if (n == 0 && x == 0)
      break;

    for (int i = 1; i <= n; i++) {
      for (int j = i + 1; j <= n; j++) {
        for (int k = j + 1; k <= n; k++) {

          if ((i + j + k) == x)
            d++;
          if ((i + j + k) > x)
            break;
        }
      }
    }
    cout << d << endl;
  }
}
Problem p02412 (C++)

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

int main() {
  int Ans[1000][3000];
  int n[100000], x[100000];
  int c = 0;
  memset(Ans, 0, sizeof(Ans));
  for (int i = 3; i <= 100; i++) {
    for (int j = 3; j <= i; j++) {
      for (int k = 2; k < j; k++) {
        for (int l = 1; l < k; l++) {
          Ans[i][j + k + l]++;
        }
      }
    }
  }
  for (int i = 1; i <= 100000; i++) {
    cin >> n[i] >> x[i];
    if (x[i] == 0 && n[i] == 0) {
      goto Exit;
    }
    c++;
  }
Exit:
  for (int i = 1; i <= c; i++) {
    cout << Ans[n[i]][x[i]] << endl;
  }
  return 0;
}

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

int main() {
  int Ans[500][1000];
  int n[100000], x[100000];
  int c = 0;
  memset(Ans, 0, sizeof(Ans));
  for (int i = 3; i <= 100; i++) {
    for (int j = 3; j <= i; j++) {
      for (int k = 2; k < j; k++) {
        for (int l = 1; l < k; l++) {
          Ans[i][j + k + l]++;
        }
      }
    }
  }
  for (int i = 1; i <= 100000; i++) {
    cin >> n[i] >> x[i];
    if (x[i] == 0 && n[i] == 0) {
      goto Exit;
    }
    c++;
  }
Exit:
  for (int i = 1; i <= c; i++) {
    cout << Ans[n[i]][x[i]] << endl;
  }
  return 0;
}
Problem p02412 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;

int count(int n, int x) {
  int cnt = 0;
  for (int i = 1; i <= n - 2; i++) {
    for (int j = 1 + i; j = n - 1; j++) {
      for (int k = j + 1; k <= n; k++) {
        if (i + j + k == x)
          cnt++;
      }
    }
  }
  return cnt;
}

int main() {
  int n, x;

  while (1) {
    cin >> n >> x;
    if (n == 0 && x == 0)
      break;
    cout << count(n, x) << endl;
  }

  return 0;
}

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

int count(int n, int x) {
  int cnt = 0;
  for (int i = 1; i <= n - 2; i++) {
    for (int j = 1 + i; j <= n - 1; j++) {
      for (int k = j + 1; k <= n; k++) {
        if (i + j + k == x)
          cnt++;
      }
    }
  }
  return cnt;
}

int main() {
  int n, x;

  while (1) {
    cin >> n >> x;
    if (n == 0 && x == 0)
      break;
    cout << count(n, x) << endl;
  }

  return 0;
}
Problem p02412 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
using namespace std;

int main() {
  int a, n, x;

  while (1) {
    a = 0;
    cin >> n >> x;
    if (n == 0 && x == 0) {
      break;
    } else {
      for (int h = 1; h <= n; h++) {
        for (int i = h + 1; i <= n; i++) {
          for (int j = i + 1; j <= n; i++) {
            if (h + i + j == x) {
              a += 1;
            }
          }
        }
      }
      cout << a << endl;
    }
  }
  return 0;
}


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

int main() {
  int a, n, x;

  while (1) {
    a = 0;
    cin >> n >> x;
    if (n == 0 && x == 0) {
      break;
    } else {
      for (int h = 1; h <= n; h++) {
        for (int i = h + 1; i <= n; i++) {
          for (int j = i + 1; j <= n; j++) {
            if (h + i + j == x) {
              a += 1;
            }
          }
        }
      }
      cout << a << endl;
    }
  }
  return 0;
}
Problem p02412 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
using namespace std;

int n, x;

int loop(int cnt, int sum, int plus) {
  if (cnt == 3 && sum == x) {
    return 1;
  }

  if (plus > n) {
    return 0;
  }

  return loop(cnt + 1, sum + plus, plus + 1) + loop(cnt, sum, plus + 1);
}

int main() {
  while (cin >> n >> x && (n != 0 || x != 0)) {
    cout << loop(0, 0, 1) << endl;
  }
}

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

int n, x;

int loop(int cnt, int sum, int plus) {
  if (cnt == 3) {
    if (sum == x) {
      return 1;
    } else {
      return 0;
    }
  }

  if (plus > n) {
    return 0;
  }

  return loop(cnt + 1, sum + plus, plus + 1) + loop(cnt, sum, plus + 1);
}

int main() {
  while (cin >> n >> x && (n != 0 || x != 0)) {
    cout << loop(0, 0, 1) << endl;
  }
}
Problem p02412 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;

int main() {
  while (true) {
    int n, x;
    cin >> n >> x;
    if (n == x && x == -1) {
      return 0;
    }
    int ans = 0;
    for (int i = 1; i < n + 1; i++) {
      for (int j = i + 1; j < n + 1; j++) {
        for (int k = j + 1; k < n + 1; k++) {
          if (i + j + k == x) {
            ans++;
          }
        }
      }
    }
    cout << ans << endl;
  }

  return 0;
}

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

int main() {
  while (true) {
    int n, x;
    cin >> n >> x;
    if (n == x && x == 0) {
      return 0;
    }
    int ans = 0;
    for (int i = 1; i < n + 1; i++) {
      for (int j = i + 1; j < n + 1; j++) {
        for (int k = j + 1; k < n + 1; k++) {
          if (i + j + k == x) {
            ans++;
          }
        }
      }
    }
    cout << ans << endl;
  }

  return 0;
}
Problem p02412 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
using namespace std;

int count(int n, int x) {
  int cnt = 0;
  int i, j, k;
  for (i = 1; i <= n - 2; i++) {
    for (j = i + 1; i <= n - 1; k++) {
      for (k = j + 1; i <= n; j++) {
        if (i + j + k == x)
          cnt++;
      }
    }
  }
  return cnt;
}

int main() {
  int n, x;

  while (1) {
    cin >> n >> x;
    if (n == 0 && x == 0)
      break;
    cout << count(n, x) << endl;
  }

  return 0;
}

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

int count(int n, int x) {
  int cnt = 0;
  int i, j, k;
  for (i = 1; i <= n - 2; i++) {
    for (j = i + 1; j <= n - 1; j++) {
      for (k = j + 1; k <= n; k++) {
        if (i + j + k == x)
          cnt++;
      }
    }
  }
  return cnt;
}

int main() {
  int n, x;

  while (1) {
    cin >> n >> x;
    if (n == 0 && x == 0)
      break;
    cout << count(n, x) << endl;
  }

  return 0;
}
Problem p02412 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#define MAXNUM 100
#define MAXSUM 300
using namespace std;

int dp2[MAXNUM][MAXSUM];
int dp3[MAXNUM][MAXSUM];

int main() {
  int n, m, i, j;
  while (1) {
    cin >> n >> m;
    if (n == 0)
      break;
    for (i = 2; i <= n; i++) {
      for (j = 3; j <= m; j++) {
        dp2[i][j] = dp2[i - 1][j];
        if (j - i > 0 && i - 1 >= j - i)
          dp2[i][j]++;
        dp3[i][j] = dp3[i - 1][j];
        if (j - i > 0)
          dp3[i][j] += dp2[i - 1][j - i];
      }
    }

    cout << dp3[n][m] << endl;
  }
  return 0;
}

Fixed submission:
#include <iostream>
#define MAXNUM 200
#define MAXSUM 600
using namespace std;

int dp2[MAXNUM][MAXSUM];
int dp3[MAXNUM][MAXSUM];

int main() {
  int n, m, i, j;
  while (1) {
    cin >> n >> m;
    if (n == 0)
      break;
    for (i = 2; i <= n; i++) {
      for (j = 3; j <= m; j++) {
        dp2[i][j] = dp2[i - 1][j];
        if (j - i > 0 && i - 1 >= j - i)
          dp2[i][j]++;
        dp3[i][j] = dp3[i - 1][j];
        if (j - i > 0)
          dp3[i][j] += dp2[i - 1][j - i];
      }
    }

    cout << dp3[n][m] << endl;
  }
  return 0;
}
Problem p02412 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
template <typename T> std::string to_string(const T &n) {
  std::ostringstream stm;
  stm << n;
  return stm.str();
}

int main(void) {
  int n, x;
  int tx, ty, tz;
  int ans = 0;
  cin >> n >> x;
  while (n != -1 || x != -1) {
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= n; j++) {
        for (int k = 1; k <= n; k++) {
          if (i + j + k == x && (i != j && j != k && k != i))
            ans++;
        }
      }
    }
    cout << ans / 6 << "\n";
    ans = 0;
    cin >> n >> x;
  }
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
template <typename T> std::string to_string(const T &n) {
  std::ostringstream stm;
  stm << n;
  return stm.str();
}

int main(void) {
  int n, x;
  int tx, ty, tz;
  int ans = 0;
  cin >> n >> x;
  while (n != 0 || x != 0) {
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= n; j++) {
        for (int k = 1; k <= n; k++) {
          if (i + j + k == x && (i != j && j != k && k != i))
            ans++;
        }
      }
    }
    cout << ans / 6 << "\n";
    ans = 0;
    cin >> n >> x;
  }
  return 0;
}
Problem p02412 (C++)

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

const int N = 100;

int main(void) {
  int n = 0;
  int x = 0;

  std::cin >> n >> x;

  while (!((n == 0) && (x == 0))) {
    int count = 0;
    bool generated[N][N][N] = {false};

    for (int i = 1; i <= n - 2; i++) {
      for (int j = 1; j <= n - 1; j++) {
        for (int k = 1; k <= n; k++) {
          if ((i == j) || (j == k) || (i == k)) {
            continue;
          }

          if (generated[i][j][k]) {
            continue;
          }

          if ((i + j + k) == x) {
            count++;

            generated[i][j][k] = true;
            generated[i][k][j] = true;
            generated[j][i][k] = true;
            generated[j][k][i] = true;
            generated[k][i][j] = true;
            generated[k][j][i] = true;
          }
        }
      }
    }

    std::cout << count << std::endl;

    std::cin >> n >> x;
  }

  return 0;
}

Fixed submission:
#include <iostream>

const int N = 100;

int main(void) {
  int n = 0;
  int x = 0;

  std::cin >> n >> x;

  while (!((n == 0) && (x == 0))) {
    int count = 0;
    bool generated[N + 1][N + 1][N + 1] = {false};

    for (int i = 1; i <= n - 2; i++) {
      for (int j = 1; j <= n - 1; j++) {
        for (int k = 1; k <= n; k++) {
          if ((i == j) || (j == k) || (i == k)) {
            continue;
          }

          if (generated[i][j][k]) {
            continue;
          }

          if ((i + j + k) == x) {
            count++;

            generated[i][j][k] = true;
            generated[i][k][j] = true;
            generated[j][i][k] = true;
            generated[j][k][i] = true;
            generated[k][i][j] = true;
            generated[k][j][i] = true;
          }
        }
      }
    }

    std::cout << count << std::endl;

    std::cin >> n >> x;
  }

  return 0;
}
Problem p02412 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
using namespace std;
int main() {
  int n, x;
  int a = 0;

  while (1) {
    cin >> n >> x;
    if (n == 0 && x == 0)
      break;

    for (int i = 1; i <= n; i++) {
      for (int j = i + 1; j <= n; j++) {
        for (int k = j + 1; j <= n; k++) {
          if (i + j + k == x)
            a++;
        }
      }
    }
    cout << a << endl;
    a = 0;
  }
}


Fixed submission:
#include <iostream>
using namespace std;
int main() {
  int n, x;
  int a = 0;

  while (1) {
    cin >> n >> x;
    if (n == 0 && x == 0)
      break;

    for (int i = 1; i <= n; i++) {
      for (int j = i + 1; j <= n; j++) {
        for (int k = j + 1; k <= n; k++) {
          if (i + j + k == x)
            a++;
        }
      }
    }
    cout << a << endl;
    a = 0;
  }
}
Problem p02413 (C++)

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

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

Buggy submission (status: 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[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;
}


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[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;
}
Problem p02413 (C++)

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

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

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


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

Buggy submission (status: 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[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;
}

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[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;
}
Problem p02413 (C++)

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

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

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

int main() {
  int r, c, i, j;
  int table[100][100] = {0};

  cin >> r >> c;
  for (i = 0; i < r; i++) {
    for (j = 0; j < c; j++) {
      cin >> table[i][j];
    }
  }
  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;
}

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

int main() {
  int r, c, i, j;
  int table[101][101] = {0};

  cin >> r >> c;
  for (i = 0; i < r; i++) {
    for (j = 0; j < c; j++) {
      cin >> table[i][j];
    }
  }
  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 (status: 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 < 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;
}

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

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


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

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

using namespace std;

int main() {
  int r, c;
  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];
      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++) {
      cout << a[i][j];
      if (j != c)
        cout << " ";
      else
        cout << endl;
    }
  }

  return 0;
}

Fixed submission:
#include <iostream>

using namespace std;

int main() {
  int r, c;
  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];
      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++) {
      cout << a[i][j];
      if (j != c)
        cout << " ";
      else
        cout << endl;
    }
  }

  return 0;
}
Problem p02413 (C++)

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

Fixed submission:
#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;
}