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

#include <iostream>
#include <vector>
int main() {
  std::vector<int> a, b;
  while (true) {
    int n;
    int as = 0, bs = 0;
    std::cin >> n;
    if (!n) {
      break;
    }
    for (int i = 0; i < n; ++i) {
      int n, m;
      std::cin >> n >> m;
      if (n == m) {
        as += n;
        bs += m;
      } else if (n > m) {
        as += n + m;
      } else if (m > n) {
        bs += n + m;
      }
    }
    a.push_back(as);
    b.push_back(bs);
  }
  for (int i = 0; i < a.size(); ++i) {
    std::cout << a[i] << " " << b[i] << std::endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <vector>
int main() {
  std::vector<int> a, b;
  while (true) {
    int n;
    int as = 0;
    int bs = 0;
    std::cin >> n;
    if (!n) {
      break;
    }
    for (int i = 0; i < n;) {
      int n, m;
      std::cin >> n >> m;
      if (n > m) {
        as += n + m;
      }
      if (m > n) {
        as += n + m;
      }
    }
    a.push_back(as);
    b.push_back(bs);
  }
  for (int i = 0; i < a.size(); ++i) {
    std::cout << a[i] << " " << b[i] << std::endl;
  }
  return 0;
}
Problem p00423 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <stdio.h>
int main(void) {
  int n;
  int a[10000];
  int b[10000];
  int i;
  int suma, sumb;

  scanf("%d", &n);
  while (n != 0) {
    suma = 0;
    sumb = 0;
    for (i = 0; i < n; i++) {
      scanf("%d %d", &a[i], &b[i]);
      if (a[i] > b[i]) {
        suma = suma + a[i] + b[i];
      } else if (a[i] < b[i]) {
        sumb = sumb + a[i] + b[i];
      } else {
        suma = suma + a[i];
        sumb = sumb + b[i];
      }
    }
    printf("%d %d\\n", suma, sumb);
    scanf("%d", &n);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <stdio.h>
int main(void) {
  int n;
  int a[10000];
  int b[10000];
  int i;
  int suma, sumb;

  scanf("%d", &n);
  while (n != 0) {
    suma = 0;
    sumb = 0;
    for (i = 0; i < n; i++) {
      scanf("%d %d", &a[i], &b[i]);
      if (a[i] > b[i]) {
        suma = suma + a[i] + b[i];
      } else if (a[i] < b[i]) {
        sumb = sumb + a[i] + b[i];
      } else {
        suma = suma + a[i];
        sumb = sumb + b[i];
      }
    }
    printf("%d %d\\n", suma, sumb);
    scanf("%d %d", &a[i], &b[i]);
  }
  return 0;
}
Problem p00423 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int main() {
  int score_a[] = {0, 0, 0, 0, 0};
  int score_b[] = {0, 0, 0, 0, 0};
  int cnt = 0;
  bool flg = true;

  while (flg) {
    int num;

    cin >> num;
    if ((cnt >= 5) || (num == 0)) {
      flg = false;
    } else {
      for (int i = 0; i < num; i++) {
        int a;
        int b;

        cin >> a >> b;
        if (a > b) {
          score_a[cnt] += a + b;
        } else if (b > a) {
          score_b[cnt] += a + b;
        } else {
          score_a[cnt] += a;
          score_b[cnt] += b;
        }
      }
      cnt++;
    }
  }
  for (int i = 0; i < cnt; i++) {
    cout << score_a[i] << " " << score_b[i] << endl;
  }

  // while (1);

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int num;
  int score_a = 0;
  int score_b = 0;
  int cnt = 0;

  cin >> num;
  while (num != 0) {
    for (int i = 0; i < num; i++) {
      int a;
      int b;

      cin >> a >> b;
      if (a > b) {
        score_a += a + b;
      } else if (b > a) {
        score_b += a + b;
      } else {
        score_a += a;
        score_b += b;
      }
    }
    cout << score_a << " " << score_b << endl;
    score_a = 0;
    score_b = 0;
    cnt++;
  }

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

#include <iostream>

int main() {
  int n, a, b, apt, bpt;
  while (std::cin >> n, n) {
    for (apt = bpt = 0; n; n--) {
      std::cin >> a >> b;
      if (a > b)
        apt += a + b;
      else if (b > a)
        bpt += a + b;
      else {
        apt += a;
        bpt += b;
      }
    }
    std::cout << apt << ' ' << bpt << std::endl;
  }
  return 0;
}

Error: WA

Fixed submission:

#include <algorithm>
#include <iostream>

int main() {
  int a, b, lcm, gcd;
  while (std::cin >> a >> b) {
    int _a = a, _b = b;
    while (1) {
      if (_b % _a == 0) {
        gcd = _a;
        break;
      }
      _a = _a % _b;
      std::swap(_a, _b);
    }
    lcm = a / gcd * b;
    std::cout << gcd << ' ' << lcm << std::endl;
  }
  return 0;
}
Problem p00423 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
int main() {
  int a, b, n;
  while (scanf("%d", &n), n) {
    int asum = 0, bsum = 0;
    for (int i = 0; i < n; i++) {
      scanf("%d %d", &a, &b);
      if (a > b) {
        asum += a + b;
      } else if (a < b) {
        bsum += a + b;
      } else {
        asum += a;
        bsum += b;
      }
    }
    printf("%d %d\\n", asum, bsum);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <cstdio>
int main() {
  int a, b, n;
  while (scanf("%d", &n) != 0) {
    int asum = 0, bsum = 0;
    for (int i = 0; i < n; i++) {
      scanf("%d %d", &a, &b);
      if (a > b) {
        asum += a + b;
      } else if (a < b) {
        bsum += a + b;
      } else {
        asum += a;
        bsum += b;
      }
    }
    printf("%d %d\\n", asum, bsum);
  }
  return 0;
}
Problem p00423 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
int main() {
  int a = 1, e = 0, f = 0, c, d;
  while (1) {
    cin >> a;
    if (a == 0) {
      break;
    }
    e = 0;
    f = 0;
    for (int b = 0; b < a; b++) {
      cin >> c;
      cin >> d;
      if (c > d) {
        e += c;
        e += d;
      } else if (d > c) {
        f += c;
        f += d;
      } else {
        e += c;
        f += d;
      }
    }
    cout << e << " " << f << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int a = 1, e = 0, f = 0, c, d;
  while (a != 0) {
    cin >> a;
    e = 0;
    f = 0;
    for (int b = 0; b < a, a != 0; b++) {
      cin >> c;
      cin >> d;
      if (c > d) {
        e += c;
        e += d;
      } else if (d > c) {
        f += c;
        f += d;
      } else {
        e += c;
        f += d;
      }
    }
    cout << e << " " << f << endl;
  }
  return 0;
}
Problem p00423 (C++) — buggy submission, verdict: Time Limit Exceeded

//============================================================================
// Name        : svdzva.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================
#include <iostream>
using namespace std;
int main() {
  while (true) {
    int n, play1 = 0, play2 = 0, card1[10000], card2[10000];
    cin >> n;
    if (n == 0)
      break;
    for (int i = 0; i < n; i++) {
      cin >> card1[i] >> card2[i];
      if (card1[i] > card2[i]) {
        play1 = play1 + card1[i] + card2[i];
      } else if (card1[i] < card2[i]) {
        play2 = play2 + card2[i] + card1[i];
      } else {
        play1 = play1 + card1[i];
        play2 = play2 + card2[i];
      }
    }
    cout << play1 << " " << play2 << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

//============================================================================
// Name        : svdzva.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================
#include <algorithm>
#include <iostream>
using namespace std;

int main() {
  int n, play1 = 0, play2 = 0, card1[10000], card2[10000];
  while (true) {
    cin >> n;
    for (int i = 0; i < n; i++) {
      cin >> card1[i] >> card2[i];
      if (card1[i] > card2[i]) {
        play1 = play1 + card1[i] + card2[i];
      } else if (card1[i] < card2[i]) {
        play2 = play2 + card2[i] + card1[i];
      } else {
        play1 = play1 + card1[i];
        play2 = play2 + card2[i];
      }
    }
  }
  cout << play1 << " " << play2 << endl;
  return 0;
}
Problem p00423 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
int n[10000000], s1, s2;
int main() {
  int p, a, b;
  while (true) {
    s1 = 0;
    s2 = 0;
    cin >> p;
    if (p == 0) {
      break;
    }
    for (int i = 0; i < p; i++) {
      cin >> a >> b;
      if (a > b) {
        s1 += a + b;
      } else if (b > a) {
        s2 += a + b;
      } else {
        s1 += a;
        s2 += b;
      }
    }
    cout << s1 << ' ' << s2 << endl;
  }
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int n[10000000], s1, s2;
int main() {
  int p, a, b;
  while (true) {
    s1 = 0;
    s2 = 0;
    cin >> p;
    for (int i = 0; i < p; i++) {
      cin >> a >> b;
      if (a > b) {
        s1 += a + b;
      } else if (b > a) {
        s2 += a + b;
      } else {
        s1 += a;
        s2 += b;
      }
    }
    cout << s1 << ' ' << s2 << endl;
  }
}
Problem p00423 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
int main() {
  int t;
  while (cin >> t && t > 0) {
    int p1 = 0, p2 = 0;
    while (t > 0) {
      int a = 0, b = 0;
      cin >> a >> b;
      if (a < 0 || a > 9 || a < 0 || a > 9) {
        continue;
      }
      if (a > b) {
        p1 += a + b;
      } else if (a < b) {
        p2 += a + b;
      } else {
        p1 += a;
        p2 += b;
      }
      t--;
    }
    cout << p1 << " " << p2 << endl;
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int t;
  while (cin >> t && t > 0) {
    int p1 = 0, p2 = 0;
    while (t > 0) {
      int a = 0, b = 0;
      cin >> a >> b;
      if (a >= 0 && a <= 9 && a >= 0 && a <= 9) {
        continue;
      }
      if (a > b) {
        p1 += a + b;
      } else if (a < b) {
        p2 += a + b;
      } else {
        p1 += a;
        p2 += b;
      }
      t--;
    }
    cout << p1 << " " << p2 << endl;
  }
  return 0;
}
Problem p00423 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
int main() {
  int n, a, b, A = 0, B = 0;
  while (1) {
    A = 0;
    B = 0;
    cin >> n;
    if (n == 0) {
      break;
    }
    for (int i = 0; i < n; i++) {
      cin >> a >> b;
      if (a > b) {
        A = A + a + b;
      } else if (a < b) {
        B = B + a + b;
      } else if (a == b) {
        A = A + a;
        B = B + b;
      }
    }
    cout << A << " " << B << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  while (1) {
    int n, a[1000] = {0}, b[1000] = {0}, A = 0, B = 0;
    cin >> n;
    if (n == 0) {
      break;
    }
    for (int i = 0; i < n; i++) {
      cin >> a[i] >> b[i];
      if (a[i] > b[i]) {
        A = A + a[i] + b[i];
      } else if (a[i] < b[i]) {
        B = B + a[i] + b[i];
      } else if (a[i] == b[i]) {
        A = A + a[i];
        B = B + b[i];
      }
    }
    cout << A << " " << B << endl;
  }
  return 0;
}
Problem p00423 (C++) — buggy submission, verdict: Time Limit Exceeded


#include <iostream>
using namespace std;

int main() {
  int a, b;
  int n;
  while (1) {
    int aten = 0, bten = 0;
    cin >> n;
    if (n == 0) {
      break;
    }
    for (int i = 0; i < n; i++) {
      cin >> a >> b;
      if (a > b) {
        aten = aten + a + b;
      } else if (a == b) {
        aten = aten + a;
        bten = bten + a;
      } else {
        bten = bten + b + a;
      }
    }
    cout << aten << " " << bten << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:


#include <iostream>
using namespace std;

int main() {
  int aten = 0, bten = 0, a, b;
  int n;
  cin >> n;
  while (true) {
    if (n == 0) {
      break;
    }
    cin >> a >> b;
    if (a > b) {
      aten = aten + a + b;
    } else if (a == b) {
      aten = aten + a;
      bten = bten + a;
    } else {
      bten = bten + b + a;
    }
  }
  cout << aten << " " << bten << endl;
  return 0;
}
Problem p00423 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

int main() {
  int n, a, b, at, bt;

loop:
  scanf("%d\\n", &n); // 各人のカード枚数
  if (n == 0)
    goto end_scope;
  at = 0;
  bt = 0;

labl_testloop:
  scanf("%d %d\\n", &a, &b);
  if (a > b)
    at += a + b;
  else if (a == b) {
    at += a;
    bt += b;
  } else
    bt += a + b;
  n--;
  if (n > 0)
    goto labl_testloop;

  printf("%d %d\\n", at, bt);
  goto loop;
end_scope:
  return 0;
}

Error: -11

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int n, a, b, at, bt;

loop:
  scanf("%d\\n", &n); // 各人のカード枚数
  if (n == 0)
    goto end_scope;
  at = 0;
  bt = 0;

labl_testloop:
  scanf("%d %d\\n", a, b);
  if (a > b)
    at += a + b;
  else if (a == b) {
    at += a;
    bt += b;
  } else
    bt += a + b;
  n--;
  if (n > 0)
    goto labl_testloop;

  printf("%d %d\\n", at, bt);
  goto loop;
end_scope:
  return 0;
}
Problem p00423 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>

int n;

int main() {
  while (1) {
    int A, B, Aanswer = 0, Banswer = 0;
    scanf("%d", &n);
    if (n == 0)
      return 0;
    for (int i = 0; i < n; i++) {
      scanf("%d %d", &A, &B);
      if (A > B)
        Aanswer += A + B;
      else if (A < B)
        Banswer += A + B;
      else {
        Aanswer += A;
        Banswer += B;
      }
    }
    printf("%d %d\\n", Aanswer, Banswer);
  }
  return 0;
}

Error: -11

Fixed submission:

#include <cstdio>

int n;

int main() {
  int A, B, Aanswer = 0, Banswer = 0;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d %d", A, B);
    if (A > B)
      Aanswer += A + B;
    else if (A < B)
      Banswer += A + B;
    else {
      Aanswer += A;
      Banswer += B;
    }
  }
  printf("%d %d\\n", Aanswer, Banswer);
  return 0;
}
Problem p00423 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#define N 10000
using namespace std;
int main() {
  int a[N], b[N], n, scoreA, scoreB;
  while (cin >> n, n != 0) {

    scoreA = 0;
    scoreB = 0;
    for (int i = 0; i < n; i++) {
      cin >> a[i] >> b[i];
    }
    for (int i = 0; i < n; i++) {
      if (a[i] > b[i]) {
        scoreA += a[i] + b[i];
      } else if (a[i] < b[i]) {
        scoreB += a[i] + b[i];
      } else if (a[i] == b[i]) {
        scoreA = scoreA + a[i];
        scoreB += b[i];
      }
    }

    cout << scoreA << " " << scoreB << endl;
  }
}

Error: TLE

Fixed submission:

#include <iostream>
#include <vector>
int main() {
  int i = 0;
  std::cin >> i;
  std::vector<int> ha, hb;
  while (i != 0) {
    int A = 0, B = 0;
    std::vector<int> a(10000), b(10000);
    for (int j = 0; j < i; ++j) {
      std::cin >> a[j] >> b[j];
    }
    for (int j = 0; j < i; ++j) {
      if (a[j] > b[j]) {
        A += (a[j] + b[j]);
      } else if (a[j] < b[j]) {
        B += (a[j] + b[j]);
      } else {
        A += a[j];
        B += b[j];
      }
    }
    ha.push_back(A);
    hb.push_back(B);
  }
  for (int j = 0; j < i; ++j) {
    std::cout << ha[j] << " " << hb[j] << std::endl;
  }
  return 0;
}
Problem p00423 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <stdio.h>

int n, A[11234], B[11234];
int ans[2];

int main(void) {
  while (true) {
    ans[0] = ans[1] = 0;
    scanf("%d", &n);
    if (n == 0) {
      break;
    }
    for (int i = 0; i < n; ++i) {
      scanf("%d%d", &A[i], &B[i]);
    }

    for (int i = 0; i < n; ++i) {
      if (A[i] > B[i]) {
        ans[0] += A[i] + B[i];
      } else if (A[i] < B[i]) {
        ans[1] += A[i] + B[i];
      } else {
        ans[0] += A[i], ans[1] += B[i];
      }
    }

    printf("%d %d\\n", ans[0], ans[1]);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <stdio.h>

int n, A[11234], B[11234];
int ans[2];

int main(void) {
  while (true) {
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
      scanf("%d%d", &A[i], &B[i]);
    }

    for (int i = 0; i < n; ++i) {
      if (A[i] > B[i]) {
        ans[0] += A[i] + B[i];
      } else if (A[i] < B[i]) {
        ans[1] += A[i] + B[i];
      } else {
        ans[0] += A[i], ans[1] += B[i];
      }
    }

    printf("%d %d\\n", ans[0], ans[1]);
  }
  return 0;
}
Problem p00423 (C++) — buggy submission, verdict: Runtime Error

#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include "bits/stdc++.h"
#include <list>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define REP(i, a, b) for (i = a; i < b; ++i)
#define rep(i, n) REP(i, 0, n)
#define ll long long
#define ull unsigned ll
typedef long double ld;
#define SQR(X) ((X) * (X))
#define CUBE(X) ((X) * (X) * (X))

// #define int ll

using namespace std;

bool test = 0;

/* ?????????????????¬??¨ */

int main() {
  int i, j, k, l;
  int n;
  while (scanf("%d", &n) != EOF) {
    if (n == 0)
      break;
    int score[2] = {0};
    for (i = 0; i < n; i++) {
      int num[2];
      cin >> num[0] >> num[1];
      auto sum = num[0] + num[1];
      if (num[0] > num[1])
        score[0] += sum;
      else if (num[0] < num[1])
        score[1] += sum;
      else {
        for (j = 0; j < 2; j++)
          score[j] += num[j];
      }
    }
    printf("%d %d\\n", score[0], score[1]);
  }
  return 0;
}

Error: WA

Fixed submission:

#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include "bits/stdc++.h"
#include <list>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define REP(i, a, b) for (i = a; i < b; ++i)
#define rep(i, n) REP(i, 0, n)
#define ll long long
#define ull unsigned ll
typedef long double ld;
#define SQR(X) ((X) * (X))
#define CUBE(X) ((X) * (X) * (X))

// #define int ll

using namespace std;

bool test = 0;

/* ?????????????????¬??¨ */

int main() {
  int i, j, k, l;
  int n;
  while (scanf("%d", &n) != EOF) {
    if (n == 0)
      break;
    int score[2] = {0};
    for (i = 0; i < n; i++) {
      int num[2];
      cin >> num[0] >> num[1];
      auto sum = num[0] + num[1];
      if (num[0] > num[1])
        score[0] += sum;
      else if (num[0] < num[1])
        score[1] += sum;
      else {
        for (j = 0; j < 2; j++)
          score[i] += num[i];
      }
    }
    printf("%d %d\\n", score[0], score[1]);
  }
  return 0;
}
Problem p00423 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
int main() {
  int maisuu, a[15000], b[15000];
  long long int a_p = 0, b_p = 0;
  int anser[2][10];
  int hasi;
  for (int i = 0; i < 5; i++) {
    cin >> maisuu;
    if (maisuu == 0) {
      break;
    }
    for (int i2 = 0; i2 < maisuu; i2++) {
      cin >> a[i2];
      cin >> b[i2];
    }
    for (int i2 = 0; i2 < maisuu; i2++) {
      if (a[i2] < b[i2]) {
        b_p += a[i2] + b[i2];
      } else if (a[i2] > b[i2]) {
        a_p += a[i2] + b[i2];
      } else if (a[i2] == b[i2]) {
        a_p += a[i2];
        b_p += b[i2];
      }
    }
    anser[0][i] = a_p;
    anser[1][i] = b_p;
    maisuu = 0;
    a_p = 0;
    b_p = 0;
    hasi = i;
  }
  for (int i = 0; i <= hasi; i++) {
    cout << anser[0][i] << " " << anser[1][i] << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int maisuu, a[10], b[10];
  long long int a_p = 0, b_p = 0;
  int anser[2][10];
  int hasi;
  for (int i = 0; i < 5; i++) {
    cin >> maisuu;
    if (maisuu == 0) {
      break;
    }
    for (int i2 = 0; i2 < maisuu; i2++) {
      cin >> a[i2];
      cin >> b[i2];
    }
    for (int i2 = 0; i2 < maisuu; i2++) {
      if (a[i2] < b[i2]) {
        b_p += a[i2] + b[i2];
      } else if (a[i2] > b[i2]) {
        a_p += a[i2] + b[i2];
      } else if (a[i2] == b[i2]) {
        a_p += a[i2];
        b_p += b[i2];
      }
    }
    anser[0][i] = a_p;
    anser[1][i] = b_p;
    maisuu = 0;
    a_p = 0;
    b_p = 0;
    hasi = i;
  }
  for (int i = 0; i <= hasi; i++) {
    cout << anser[0][i] << " " << anser[1][i] << endl;
  }
  return 0;
}
Problem p00423 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <queue>
#include <sstream>
#include <stdlib.h>
#include <string>
#include <time.h>
#include <vector>
using namespace std;
int main(void) {
  int n;
  while (cin >> n) {
    if (n == 0)
      break;
    int a = 0;
    int b = 0;
    for (int i = 0; i < n; i++) {
      int r, l;
      cin >> l >> r;
      if (r < l) {
        a += r + l;
      } else if (r > l) {
        b += r + l;
      } else if (r == l) {
        a += l;
        b += r;
      }
    }
    cout << a << " " << b << endl;
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <queue>
#include <sstream>
#include <stdlib.h>
#include <string>
#include <time.h>
#include <vector>
using namespace std;
int main(void) {
  int n;
  while (cin >> n, !0) {
    int a = 0;
    int b = 0;
    for (int i = 0; i < n; i++) {
      int r, l;
      cin >> l >> r;
      if (r < l) {
        a += r + l;
      } else if (r > l) {
        b += r + l;
      } else if (r == l) {
        a += l;
        b += r;
      }
    }
    cout << a << " " << b << endl;
  }
}
Problem p00423 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>

int main() {
  int n = 1;

  while (n) {
    scanf("%d", &n);
    if (n == 0)
      break;
    int ac, bc;
    ac = bc = 0;
    for (int i = 0; i < n; i++) {
      int a, b;
      scanf("%d%d", &a, &b);
      if (a > b) {
        ac += a + b;
      } else if (a == b) {
        ac += a, bc += b;
      } else {
        bc += a + b;
      }
    }
    printf("%d %d\\n", ac, bc);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <cstdio>

int main() {
  int n;
  scanf("%d", &n);
  while (n) {
    int ac, bc;
    ac = bc = 0;
    for (int i = 0; i < n; i++) {
      int a, b;
      scanf("%d%d", &a, &b);
      if (a > b)
        ac += a + b;
      else if (a == b)
        ac += a, bc += b;
      else
        bc += a + b;
    }
    printf("%d %d\\n", ac, bc);
  }
  return 0;
}
Problem p00423 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
int main() {
  int n, a, b, ap, bp, i;
  while (1) {
    cin >> n;
    if (n == 0)
      break;
    ap = bp = 0;
    for (i = 0; i < n; i++) {
      cin >> a >> b;
      if (a > b)
        ap += a + b;
      else if (b > a)
        bp += a + b;
      else
        ap += a, bp += b;
    }
    cout << ap << ' ' << bp << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int n, a, b, ap, bp, i;
  while (1) {
    cin >> n;
    ap = bp = 0;
    for (i = 0; i < n; i++) {
      cin >> a >> b;
      if (a > b)
        ap += a + b;
      else if (b > a)
        bp += a + b;
      else
        ap += a, bp += b;
    }
    cout << ap << ' ' << bp << endl;
  }
  return 0;
}
Problem p00423 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
int main() {
  int n = 1;
  int a, b, pa, pb;
  for (; n != 0;) {
    cin >> n;
    if (n == 0) {
      break;
    }
    pa = 0;
    pb = 0;
    for (int i = 0; i < n; i++) {
      a = 0;
      b = 0;
      cin >> a;
      cin >> b;
      if (a > b) {
        pa += a + b;
      }
      if (a == b) {
        pa += a;
        pb += b;
      }
      if (a < b) {
        pb += a + b;
      }
    }
    cout << pa << " " << pb << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int n, a, b, pa, pb;
  cin >> n;
  for (; n != 0;) {
    pa = 0;
    pb = 0;
    for (int i = 0; i < n; i++) {
      cin >> a;
      cin >> b;
      if (a == b) {
        pa += a;
        pb += a;
      }
      if (a > b) {
        pa += a + b;
      }
      if (a < b) {
        pb += a + b;
      }
    }
    cout << pa << " " << pb << endl;
  }
  return 0;
}