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

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

using namespace std;

vector<int> primes;
bool isPrime[60000];

void erats() {
  fill(isPrime, isPrime + 60000, true);
  isPrime[0] = false;
  isPrime[1] = false;
  for (int i = 2; i < 60000; i++) {
    if (isPrime[i]) {
      primes.push_back(i);
      for (int j = 2 * i; j < 60000; j += i) {
        isPrime[j] = false;
      }
    }
  }
}

int main() {

  int n;
  erats();
  while (cin >> n && n != 0) {
    for (int j = n - 1;; j--) {
      if (isPrime[j]) {
        cout << j << " " << flush;
        break;
      }
    }
    for (int j = n + 1;; j++) {
      if (isPrime[j]) {
        cout << j << endl;
        break;
      }
    }
  }

  return 0;
}

Error: 0

Fixed submission:

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

using namespace std;

vector<int> primes;
bool isPrime[50000];

void erats() {
  fill(isPrime, isPrime + 50000, true);
  isPrime[0] = false;
  isPrime[1] = false;
  for (int i = 2; i < 50000; i++) {
    if (isPrime[i]) {
      primes.push_back(i);
      for (int j = 2 * i; j < 50000; j += i) {
        isPrime[j] = false;
      }
    }
  }
}

int main() {

  int n;
  erats();
  while (cin >> n && n != 0) {
    for (int j = n - 1;; j--) {
      if (isPrime[j]) {
        cout << j << " " << flush;
        break;
      }
    }
    for (int j = n + 1;; j++) {
      if (isPrime[j]) {
        cout << j << endl;
        break;
      }
    }
  }

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

#include <cstdio>
#include <cstring>
#include <iostream>
#define MAX_N 50100
using namespace std;

bool prime[MAX_N + 1];

bool isPrime(int n) {
  // 今回、０、１をこの関数の引数に取らない
  for (int r = 2; r * r <= n; r++) {
    if (n % r == 0)
      return (false);
  }
  return (true);
}

void initialize() {
  memset(prime, true, sizeof(prime));
  prime[0] = prime[1] = false; // 0,1は素数ではない。
  for (int r = 2; r * r <= MAX_N; r++) {
    if (isPrime(r)) {
      for (int c = r * 2; c <= MAX_N; c += r)
        prime[c] = false; // 倍数は素数で無い事が分かっている
    }
  }
}

int searchSmall(int num) {
  for (int r = num - 1; r >= 0; r--)
    if (prime[r])
      return (r);
  return (-1);
}

int searchLarge(int num) {
  for (int r = num + 1; r <= MAX_N; r++)
    if (prime[r])
      return (r);
  return (-1);
}

int main(void) {
  initialize();

  int input;
  while (cin >> input) {
    int max = searchSmall(input), min = searchLarge(input);
    cout << max << " " << min << endl;
  }
  return (0);
}

Error: TLE

Fixed submission:

#include <stdio.h>

#define DATANUM 50001

int maxarray(int va[], int std1);
int minarray(int vb[], int std2);

int main(void) {
  int num[DATANUM] = {0};
  int i, j, std;

  for (i = 2; i < DATANUM; i++) {
    if (i != 2 && i % 2 == 0)
      num[i] = 1;
    if (i != 3 && i % 3 == 0)
      num[i] = 1;
    if (i != 5 && i % 5 == 0)
      num[i] = 1;
    if (i != 7 && i % 7 == 0)
      num[i] = 1;
    for (j = 2; j < i; j++) {
      if (!(i % j))
        num[i] = 1;
    }
  }

  while (scanf("%d", &std) != EOF) {
    printf("%d %d\\n", maxarray(num, std), minarray(num, std));
  }

  return (0);
}

int maxarray(int va[], int std1) {
  int max, i;

  max = 2;

  for (i = 2; i < std1; i++) {
    if (i > max && va[i] != 1) {
      max = i;
      printf("max = %d\\n", max);
    }
  }

  return (max);
}

int minarray(int vb[], int std2) {
  int min, i, count = 0;

  for (i = std2 + 1; i <= DATANUM; i++) {
    if (vb[i] != 1 && count == 0) {
      min = i;
      count++;
    }
  }

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

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

int *primeNumberList(int n) {
  int *list = new int[n];

  for (int i = 2; i <= n; ++i) {
    list[i - 1] = 1;
  }

  for (int i = 2; i <= n; ++i) {
    if (list[i - 1] == 1) {
      for (int j = 2 * i; j <= n; j += i) {
        list[j - 1] = 0;
      }
    }
  }

  return list;
}
int main() {
  int max = 60000;
  int *pl = primeNumberList(max);
  int n, plowermax, pgreatermin;

  while (cin >> n) {
    for (int i = n - 1; i >= 1; --i) {
      if (pl[i - 1] == 1) {
        cout << i << " ";
        break;
      }
    }
    for (int i = n + 1; i <= 60000; ++i) {
      if (pl[i - 1] == 1) {
        cout << i << endl;
        break;
      }
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <math.h>
using namespace std;

bool judgePrimenum(int n) {

  int sqr = sqrt((double)n);

  if (n % 2 == 0)
    return false;

  for (int i = 3; i <= sqr; i += 2) {
    if (n % i == 0)
      return false;
  }

  return true;
}

int main() {
  while (true) {
    int n, min = 0, max = 0, i = 1;
    cin >> n;

    while (min == 0 || max == 0) {
      if (max == 0 && judgePrimenum(n + i))
        max = n + i;
      if (min == 0 && judgePrimenum(n - i))
        min = n - i;
      ++i;
    }

    cout << min << " " << max << endl;
  }
  return 0;
}
Problem p00044 (C++) — buggy submission, verdict: Time Limit Exceeded

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

bool prime[60000];

void func() {
  fill(prime, prime + 60000, 1);
  prime[0] = prime[1] = 0;
  for (int i = 2; i * i < 60000; i++) {
    if (prime[i]) {
      for (int j = i * 2; j < 60000; j += i) {
        prime[j] = 0;
      }
    }
  }
}

int main() {
  func();
  int n, i = 0;
  while (cin >> n) {
    for (i = n - 1; prime[i] != 1; i--) {
    }
    cout << i << ' ';
    for (i = n + 1; prime[i] != 1; i++) {
    }
    cout << i << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
bool p[50100];
int main() {
  int i, j;
  for (i = 2; i * i < 50100; i++) {
    if (!p[i]) {
      for (j = i * 2; j < 50100; j += i) {
        p[j] = true;
      }
    }
  }
  while (cin >> i, i) {
    for (j = i - 1; p[j]; j--) {
    }
    cout << j << " ";
    for (j = i + 1; p[j]; j++) {
    }
    cout << j << endl;
  }
  return 0;
}
Problem p00044 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
int p[50100];
int main() {
  int i, j;
  for (i = 2; i * i < 50100; i++) {
    if (p[i] == 0) {
      for (j = i * 2; j < 50100; j += i) {
        p[j] = 1;
      }
    }
  }
  while (cin >> i) {
    for (j = i - 1; p[j]; j--) {
    }
    cout << j << ' ';
    for (j = i + 1; p[j]; j++) {
    }
    cout << j << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int p[50100];
int main() {
  int i, j;
  for (i = 2; i * i < 50100; i++) {
    if (p[i] == 0) {
      for (j = i * 2; j < 50100; j += i) {
        p[j] = 1;
      }
    }
  }
  while (cin >> i, i) {
    for (j = i - 1; p[j]; j--) {
    }
    cout << j << ' ';
    for (j = i + 1; p[j]; j++) {
    }
    cout << j << endl;
  }
  return 0;
}
Problem p00044 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <complex>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>
using namespace std;

#define rep(i, n) for (int i = 0; i < int(n); ++i)

static const double PI = 6 * asin(0.5);
typedef complex<double> P;
typedef long long ll;

bool prime[50050];
vector<int> pri;

int main() {
  memset(prime, 0, sizeof(prime));
  rep(i, 50050) { prime[i] = true; }
  prime[1] = false;
  prime[0] = false;
  for (int i = 1; i * i < 50050; i++) {
    if (prime[i]) {
      // cout<<i<<" ";
      for (int j = i * i; j < 50050; j += i) {
        prime[j] = false;
      }
    }
  }
  rep(i, 50050) {
    if (prime[i])
      pri.push_back(i);
  }
  int n;
  while (cin >> n) {
    int smo, lar;
    rep(i, pri.size()) {
      if (pri[i] < n) {
      } else {
        if (prime[n] == true) {
          smo = pri[i - 1];
          lar = pri[i + 1];
        } else {
          smo = pri[i - 1];
          lar = pri[i];
        }
        break;
      }
    }
    cout << smo << " " << lar << endl;
  }

  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <complex>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>
using namespace std;

#define rep(i, n) for (int i = 0; i < int(n); ++i)

static const double PI = 6 * asin(0.5);
typedef complex<double> P;
typedef long long ll;

bool prime[6010];
vector<int> pri;

int main() {
  memset(prime, 0, sizeof(prime));
  rep(i, 6000) { prime[i] = true; }
  prime[1] = false;
  prime[0] = false;
  for (int i = 1; i * i < 6000; i++) {
    if (prime[i]) {
      // cout<<i<<" ";
      for (int j = i * i; j < 6000; j += i) {
        prime[j] = false;
      }
    }
  }
  rep(i, 6000) {
    if (prime[i])
      pri.push_back(i);
  }

  int n;
  while (cin >> n) {
    int smo, lar;
    rep(i, 6000) {
      if (pri[i] < n) {
      } else {
        if (prime[n] == true) {
          smo = pri[i - 1];
          lar = pri[i + 1];
        } else {
          smo = pri[i - 1];
          lar = pri[i];
        }
        break;
      }
    }
    cout << smo << " " << lar << endl;
  }

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

#include <iostream>
using namespace std;

int main() {
  int prime[30000];
  prime[0] = 2;
  int num = 1, n;

  for (int i = 3; i < 50100; i++) {
    bool f = true;
    for (int j = 0; j < num; j++) {
      if (i % prime[j] == 0) {
        f = false;
        break;
      }
    }
    if (f) {
      prime[num] = i;
      num++;
    }
  }

  while (cin >> n, !cin.eof()) {

    int i;

    for (i = 0; prime[i] < n; i++) {
    }
    cout << prime[i - 1] << ' ' << ((prime[i] == n) ? prime[i + 1] : prime[i])
         << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int prime[30000];
  prime[0] = 2;
  int num = 1, n;

  for (int i = 3; i < 50000; i++) {
    bool f = true;
    for (int j = 0; j < num; j++) {
      if (i % prime[j] == 0) {
        f = false;
        break;
      }
    }
    if (f) {
      prime[num] = i;
      num++;
    }
  }

  while (cin >> n, n) {

    int i;

    for (i = 0; prime[i] < n; i++) {
    }
    cout << prime[i - 1] << ' ' << ((prime[i] == n) ? prime[i + 1] : prime[i])
         << endl;
  }

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

#include <iostream>
#include <vector>
#define MAX 100000
using namespace std;
int main() {
  vector<bool> v(MAX);
  for (int i = 0; i < MAX; i++)
    v[i] = true;

  v[0] = v[1] = false;
  for (int i = 2; i < 1000; i++) {
    if (v[i]) {
      for (int j = i * i; j < MAX; j += i) {
        v[j] = false;
      }
    }
  }
  while (true) {
    int a;
    cin >> a;
    if (cin.eof())
      return 0;
    for (int i = a - 1; true; i--) {
      if (v[i]) {
        cout << i << ' ';
        break;
      }
    }
    for (int i = a + 1; true; i++) {
      if (v[i]) {
        cout << i << endl;
        break;
      }
    }
  }
}


Error: TLE

Fixed submission:

#include <iostream>
#include <vector>
#define MAX 100000
using namespace std;
int main() {
  vector<bool> v(MAX);
  for (int i = 0; i < MAX; i++)
    v[i] = true;

  v[0] = v[1] = false;
  for (int i = 2; i < 1000; i++) {
    if (v[i]) {
      for (int j = i * i; j < MAX; j += i) {
        v[j] = false;
      }
    }
  }
  while (true) {
    int a;
    cin >> a;
    if (cin.eof())
      return 0;
    while (true) {
      int i = a;
      i--;
      if (v[i]) {
        cout << i << ' ';
        break;
      }
    }
    while (true) {
      int i = a;
      i++;
      if (v[i]) {
        cout << i << endl;
        break;
      }
    }
  }
}
Problem p00045 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int a, b, sum = 0, i = 0;
  int c = 0;
  while (scanf("%d,%d", &a, &b) != EOF) {
    sum += a * b;
    i++;
    c += b;
  }
  printf("%d\\n%d\\n", sum, (c + 1) / i);
  return (0);
}

Error: TLE

Fixed submission:

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

int main() {
  int a, b, sum = 0, i = 0, c = 0;
  while (scanf("%d,%d", &a, &b)) {
    sum += a * b;
    i++;
    c += b;
  }
  cout << sum << endl << c / i << endl;
  return (0);
}
Problem p00045 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int a = 0, s = 0, n = 0, b, c;
  while (scanf("%d,%d", &b, &c) + 1) {
    s += (b * c);
    a += c;
    ++n;
  }
  a = round((double)a / n);
  cout << s << endl << a << endl;
}

Error: -11

Fixed submission:

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

int main() {
  int a = 0, s = 0, n = 0, b, c;
  while (scanf("%d,%d", b, c) + 1) {
    s += (b * c);
    ++n;
    a += c;
  }
  a /= n;
}
Problem p00045 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define reps(i, f, n) for (int i = f; i < int(n); i++)
#define rep(i, n) reps(i, 0, n)

int main() {

  int a, b;
  int sum = 0, c = 0;
  int sumb = 0;

  while (scanf("%d,%d", &a, &b) != EOF) {
    sum += a * b;
    sumb += b;
    c++;
  }

  printf("%d\\n%d\\n", sum, int(sumb / (double)c + 0.5));
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define reps(i, f, n) for (int i = f; i < int(n); i++)
#define rep(i, n) reps(i, 0, n)

int main() {
  int a, b;
  int sum = 5, c = 3;

  while (scanf("%d,%d", &a, &b)) {
    sum += a * b;
    c++;
  }

  printf("%d %d\\n", sum, int(sum / (double)c + 0.5));
}
Problem p00045 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  double a = 0.0, b = 0.0, sum = 0.0, sumw = 0.0;
  double cnt = 0.0;
  while (scanf("%lf,%lf", &a, &b) != EOF) {
    sum = sum + a * b;
    sumw = sumw + b;
    cnt = cnt + 1.0;
  }

  cout << sum << endl;
  cout << (int)floor((sumw / cnt) + 0.5) << endl;
}

Error: TLE

Fixed submission:

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

int main() {
  double a = 0.0, b = 0.0, sum = 0.0, sumw = 0.0;
  double cnt = 0.0;
  while (scanf("%lf,%lf", &a, &b) != '\\n') {
    sum = sum + a * b;
    sumw = sumw + b;
    cnt = cnt + 1.0;
  }

  cout << sum << endl;
  cout << (int)floor((sumw / cnt) + 0.5) << endl;
}
Problem p00045 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int a, b, c, s1;
  double s2;

  c = s1 = s2 = 0;

  while (scanf("%d,%d", &a, &b) != EOF) {
    // while (scanf("%d,%d", &a, &b) != EOF){
    s1 += a * b;
    c++;
    s2 += b;
  }
  printf("%d\\n%.0f\\n", s1, (s2 + 1) / c);

  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  int a, b, c, s1;
  double s2;

  c = s1 = s2 = 0;

  while (scanf("%d,%d", &a, &b)) {
    s1 += a * b;
    c++;
    s2 += b;
  }
  printf("%d\\n%.0f\\n", s1, s2 / c);

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

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>

using namespace std;
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

int main() {
  int a, b, c = 0, d = 0, n = 0;
  while (~scanf("%d,%d", &a, &b))
    c += a * b, d += b, n++;
  printf("%d\\n%d\\n", c, (int)floor((double)d / n + 0.5));
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>

using namespace std;
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

int main() {
  int a, b, c = 0, d = 0, n = 0;
  while (scanf("%d,%d", &a, &b))
    c += a * b, d += b, n++;
  printf("%d\\n%d\\n", c, (int)floor((double)d / n + 0.5));
  return 0;
}
Problem p00045 (C++) — buggy submission, verdict: Time Limit Exceeded

#include "bits/stdc++.h"
#include <unordered_map>
#include <unordered_set>
#pragma warning(disable : 4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;

//// < "d:\\d_download\\visual studio
///2015\\projects\\programing_contest_c++\\debug\\a.txt" > "d:\\d_download\\visual
///studio 2015\\projects\\programing_contest_c++\\debug\\b.txt"

int main() {
  int a, b;
  int c = 0, d = 0;
  int n = 0;
  while (scanf("%d,%d", &a, &b) != EOF) {
    c += a * b;
    d += b;
    n++;
  }
  cout << c << endl << int((ld(d) + 0.5 * n) / n) << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include "bits/stdc++.h"
#include <unordered_map>
#include <unordered_set>
#pragma warning(disable : 4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;

//// < "d:\\d_download\\visual studio
///2015\\projects\\programing_contest_c++\\debug\\a.txt" > "d:\\d_download\\visual
///studio 2015\\projects\\programing_contest_c++\\debug\\b.txt"

int main() {
  int a, b;
  int c = 0, d = 0;
  int n = 0;
  while (scanf("%d,%d", &a, &b)) {
    c += a * b;
    d += b;
    n++;
  }
  cout << c << endl << d / n << endl;
  return 0;
}
Problem p00045 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int price, amount;
  int sum = 0, ave = 0, i = 0;
  while (scanf("%d,%d", &price, &amount) != EOF) {
    sum += price * amount;
    ave += amount;
    i++;
  }

  printf("%d\\n%d\\n", sum, (int)(ave / (double)i + 0.5));
  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  int price, amount;
  int sum = 0, ave = 0, i = 0;
  while (scanf("%d,%d", &price, &amount)) {
    sum += price * amount;
    ave += amount;
    i++;
  }

  printf("%d\\n%d\\n", sum, (int)(ave / (double)i + 0.5));
  return 0;
}
Problem p00045 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <string.h>
using namespace std;

int main() {
  int m = 0, n = 0, c = 0, i, j;
  char a;
  while (cin >> i >> a >> j) {
    m += (i * j);
    n += j;
    c++;
  }
  double am = 1.0 * n / c;
  if (am * 10 - int(am / 10) > 4)
    am = am + 1;
  cout << m << endl << int(am) << endl;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <string.h>
using namespace std;

int main() {
  int m = 0, n = 0, c = 0, i, j;
  char a;
  while (cin >> i >> a >> j, i) {
    m += (i * j);
    n += j;
    c++;
  }
  double am = 1.0 * n / c;
  if (am * 10 - int(am / 10) > 4)
    am = am + 1;
  cout << m << endl << int(am) << endl;
}
Problem p00045 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>
#include <iostream>

using namespace std;

int main() {
  int one, all, i;
  double many, heikin;

  all = 0;

  i = 0;

  while (scanf("%d,%lf", &one, &many) != EOF) {

    all += one * many;

    heikin += many;

    i++;
  }

  printf("%d\\n%.f\\n", all, (heikin / i + 0.5));

  return 0;
}

Error: -8

Fixed submission:

#include <algorithm>
#include <iostream>

using namespace std;

int main() {
  int one, many, all, heikin, i;

  all = 0;

  i = 0;

  while (cin >> one >> many) {

    all += one * many;

    heikin += many;

    i++;
  }
  cout << all << heikin / i << endl;

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

#include <cstdio>

int main() {
  int sp = 0;
  int tn = 0;
  int n = 0;

  int price, num;

  while (scanf("%d,%d", &price, &num) != EOF) {

    sp += price * num;
    tn += num;
    n++;
  }
  printf("%d\\n%d\\n", sp, (int)((double)tn / n + 0.5));
}


Error: -8

Fixed submission:

#include <iostream>

using namespace std;

int main() {

  int price, num;
  int n = 0;
  int sp = 0;
  int tn = 0;

  while (cin >> price >> num) {

    sp += price * num;
    tn += num;
    n++;
  }
  cout << sp << "\\n";
  cout << tn / n << "\\n";

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

#include <cstdio>
#include <iostream>
using namespace std;
int main() {
  double sum = 0, cnt = 0, a = 0, b = 0, i = 0;
  while (scanf("%lf,%lf", &a, &b) != EOF) {
    cnt += b;
    sum += a * b;
    i++;
  }
  int s = (int)(cnt / i);
  if ((double)s + 0.500 <= sum)
    s++;
  cout << sum << endl << s << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <cstdio>
#include <iostream>
using namespace std;
int main() {
  double sum = 0, cnt = 0, a = 0, b = 0, i = 0;
  while (true) {
    cin >> a;
    cin.ignore();
    cin >> b;
    if (a == 0 && b == 0)
      break;
    cnt += b;
    sum += a * b;
    i++;
  }
  int s = (int)(cnt / i);
  if ((double)s + 0.500 <= sum)
    s++;
  cout << sum << " " << s << endl;
  return 0;
}
Problem p00045 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
int main() {
  map<double, double> m;
  double a, b, ave = 0, sum = 0;
  while (scanf("%lf,%lf", &a, &b) != EOF) {
    m[a] = b;
  }
  map<double, double>::iterator it = m.begin();
  while (it != m.end()) {
    ave += (*it).second, sum += ((*it).first * (*it).second);
    it++;
  }
  ave /= m.size();
  ave += 0.5;
  cout << sum << endl << (int)ave << endl;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
int main() {
  map<double, double> m;
  double a, b, ave, sum;
  while (scanf("%lf,%lf", &a, &b)) {
    if (!a)
      break;
    m[a] = b;
  }
  map<double, double>::iterator it = m.begin();
  while (it != m.end()) {
    ave += (*it).second, sum += ((*it).first * (*it).second);
    it++;
  }
  ave /= m.size();
  ave += 0.5;
  cout << sum << endl << (int)ave << endl;
}
Problem p00045 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
#include <iostream>

using namespace std;

int main() {

  int value, num, i = 0, total = 0, ave = 0;

  while (scanf("%d, %d", &value, &num) != EOF) {
    total += value * num;
    ave += num;
    i++;
  }

  cout << total << endl << (int)(ave / (double)i + 0.5) << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <cstdio>
#include <iostream>

using namespace std;

int main() {

  int value, num, i = 0, total = 0, ave = 0;

  while (scanf("%d %d", &value, &num) != EOF) {
    total += value * num;
    ave += num;
    i++;
  }

  cout << total << endl << (int)(ave / (double)i + 0.5) << endl;

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

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

int main() {
  int a, b;
  int ca = 0;
  double cb = 0;
  int i = 0;
  while (scanf("%d,%d", &a, &b) != EOF) {
    ca += a * b;
    cb += b;
    i++;
  }
  double cc = cb / i;
  double cd = round(cc);
  cout << ca << endl << cd << endl;
  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  int a, b;
  int ca = 0;
  double cb = 0;
  int i = 0;
  while (scanf("%d,%d", &a, &b)) {
    ca += a * b;
    cb += b;
    i++;
  }
  double cc = cb / i;
  double cd = round(cc);
  cout << ca << endl << cd << endl;
  return 0;
}