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

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

vector<int> primes(1e6 + 1);
vector<int> sums(1e6 + 1);
void hurui(const int amax) {
  static bool flag = false;
  if (flag)
    return;
  vector<int> sos;
  sos = vector<int>(amax + 1, true);
  sos[0] = false;
  sos[1] = false;
  for (int i = 2; i <= amax; ++i) {
    if (sos[i]) {
      for (int j = 2 * i; j <= amax; j += i)
        sos[j] = false;
    }
  }
  for (int i = 0; i <= amax; ++i) {
    if (sos[i]) {
      primes[i] = true;
    }
  }
  flag = true;
}

int main() {
  hurui(999983);
  for (int i = 0; i < 1e6; ++i) {
    sums[i + 1] = sums[i] + primes[i + 1];
  }
  while (1) {
    int N;
    cin >> N;
    if (!N)
      break;
    long long int prize = 0;
    while (N--) {
      long long int p, m;
      cin >> p >> m;
      int amax = min(999983ll, p + m);
      int amin = max(0ll, p - m - 1);
      const int aprize = sums[amax] - sums[amin];
      prize += aprize - 1;
    }
    cout << max(0ll, prize) << endl;
  }
  return 0;
}

Error: -11

Fixed submission:

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

vector<int> primes(1e6);
vector<int> sums(1e6 + 1);
void hurui(const int amax) {
  static bool flag = false;
  if (flag)
    return;
  vector<int> sos;
  sos = vector<int>(amax + 1, true);
  sos[0] = false;
  sos[1] = false;
  for (int i = 2; i <= amax; ++i) {
    if (sos[i]) {
      for (int j = 2 * i; j <= amax; j += i)
        sos[j] = false;
    }
  }
  for (int i = 0; i <= amax; ++i) {
    if (sos[i]) {
      primes[i] = true;
    }
  }
  flag = true;
}

int main() {
  hurui(999983);
  for (int i = 0; i < 1e7; ++i) {
    sums[i + 1] = sums[i] + primes[i + 1];
  }
  while (1) {
    int N;
    cin >> N;
    if (!N)
      break;
    long long int prize = 0;
    while (N--) {
      long long int p, m;
      cin >> p >> m;
      int amax = min(999983ll, p + m);
      int amin = max(0ll, p - m - 1);
      const int aprize = sums[amax] - sums[amin];
      prize += aprize - 1;
    }
    cout << max(0ll, prize) << endl;
  }
  return 0;
}
Problem p00165 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
int a[1000000][2];
int main() {
  int i, j, k, n, x, s;
  k = 0;
  for (i = 2; i < 1000000; i++) {
    if (!a[i][0]) {
      k++;
      for (j = 2; i * j < 1000000; j++) {
        a[i * j][0] = 1;
      }
    }
    a[i][1] = k;
  }
  for (;;) {
    cin >> n;
    if (n == 0)
      break;
    s = 0;
    while (n--) {
      cin >> i >> j;
      k = (i + j) >= 1000000 ? 999999 : i + j;
      x = a[k][1];
      k = (i - j - 1) < 0 ? 0 : i - j - 1;
      x -= a[k][1];
      if (x > 0)
        s += x - 1;
      else
        s--;
    }
    cout << s << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <set>
using namespace std;
bool a[1000000];
int main() {
  int i, j, k, n, x, s;
  set<int> se;
  set<int>::iterator it;
  for (i = 2; i < 1000000; i++) {
    if (!a[i]) {
      se.insert(i);
      for (j = 2; i * j < 1000000; j++) {
        a[i * j] = true;
      }
    }
  }
  for (;;) {
    cin >> n;
    if (n == 0)
      break;
    s = 0;
    while (n--) {
      cin >> i >> j;
      x = 0;
      it = se.lower_bound(i - j);
      while ((*it) <= i + j && it != se.end()) {
        x++;
        it++;
      }
      if (x > 0)
        s += x - 1;
      else
        s--;
    }
    cout << s << endl;
  }
  return 0;
}
Problem p00165 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;

const int MAX = 999984;
vector<int> v;
bool prime[MAX];

void sieve() {
  fill(prime, prime + MAX, true);
  prime[0] = prime[1] = false;

  for (int i = 0; i < MAX; i++) {
    if (!prime[i])
      continue;
    v.push_back(i);
    for (int j = i + i; j < MAX; j += i) {
      prime[j] = false;
    }
  }
}

int main() {
  sieve();
  int n;
  while (cin >> n, n) {
    int ans = 0;
    for (int i = 0; i < n; i++) {
      int a, b;
      cin >> a >> b;
      int p = lower_bound(v.begin(), v.end(), a + b + 1) -
              lower_bound(v.begin(), v.end(), a - b);
      ans += p;
    }
    ans -= n;
    cout << ans << endl;
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

const int MAX = 1000003;
bool prime[MAX];

void sieve() {
  fill(prime, prime + MAX, true);
  prime[0] = prime[1] = false;

  for (int i = 0; i < MAX; i++) {
    if (!prime[i])
      continue;
    for (int j = i + i; j < MAX; j += i) {
      prime[j] = false;
    }
  }
}

int main() {
  sieve();
  int n;
  while (cin >> n, n) {
    int ans = 0;
    for (int i = 0; i < n; i++) {
      int a, b;
      cin >> a >> b;
      for (int j = max(2, a - b); j <= min(a + b, 999983); j++) {
        if (prime[j])
          ans++;
      }
      ans--;
    }
    cout << ans << endl;
  }
}
Problem p00165 (C++) — buggy submission, verdict: Time Limit Exceeded

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

const long N = 1000000;

int main() {
  bool prime[N + 1];

  for (long i = 0; i <= N; ++i)
    prime[i] = true;
  prime[0] = prime[1] = false;
  for (long i = 2; i <= N; ++i) {
    if (prime[i])
      for (long j = 2; i * j <= N; ++j)
        prime[i * j] = false;
  }

  while (1) {
    int n;
    scanf(" %d", &n);
    if (n == 0)
      break;

    long ans = 0;
    for (int i = 0; i < n; ++i) {
      long p, m;
      scanf(" %ld %ld", &p, &m);

      long x = 0;
      int y = 0;
      if ((p + m) % 2 == 0)
        y = 1;

      if (p - m <= 2)
        ++x;

      for (long j = p - m + y; j <= p + m - y; j += 2) {
        // printf("j=%ld\\n", j);
        if (j < 2)
          continue;
        if (j > N)
          break;

        if (prime[j])
          x++;
      }

      ans += x - 1;
      // printf("%ld\\n", ans);
    }

    printf("%ld\\n", ans);
  }
}

Error: TLE

Fixed submission:

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

const long N = 1000000;

int main() {
  bool prime[N + 1];

  for (long i = 0; i <= N; ++i)
    prime[i] = true;
  prime[0] = prime[1] = false;
  for (long i = 2; i <= N; ++i) {
    if (prime[i])
      for (long j = 2; i * j <= N; ++j)
        prime[i * j] = false;
  }

  while (1) {
    int n;
    scanf(" %d", &n);
    if (n == 0)
      break;

    long ans = 0;
    for (int i = 0; i < n; ++i) {
      long p, m;
      scanf(" %ld %ld", &p, &m);

      long x = 0;
      for (long j = p - m; j <= p + m; ++j) {
        if (j < 2)
          continue;
        if (j > N)
          break;

        if (prime[j])
          x++;
      }

      ans += x - 1;
    }

    printf("%ld\\n", ans);
  }
}
Problem p00165 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
#include <iostream>
#include <vector>
using namespace std;
bool prime[1000001];
vector<int> ppp;

void p_init() {
  prime[0] = prime[1] = true;
  for (int i = 0; i <= 1000; i++) {
    if (!prime[i])
      for (int j = i << 1; j <= 1000000; j += i) {
        prime[j] = true;
      }
  }

  for (int i = 0; i <= 1000000; i++) {
    if (!prime[i]) {
      ppp.push_back(i);
    }
  }
}

int main() {
  p_init();
  int x, n, p, m;
  int ret;
  while (cin >> n && n) {
    ret = 0;
    for (int i = 0; i < n; i++) {
      scanf("%d %d", &p, &m);
      int mi = p < m ? 0 : p - m;
      int mx = p + m > 1000000 ? 1000000 : p + m;
      x = 0;
      for (int i = 0; i < ppp.size(); i++) {
        if (ppp[i] > mx)
          break;
        if (ppp[i] >= mi) {
          ret++;
        }
      }
      if (x) {
        ret += x - 1;
      } else {
        ret--;
      }
    }
    printf("%d\\n", ret < 0 ? 0 : ret);
  }
}

Error: TLE

Fixed submission:

#include <cstdio>
#include <iostream>
using namespace std;
bool prime[1000001];

void p_init() {
  prime[0] = prime[1] = true;
  for (int i = 0; i <= 1000; i++) {
    if (!prime[i])
      for (int j = i << 1; j <= 1000000; j += i) {
        prime[j] = true;
      }
  }
}

int main() {
  p_init();
  int x, n, p, m;
  int ret;
  while (cin >> n && n) {
    ret = 0;
    for (int i = 0; i < n; i++) {
      scanf("%d %d", &p, &m);
      x = 0;
      for (int o = p < m ? 0 : p - m; o <= (p + m > 1000000 ? 1000000 : p + m);
           o++) {
        if (!prime[o]) {
          x++;
        }
      }
      if (x) {
        ret += x - 1;
      } else {
        ret--;
      }
    }
    printf("%d\\n", (ret < 0 ? 0 : ret));
  }
}
Problem p00165 (C++) — buggy submission, verdict: Time Limit Exceeded

// 2011/10/16 Tazoe

#include <iostream>
using namespace std;

void prime(bool prm[], int n) {
  if (n >= 1)
    prm[0] = false;
  if (n >= 2)
    prm[1] = false;

  for (int i = 2; i < n; i++)
    prm[i] = true;

  for (int i = 2; i < n; i++)
    if (prm[i])
      for (int j = i + i; j < n; j += i)
        prm[j] = false;
}

int main() {
  bool prm[1000001];
  prime(prm, 1000001);

  int prm2[1000001];
  int cnt = 0;
  for (int i = 0; i <= 1000000; i++) {
    if (prm[i])
      cnt++;
    prm2[i] = cnt;
  }

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

    int sum = 0;
    for (int i = 0; i < n; i++) {
      int p, m;
      cin >> p >> m;

      int bgn;
      if (p - m - 1 < 0)
        bgn = 0;
      else
        bgn = p - m - 1;

      int end;
      if (p + m > 1000000)
        end = 1000000;
      else
        end = p + m;

      sum += (prm2[end] - prm2[bgn]);

      sum--;

      //			cout << sum << endl;
    }

    cout << sum << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

// 2011/10/16 Tazoe

#include <iostream>
using namespace std;

void prime(bool prm[], int n) {
  if (n >= 1)
    prm[0] = false;
  if (n >= 2)
    prm[1] = false;

  for (int i = 2; i < n; i++)
    prm[i] = true;

  for (int i = 2; i < n; i++)
    if (prm[i])
      for (int j = i + i; j < n; j += i)
        prm[j] = false;
}

int main() {
  bool prm[1000001];
  prime(prm, 1000001);

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

    int sum = 0;
    for (int i = 0; i < n; i++) {
      int p, m;
      cin >> p >> m;

      int bgn;
      if (p - m < 0)
        bgn = 0;
      else
        bgn = p - m;

      int end;
      if (p + m > 1000000)
        end = 1000000;
      else
        end = p + m;

      for (int j = bgn; j <= end; j++)
        if (prm[j])
          sum++;

      sum--;

      //			cout << sum << endl;
    }

    cout << sum << endl;
  }

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

#include <algorithm>
#include <iostream>

#define mx 1000001

using namespace std;

bool prm[mx];
int cnt[mx];

void mkPrm() {
  fill(prm, prm + mx, true);
  prm[0] = prm[1] = false;

  for (int i = 2; i < mx; ++i)
    if (prm[i])
      for (int j = i + i; j < mx; j += i)
        prm[j] = false;

  int t = 0;
  for (int i = 0; i < mx; ++i) {
    if (prm[i])
      ++t;
    cnt[i] = t;
  }

  return;
}

int main() {
  int n, s, p, m, c;
  mkPrm();

  while (cin >> n && n) {
    s = 0;
    while (n--) {
      cin >> p >> m;
      c = ((p + m >= mx) ? cnt[mx - 1] : cnt[p + m]);
      c -= (p - m < 1) ? cnt[0] : cnt[p - m - 1];
      s--;
      if (c > 0)
        s += c;
    }
    cout << ((s < 0) ? 0 : s) << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <set>
#include <vector>

using namespace std;

int main() {
  int n, m, p, s, t;
  bool a[1000000];
  fill(a, a + 1000000, true);
  a[0] = a[1] = false;
  vector<int> vec;

  for (int i = 2; i < 1000000; i++) {
    if (a[i]) {
      vec.push_back(i);
      for (int j = i + i; j < 1000000; j += i) {
        a[j] = false;
      }
    }
  }

  while (cin >> n && n) {
    set<int> stt;
    while (n--) {
      cin >> p >> m;
      s = p - m;
      if (s < 0) {
        s = 0;
      }
      t = p + m;
      if (t > 999983) {
        t = 999983;
      }

      for (int i = 0; i < vec.size() && vec[i] <= t; i += 1) {
        if (s <= vec[i] && vec[i] <= t) {
          stt.insert(vec[i]);
        }
      }
    }

    cout << ((stt.size() > 1) ? (stt.size() - 1) : 0) << endl;
  }

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

#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstdio>
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e9 + 7;
const ll MOD = 1e9 + 7;

#define FOR(i, a, b) for (long long i = (a); i < (b); i++)
#define REP(i, N) for (long long i = 0; i < (N); i++)
#define ALL(s) (s).begin(), (s).end()
#define EQ(a, b) (abs((a) - (b)) < EPS)
#define EQV(a, b) (EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()))
#define fi first
#define se second

int n;

bool is_prime[2000100];
int cnt[2000100];

int main() {
  fill(is_prime, is_prime + 1000000, 1);
  is_prime[0] = 0;
  is_prime[1] = 0;
  for (int i = 2; i <= (int)1e6; i++) {
    if (is_prime[i]) {
      for (int j = i * 2; j <= (int)1e6; j += i) {
        is_prime[j] = 0;
      }
    }
  }
  FOR(i, 1, 2000000 + 10) {
    if (is_prime[i])
      cnt[i]++;
    cnt[i] += cnt[i - 1];
  }
  // REP(i, 10){
  //	cout << i << " " << cnt[i] << endl;
  // }
  // for (int i = 999983 - 20; i <= 999983 + 20; i++){
  //	cout << i << " " << cnt[i] << endl;
  // }
  while (cin >> n && n) {
    int ans = 0;
    REP(i, n) {
      int p, m;
      cin >> p >> m;
      int x = cnt[p + m];
      if (p - m - 1 >= 0)
        x -= cnt[p - m - 1];
      ans += (x - 1);
    }
    cout << ans << endl;
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define FOR(i, a, b) for (long long i = (a); i < (b); i++)
#define REP(i, N) for (long long i = 0; i < (N); i++)
#define ALL(s) (s).begin(), (s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 10e15 + 9
#define MOD 1000000007
#define EPS 1e-10
#define MAX_N 100100
#define MAX_M 100100

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;

#define MP 999983

int n;
int p, m;

bool is_prime[MP + 100];

int main() {
  fill(is_prime, is_prime + MP + 100, 1);
  is_prime[0] = 0;
  is_prime[1] = 0;
  for (int i = 2; i <= MP; i++) {
    if (is_prime[i]) {
      for (int j = i * 2; j <= MP; j += i) {

        is_prime[j] = 0;
      }
    }
  }
  while (cin >> n && n) {
    int ans = 0;
    REP(i, n) {
      cin >> p >> m;
      for (int i = max(p - m, 2); i <= min(p + m, MP); i++) {
        if (is_prime[i]) {
          ans++;
        }
      }
    }
    cout << ans - n << endl;
  }
}
Problem p00165 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

#define MP 999983

int main() {
  vector<int> data(MP + 1, 0);
  data[0] = data[1] = 1;
  vector<int> data2;
  for (int i = 2; i * i <= MP; i++) {
    if (data[i] == 0) {
      for (int j = 2; i * j <= MP; j++) {
        data[i * j] = 1;
      }
    }
  }
  for (int i = 0; i <= MP; i++) {
    if (data[i] == 0) {
      data2.push_back(i);
    }
  }
  int n;
  while (cin >> n) {
    if (n == 0) {
      break;
    }
    int p, m;
    int counter2 = 0;
    for (int i = 0; i < n; i++) {
      cin >> p >> m;
      int ma, mi;
      ma = min(p + m, MP);
      mi = max(p - m, 0);
      vector<int>::iterator ite = lower_bound(data2.begin(), data2.end(), mi);
      vector<int>::iterator ite2 = upper_bound(data2.begin(), data2.end(), ma);
      // cout << ite2-ite << endl;
      counter2 += ite2 - ite - 1;
    }
    cout << counter2 << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <vector>

using namespace std;

#define MP 999983

int main() {
  vector<int> data(MP + 1, 0);
  data[0] = data[1] = 1;
  for (int i = 2; i * i <= MP; i++) {
    if (data[i] == 0) {
      for (int j = 2; i * j <= MP; j++) {
        data[i * j] = 1;
      }
    }
  }
  int n;
  while (cin >> n) {
    if (n == 0) {
      break;
    }
    int p, m;
    int counter2 = 0;
    // vector<int> data2(MP+1, 0);
    for (int i = 0; i < n; i++) {
      cin >> p >> m;
      int ma, mi;
      ma = min(p + m, MP);
      mi = max(p - m, 0);
      int counter = 0;
      for (int j = mi; j <= ma; j++) {
        if (data[j] == 0) {
          counter++;
        }
      }
      counter2 += counter - 1;
      // data2[m] += counter;
    }
    /*for (int i = 0; i <= MP; i++) {
            if (data2[i] > 0) {
                    cout << data2[i] << endl;
                    counter2 += data2[i]-1;
            }
    }*/
    cout << counter2 << endl;
  }
  return 0;
}
Problem p00165 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;

int const MP = 999983;

bool is_prime[MP + 1];
int sum_prime[MP + 1];

void Sieve() {

  fill(is_prime, is_prime + MP + 1, true);
  is_prime[0] = is_prime[1] = false;

  for (int i = 2; (long long)i * i <= MP; i++) {
    if (is_prime[i]) {
      for (long long j = i * i; j <= MP; j += i) {
        is_prime[j] = false;
      }
    }
  }

  for (int i = 0; i < MP + 1; i++) {
    sum_prime[i + 1] += sum_prime[i] + is_prime[i + 1];
  }
}

int main() {

  Sieve();

  int N;
  while (cin >> N && N) {
    int X = 0;
    for (int i = 0; i < N; i++) {
      int p, m;
      cin >> p >> m;
      int L = max(p - m, 1), R = min(p + m, MP);
      int cnt = sum_prime[R] - sum_prime[L - 1] - 1;
      X += cnt;
    }
    cout << X << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:


#include <bits/stdc++.h>

using namespace std;

#define MP (999983)

int memo[MP + 2];
bool isPrime(int x) {
  if (x < 2)
    return 0;
  for (int i = 2; i * i <= x; i++) {
    if (x % i == 0)
      return memo[x] = 0;
  }

  return memo[x] = 1;
}

int main() {

  memset(memo, -1, sizeof(memo));

  int N;
  while (cin >> N && N) {
    int X = 0;
    for (int i = 0; i < N; i++) {
      int p, m;
      cin >> p >> m;
      int L = max(p - m, 0), R = min(p + m, MP);
      int cnt = 0;
      for (int i = L; i <= R; i++)
        cnt += isPrime(i);
      // if(cnt == 0) cnt --;
      cnt--;
      X += cnt;
    }
    cout << X << endl;
  }

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

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) REP((i), 0, (n))
#define RREP(i, a, b) for (int i = (int)(a); i >= (int)(b); i--)
#define rrep(i, n) RREP(i, n, 0)
#define each(it, X)                                                            \\
  for (__typeof((X).begin()) it = (X).begin(); it != (X).end(); it++)
#define all(v) ((v).begin(), (v).end())
#define fi first
#define se second
#define pb push_back
typedef pair<int, int> pr;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef set<int> si;
const int INF = 1070000000ll;
const int mod = 1000000007ll;
const double EPS = 1e-9;
const double PI = 3.14159265;
double getS(int x) {
  int d = 360;
  double S = 0;
  rep(i, x - 1) {
    int z;
    cin >> z;
    d -= z;
    S += fabs(sin(1.0 * z / 180 * PI));
  }
  S += fabs(sin(1.0 * d / 180 * PI));
  return S;
}
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  double S[2];

  int x;
  while (cin >> x, x) {
    S[0] = getS(x);
    cin >> x;
    S[1] = getS(x);
    if (fabs(S[0] - S[1]) < EPS)
      cout << 0 << endl;
    else if (S[0] > S[1])
      cout << 1 << endl;
    else
      cout << 2 << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) REP((i), 0, (n))
#define RREP(i, a, b) for (int i = (int)(a); i >= (int)(b); i--)
#define rrep(i, n) RREP(i, n, 0)
#define each(it, X)                                                            \\
  for (__typeof((X).begin()) it = (X).begin(); it != (X).end(); it++)
#define all(v) ((v).begin(), (v).end())
#define fi first
#define se second
#define pb push_back
typedef pair<int, int> pr;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef set<int> si;
const int INF = 1070000000ll;
const int mod = 1000000007ll;
const double EPS = 1e-9;
const double PI = 3.14159265;
double getS(int x) {
  int d = 360;
  double S = 0;
  rep(i, x - 1) {
    int z;
    cin >> z;
    d -= z;
    S += fabs(sin(1.0 * z / 180 * PI));
  }
  S += fabs(sin(1.0 * d / 180 * PI));
  return S;
}
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  double S[2];

  int x;
  while (cin >> x, x) {
    S[0] = getS(x);
    scanf("%d", &x);
    S[1] = getS(x);
    if (fabs(S[0] - S[1]) < EPS)
      cout << 0 << endl;
    else if (S[0] > S[1])
      cout << 1 << endl;
    else
      cout << 2 << endl;
  }
  return 0;
}
Problem p00166 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <iostream>
using namespace std;
#define PI 3.141592653589793238462643L
int K[100000];
long double SIN(long double b) { return sinl(b * PI / 180.0L); }
int main() {
  int N, cnt = 0;
  long double a, sum, s[2], V;
  while (true) {
    for (int i = 0; i < 2; i++) {
      cin >> N;
      V = 0.0L;
      sum = 0.0L;
      if (N == 0) {
        goto E;
      }
      for (int i = 0; i < N - 1; i++) {
        cin >> a;
        sum += SIN(a);
        V += a;
      }
      sum += SIN(360.0L - V);
      s[i] = sum;
    }
    if (fabs(s[0] - s[1]) < 1e-9) {
      cout << '0' << endl;
    } else if (s[0] > s[1]) {
      cout << '1' << endl;
    } else if (s[0] < s[1]) {
      cout << '2' << endl;
    }
  }
E:;
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
using namespace std;
#define PI 3.141592653589793238462643L
int K[100000];
long double SIN(long double b) { return sinl(b * PI / 180.0L); }
int main() {
  int N, cnt = 0;
  long double a, sum, s[2], V;
  while (true) {
    for (int i = 0; i < 2; i++) {
      cin >> N;
      V = 0.0L;
      sum = 0.0L;
      if (N == 0) {
        break;
      }
      for (int i = 0; i < N - 1; i++) {
        cin >> a;
        sum += SIN(a);
        V += a;
      }
      sum += sin(360.0L - V);
      s[i] = sum;
    }
    if (s[0] == s[1]) {
      cout << '0' << endl;
    }
    if (s[0] > s[1]) {
      cout << '1' << endl;
    }
    if (s[0] < s[1]) {
      cout << '2' << endl;
    }
  }
  return 0;
}
Problem p00167 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;
#define MAX 110
int main() {
  int n;
  int list[MAX];
  while (cin >> n, n) {
    int ans = 0;
    for (int i = 0; i < n; i++) {
      cin >> list[i];
    }

    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n - i - 1; j++) {
        if (list[j] > list[j + 1]) {
          swap(list[j], list[j + 1]);
          ans++;
        }
      }
    }

    cout << ans << endl;
  }
  return 0;
}

Error: -11

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;
#define MAX 10000010
int main() {
  int n;
  int list[MAX];
  while (cin >> n, n) {
    int ans = 0;
    for (int i = 0; i < n; i++) {
      cin >> list[i];
    }

    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n - i - 1; j++) {
        if (list[j] > list[j + 1]) {
          swap(list[j], list[j + 1]);
          ans++;
        }
      }
    }

    cout << ans << endl;
  }
  return 0;
}