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

#include <cstdio>
#include <iostream>

using namespace std;

#define ll long long

ll sum(ll arg) { return arg * (arg + 1) / 2; }

ll gcd(ll a, ll b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}

ll lcm(ll a, ll b) { return a * b / gcd(a, b); }

int main() {
  int n, m;

  while (cin >> n >> m) {
    ll a[m];
    double ret = 0;
    long long s = sum(n);
    long long allnum = n;

    if ((n | m) == 0)
      break;
    for (int i = 0; i < m; i++)
      cin >> a[i];

    // ï´
    for (ll i = 1; i < (1 << m); i++) {
      int bitnum = 0;
      ll lc = 1;
      for (int j = 0; j < m; j++) {
        if (i & (1 << j)) { // jÔÚvfªÜÜêÄ¢é
          bitnum++;
          lc = lcm(lc, a[j]);
        }
      }
      // cout << lc << endl;
      if (bitnum % 2 == 1) {
        s -= lc * sum(n / lc);
        allnum -= n / lc;
      } else {
        s += lc * sum(n / lc);
        allnum += n / lc;
      }
    }
    if (allnum == 0) {
      ret = 0;
    } else {
      ret = (double)s / allnum;
    }
    // cout << sum << " " << allnum << endl;
    printf("%.7f\\n", ret);
  }
}

Error: 0

Fixed submission:

#include <cstdio>
#include <iostream>
using namespace std;
#define ll long long

ll gcd(ll a, ll b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}

ll lcm(ll a, ll b) { return a * b / gcd(a, b); }

ll countbit(ll arg) {
  ll ret = 0;
  while (arg > 0) {
    if (arg & 1)
      ret++;
    arg >>= 1;
  }
  return ret;
}

int main() {
  int n, m;

  while (cin >> n >> m) {
    int a[22];
    double ret = 0;
    long long sum = n * (n + 1) / 2;
    long long allnum = n;

    if ((n | m) == 0)
      break;
    for (int i = 0; i < m; i++)
      cin >> a[i];

    // ï´
    for (ll i = 1; i < (1 << m); i++) {
      int bitnum = countbit(i);
      int lc = 1;
      int number;
      for (int j = 0; j < n; j++) {
        if (i & (1 << j)) { // jÔÚvfªÜÜêÄ¢é
          lc = lcm(lc, a[j]);
        }
      }
      // cout << lc << endl;
      number = n / lc;
      if (bitnum % 2 == 1) {
        sum -= lc * number * (number + 1) / 2;
        allnum -= number;
      } else {
        sum += lc * number * (number + 1) / 2;
        allnum += number;
      }
    }
    if (allnum == 0) {
      ret = 0;
    } else {
      ret = (double)sum / allnum;
    }
    // cout << sum << " " << allnum << endl;
    printf("%.10f\\n", ret);
  }
}
Problem p00661 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  long long n;
  int m;
  while (cin >> n >> m && (n || m)) {
    int f = 0;
    long long b;
    for (int i = 0; i < m; i++) {
      cin >> b;
      if (b == 1)
        f = 1;
    }
    if (f == 1)
      printf("%.10f\\n", (double)0);
    else
      printf("%.10f\\n", (double)n / 2);
  }
  return 0;
}

Error: 0

Fixed submission:

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

ll u(ll a, ll b) {
  while (b != 0) {
    ll tmp = b;
    b = a % b;
    a = tmp;
  }
  return a;
}

int main() {
  ll n, m;
  ll p[20];
  while (cin >> n >> m && (n || m)) {
    for (int i = 0; i < m; i++)
      cin >> p[i];
    sort(p, p + m);
    for (int i = m - 1; i > 0; i--) {
      for (int j = 0; j < i; j++) {
        if (p[i] % p[j] == 0) {
          p[i] = 0;
          break;
        }
      }
    }
    ll sum = n * (n + 1) / 2, cnt = n;
    for (int i = 0; i < m; i++) {
      if (p[i] == 0)
        continue;
      sum -= n * (n / p[i] + 1) / 2;
      cnt -= n / p[i];

      for (int j = 0; j < i; j++) {
        ll a = p[j] * p[i] / u(p[j], p[i]);
        sum += n * (n / a + 1) / 2;
        cnt += n / a;
      }
    }
    if (sum == 0)
      cnt = 1;
    printf("%.10f\\n", (double)sum / cnt);
  }

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

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

#define REP(i, s, e) for (int i = (int)s; i < (int)e; i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define fi first
#define se second
#define pb push_back
#define mp nake_pair

typedef long long ll;

typedef vector<int> vi;

int calc(int m, const vi &d) {
  int ret = m;
  rep(i, 3) if (m > d[i]) return -1e9;
  rep(i, 3) ret += (d[i] - m) / 3;
  return ret;
}

int main() {
  vi v(6);
  while (1) {
    rep(i, 6) cin >> v[i];
    if (v[0] == 0 && v[1] == 0 && v[2] == 0 && v[3] == 0 && v[4] == 0 &&
        v[5] == 0)
      break;
    vi d(3);
    rep(i, 6) d[i % 3] += v[i];
    double l = 0, r = 1e9;
    rep(i, 1000) {
      double m1 = l + (r - l) / 3.0, m2 = l + (r - l) * 2.0 / 3.0;
      int f1 = calc(m1, d), f2 = calc(m2, d);
      if (f1 < f2)
        l = m1;
      else
        r = m2;
    }
    cout << calc(r, d) << endl;
  }
}

Error: TLE

Fixed submission:

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

#define REP(i, s, e) for (int i = (int)s; i < (int)e; i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define fi first
#define se second
#define pb push_back
#define mp nake_pair

typedef long long ll;

typedef vector<int> vi;

int calc(int m, const vi &d) {
  int ret = m;
  rep(i, 3) if (m > d[i]) return -1e9;
  rep(i, 3) ret += (d[i] - m) / 3;
  return ret;
}

int main() {
  vi v(6);
  while (1) {
    rep(i, 6) cin >> v[i];
    if (v[0] == 0 && v[1] == 0 && v[2] == 0 && v[3] == 0 && v[4] == 0 &&
        v[5] == 0)
      break;
    vi d(3);
    rep(i, 6) d[i % 3] += v[i];
    double l = 0, r = 1e9;
    rep(i, 10000) {
      double m1 = l + (r - l) / 3.0, m2 = l + (r - l) * 2.0 / 3.0;
      int f1 = calc(m1, d), f2 = calc(m2, d);
      if (f1 < f2)
        l = m1;
      else
        r = m2;
    }
    cout << calc(r, d) << endl;
  }
}
Problem p00662 (C++) — buggy submission, verdict: Time Limit Exceeded

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

#define DUMP(x) cerr << #x << "=" << x << endl
#define DUMP2(x, y)                                                            \\
  cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")" << endl
#define BINARY(x) static_cast<bitset<16>>(x)

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

#define in_range(x, y, w, h)                                                   \\
  (0 <= (int)(x) && (int)(x) < (int)(w) && 0 <= (int)(y) && (int)(y) < (int)(h))
#define ALL(a) (a).begin(), (a).end()

typedef long long ll;
const int INF = 1e9;
const ll INFLL = 1e18;
typedef pair<int, int> PII;
int dx[4] = {0, -1, 1, 0}, dy[4] = {-1, 0, 0, 1};

int main() {
  ios::sync_with_stdio(false);

  int M, GRE, GEO, DP, GRA, O;
  while (cin >> M >> GRE >> GEO >> DP >> GRA >> O) {
    if (!M && !GRE && !GEO && !DP && !GRA && !O)
      break;

    int G1 = M + DP;
    int G2 = GRE + GRA;
    int G3 = GEO + O;

    int ans = 0;
    int mn = min({G1, G2, G3});

    /*
    {
        int tmp = mn;
        tmp += (G1 - mn) / 3;
        tmp += (G2 - mn) / 3;
        tmp += (G3 - mn) / 3;
        tmp += min({(G1 - mn)%3, (G2 - mn)%3, (G3 - mn)%3});
        ans = max(ans, tmp);
    }

    {
        int tmp = 0;
        tmp += G1/3; G1%=3;
        tmp += G2/3; G2%=3;
        tmp += G3/3; G3%=3;
        tmp += min({G1, G2, G3});
        ans = max(ans, tmp);
    }
    */

    // cerr << "------------" << endl;
    for (int m = max(0, mn - 100); m <= mn; m++) {
      int tmp = m;
      tmp += (G1 - m) / 3;
      tmp += (G2 - m) / 3;
      tmp += (G3 - m) / 3;
      ans = max(ans, tmp);
      // DUMP(tmp);
    }

    cout << ans << endl;
  }
}

Error: TLE

Fixed submission:

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

#define DUMP(x) cerr << #x << "=" << x << endl
#define DUMP2(x, y)                                                            \\
  cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")" << endl
#define BINARY(x) static_cast<bitset<16>>(x)

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

#define in_range(x, y, w, h)                                                   \\
  (0 <= (int)(x) && (int)(x) < (int)(w) && 0 <= (int)(y) && (int)(y) < (int)(h))
#define ALL(a) (a).begin(), (a).end()

typedef long long ll;
const int INF = 1e9;
const ll INFLL = 1e18;
typedef pair<int, int> PII;
int dx[4] = {0, -1, 1, 0}, dy[4] = {-1, 0, 0, 1};

int main() {
  ios::sync_with_stdio(false);

  int M, GRE, GEO, DP, GRA, O;
  while (cin >> M >> GRE >> GEO >> DP >> GRA >> O) {
    if (!M && !GRE && !GEO && !DP && !GRA && !O)
      break;

    int G1 = M + DP;
    int G2 = GRE + GRA;
    int G3 = GEO + O;

    int ans = 0;
    int mn = min({G1, G2, G3});

    for (int m = 0; m <= mn; m++) {
      int tmp = m;
      tmp += (G1 - m) / 3;
      tmp += (G2 - m) / 3;
      tmp += (G3 - m) / 3;
      ans = max(ans, tmp);
    }

    cout << ans << endl;
  }
}
Problem p00662 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  while (true) {
    vector<int> vi(3);
    for (int i = 0; i < 6; ++i) {
      int tmp;
      cin >> tmp;
      vi[i % 3] += tmp;
    }
    bool flag = true;
    for (int i = 0; i < 3; ++i) {
      if (vi[i] != 0)
        flag = false;
    }
    if (flag)
      break;
    int ans = 0;
    for (int i = 0; i < 3; ++i) {
      vector<int> hoge = vi;
      int sum = 0;
      {
        int tmp = min(hoge[0], min(i, min(hoge[1], hoge[2])));
        for (int j = 0; j < 3; ++j)
          hoge[j] -= tmp;
        sum += tmp;
      }
      for (int j = 0; j < 3; ++j) {
        int tmp = hoge[j] / 3;
        hoge[j] -= tmp * 3;
        sum += tmp;
      }
      ans = max(ans, sum);
    }
    cout << ans << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  while (true) {
    vector<int> vi(3);
    for (int i = 0; i < 6; ++i) {
      int tmp;
      cin >> tmp;
      vi[i % 3] += tmp;
    }
    bool flag = true;
    for (int i = 0; i < 3; ++i) {
      if (vi[i] != 0)
        flag = false;
    }
    if (flag)
      break;
    int ans = 0;
    while (vi[0] > 0 && vi[1] > 0 && vi[2] > 0) {
      for (int i = 0; i < 3; ++i)
        --vi[i];
      ++ans;
    }
    for (int i = 0; i < 3; ++i) {
      while (vi[i] >= 3) {
        vi[i] -= 3;
        ++ans;
      }
    }
    cout << ans << endl;
  }
  return 0;
}
Problem p00662 (C++) — buggy submission, verdict: Time Limit Exceeded

#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

static const double EPS = 1e-8;

int main() {
  int math, greedy, geometry, DP, graph, other;
  while (~scanf("%d %d %d %d %d %d", &math, &greedy, &geometry, &DP, &graph,
                &other)) {
    if (math + greedy + geometry + DP + graph + other == 0)
      break;

    int A = math + DP;
    int B = greedy + graph;
    int C = geometry + other;

    int res = 0;

    int max_game = min(min(A, B), C);
    for (int balance_game = 0; balance_game <= min(2, max_game);
         balance_game++) {
      int tmpA = A;
      int tmpB = B;
      int tmpC = C;
      tmpA -= balance_game;
      tmpB -= balance_game;
      tmpC -= balance_game;
      int math_game = tmpA / 3;
      int algorithm_game = tmpB / 3;
      int implement_game = tmpC / 3;

      res =
          max(balance_game + math_game + algorithm_game + implement_game, res);
    }
    printf("%d\\n", res);
  }
}

Error: TLE

Fixed submission:

#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

static const double EPS = 1e-8;

int main() {
  int math, greedy, geometry, DP, graph, other;
  while (~scanf("%d %d %d %d %d %d", &math, &greedy, &geometry, &DP, &graph,
                &other)) {
    if (math + greedy + geometry + DP + graph + other == 0)
      break;

    int A = math + DP;
    int B = greedy + graph;
    int C = geometry + other;

    int res = 0;

    int max_game = min(min(A, B), C);
    for (int balance_game = 0; balance_game <= max_game; balance_game++) {
      int tmpA = A;
      int tmpB = B;
      int tmpC = C;
      tmpA -= balance_game;
      tmpB -= balance_game;
      tmpC -= balance_game;
      int math_game = tmpA / 3;
      int algorithm_game = tmpB / 3;
      int implement_game = tmpC / 3;

      res =
          max(balance_game + math_game + algorithm_game + implement_game, res);
    }
    printf("%d\\n", res);
  }
}
Problem p00662 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cassert>
#include <cmath>
#include <iostream>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;

int main() {
  int Math, Greedy, Geometry, DP, Graph, Other;
  while (cin >> Math >> Greedy >> Geometry >> DP >> Graph >> Other,
         Math | Greedy | Geometry | DP | Graph | Other) {
    int total[3];
    total[0] = Math + DP;
    total[1] = Greedy + Graph;
    total[2] = Geometry + Other;
    assert(total[0] + total[1] + total[2] <= 100000000LL);

    // int Size = min(total[0],min(total[1],total[2]));
    int ans = 0;

    rep(i, 3) {
      int A = total[0], B = total[1], C = total[2];
      int preans = i;
      A -= i;
      B -= i;
      C -= i;
      if (A < 0 || B < 0 || C < 0)
        continue;
      preans += A / 3;
      preans += B / 3;
      preans += C / 3;
      ans = max(ans, preans);
    }

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

Error: TLE

Fixed submission:

#include <algorithm>
#include <cassert>
#include <cmath>
#include <iostream>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;

int main() {
  int Math, Greedy, Geometry, DP, Graph, Other;
  while (cin >> Math >> Greedy >> Geometry >> DP >> Graph >> Other,
         Math | Greedy | Geometry | DP | Graph | Other) {
    int total[3];
    total[0] = Math + DP;
    total[1] = Greedy + Graph;
    total[2] = Geometry + Other;
    assert(total[0] + total[1] + total[2] <= 100000000LL);

    int Size = min(total[0], min(total[1], total[2]));
    int ans = 0;

    rep(i, Size + 1) {
      int A = total[0], B = total[1], C = total[2];
      int preans = i;
      A -= i;
      B -= i;
      C -= i;
      preans += A / 3;
      preans += B / 3;
      preans += C / 3;
      ans = max(ans, preans);
    }

    cout << ans << endl;
  }
  return 0;
}
Problem p00662 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int main() {
  int a, b, c, d, e, f;
  while (cin >> a >> b >> c >> d >> e >> f, a || b || c || d || e || f) {
    a += d;
    b += e;
    c += f;
    int Max = 0;
    for (int i = 0; i <= min(2, min(a, min(b, c))); i++)
      Max = max(Max, (a - i) / 3 + (b - i) / 3 + (c - i) / 3 + i);
    cout << Max << endl;
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int main() {
  int a, b, c, d, e, f;
  while (cin >> a >> b >> c >> d >> e >> f, a || b || c || d || e || f) {
    a += d;
    b += e;
    c += f;
    int Max = 0;
    for (int i = 0; i <= min(a, min(b, c)); i++)
      Max = max(Max, (a - i) / 3 + (b - i) / 3 + (c - i) / 3 + i);
    cout << Max << endl;
  }
}
Problem p00662 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <sstream>
#include <string>
#include <vector>

#define REP(i, k, n) for (int i = k; i < n; i++)
#define rep(i, n) for (int i = 0; i < n; i++)
#define INF 1 << 30
#define pb push_back
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int main() {
  ll a, b, c, d, e, f;
  while (cin >> a >> c >> e >> b >> d >> f) {
    if (a == 0 && b == 0 && c == 0 && d == 0 && e == 0 && f == 0)
      break;

    ll ans = 0, A = 0, B = 0, C = 0;
    ll res = min(a + b, min(c + d, e + f));

    A = (a + b) - res;
    B = (c + d) - res;
    C = (e + f) - res;
    ans = res + (A / 3) + (B / 3) + (C / 3);

    if (res >= 1) {
      A++;
      B++;
      C++;
      res--;
    } else if (res >= 2) {
      A += 2;
      B += 2;
      C += 2;
      res -= 2;
    }

    cout << max(ans, res + (A / 3) + (B / 3) + (C / 3)) << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <sstream>
#include <string>
#include <vector>

#define REP(i, k, n) for (int i = k; i < n; i++)
#define rep(i, n) for (int i = 0; i < n; i++)
#define INF 1 << 30
#define pb push_back
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int main() {
  int a, b, c, d, e, f;
  while (cin >> a >> c >> e >> b >> d >> f) {
    if (a == 0 && b == 0 && c == 0 && d == 0 && e == 0 && f == 0)
      break;

    int ans = 0, A = a + b, B = c + d, C = e + f;

    while (a > 0 && b > 0 && a + b >= 3) {
      if (a >= 3 && b >= 3) {
        a -= 3;
        b -= 3;
        ans += 2;
      } else {
        A = a + b - 3;
        ans++;
        a = 0;
        b = 0;
      }
    }

    while (c > 0 && d > 0 && c + d >= 3) {
      if (c >= 3 && d >= 3) {
        c -= 3;
        d -= 3;
        ans += 2;
      } else {
        B = c + d - 3;
        ans++;
        c = 0;
        d = 0;
      }
    }

    while (e > 0 && f > 0 && e + f >= 3) {
      if (e >= 3 && f >= 3) {
        e -= 3;
        f -= 3;
        ans += 2;
      } else {
        C = e + f - 3;
        ans++;
        e = 0;
        f = 0;
      }
    }

    cout << ans + min(A, min(B, C)) << endl;
  }
  return 0;
}
Problem p00662 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
using namespace std;
int a, b, c, d, e, f, sum1, sum2, sum3, sum, p;
int main() {
  while (true) {
    sum = 0;
    cin >> a >> b >> c >> d >> e >> f;
    if (a + b + c + d + e + f == 0) {
      break;
    }
    sum1 = a + d;
    sum2 = b + e;
    sum3 = c + f;
    p = 0;
    p = min(sum1, sum2);
    p = min(p, sum3);
    for (int i = max(0, p - 10); i <= p; i++) {
      sum = max(sum, i + (sum1 - i) / 3 + (sum2 - i) / 3 + (sum3 - i) / 3);
    }
    cout << sum << endl;
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
using namespace std;
int a, b, c, d, e, f, sum1, sum2, sum3, sum, p;
int main() {
  while (true) {
    sum = 0;
    cin >> a >> b >> c >> d >> e >> f;
    if (a + b + c + d + e + f == 0) {
      break;
    }
    sum1 = a + d;
    sum2 = b + e;
    sum3 = c + f;
    p = 0;
    p = min(sum1, sum2);
    p = min(p, sum3);
    for (int i = 0; i <= p; i++) {
      sum = max(sum, i + (sum1 - i) / 3 + (sum2 - i) / 3 + (sum3 - i) / 3);
    }
    cout << sum << endl;
  }
}
Problem p00662 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstring>
#include <iostream>
#include <queue>
#include <stack>
#include <string>
#include <vector>

#define FOR(i, b, n) for (int i = b; i < n; i++)
#define CLR(mat) memset(mat, 0, sizeof(mat))

using namespace std;

int solve(int a, int b, int c) {
  int res = 0;

  FOR(i, 0, 3) {
    if (a >= i && b >= i && c >= i)
      res = max(res, i + (a - i) / 3 + (b - i) / 3 + (c - i) / 3);
  }

  return res;
}

int main() {
  int mt, gre, geo, dp, grp, otr;

  while (cin >> mt >> gre >> geo >> dp >> grp >> otr,
         mt || gre || geo || dp || grp || otr) {
    cout << solve(mt + dp, gre + grp, geo + otr) << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstring>
#include <iostream>
#include <queue>
#include <stack>
#include <string>
#include <vector>

#define FOR(i, b, n) for (int i = b; i < n; i++)
#define CLR(mat) memset(mat, 0, sizeof(mat))

using namespace std;

int solve(int a, int b, int c) {
  int res = 0;
  int d = min(a, min(b, c));

  FOR(i, 0, d + 1) {
    res = max(res, i + (a - i) / 3 + (b - i) / 3 + (c - i) / 3);
  }

  return res;
}

int main() {
  int mt, gre, geo, dp, grp, otr;

  while (cin >> mt >> gre >> geo >> dp >> grp >> otr,
         mt || gre || geo || dp || grp || otr) {
    cout << solve(mt + dp, gre + grp, geo + otr) << endl;
  }

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

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

#define MOD 1000000007
#define INTMAX 0x7fffffff
#define INTMIN 0x80000000
#define LLMAX 0x7fffffffffffffffLL
#define LLMIN 0x8000000000000000LL

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

using namespace std;
using ll = long long;

int main() {
  while (1) {
    int n[6];
    scanf("%d%d%d%d%d%d", n, n + 1, n + 2, n + 3, n + 4, n + 5);
    if (n[0] + n[1] + n[2] + n[3] + n[4] + n[5] == 0) {
      break;
    }
    int a = n[0] + n[3];
    int b = n[1] + n[4];
    int c = n[2] + n[5];
    int d = min(a, min(b, c));

    int ans = 0;
    rep(count4, min(d + 1, 3)) {
      ans = max(ans, count4 + (a - count4) / 3 + (b - count4) / 3 +
                         (c - count4) / 3);
    }
    printf("%d\\n", ans);
  }
}

Error: TLE

Fixed submission:

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

#define MOD 1000000007
#define INTMAX 0x7fffffff
#define INTMIN 0x80000000
#define LLMAX 0x7fffffffffffffffLL
#define LLMIN 0x8000000000000000LL

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

using namespace std;
using ll = long long;

int main() {
  while (1) {
    int n[6];
    scanf("%d%d%d%d%d%d", n, n + 1, n + 2, n + 3, n + 4, n + 5);
    if (n[0] + n[1] + n[2] + n[3] + n[4] + n[5] == 0) {
      break;
    }
    int a = n[0] + n[3];
    int b = n[1] + n[4];
    int c = n[2] + n[5];
    int d = min(a, min(b, c));

    int ans = 0;
    rep(count4, d + 1) {
      ans = max(ans, count4 + (a - count4) / 3 + (b - count4) / 3 +
                         (c - count4) / 3);
    }
    printf("%d\\n", ans);
  }
}
Problem p00662 (C++) — buggy submission, verdict: Time Limit Exceeded

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

typedef long long ll;
int A, B, C;

int main() {
  int a, b, c, d, e, f;
  while (cin >> a >> b >> c >> d >> e >> f && (a || b || c || d || e || f)) {
    A = a + d;
    B = b + e;
    C = c + f;
    //    cout<< A << " "<< B << " " << C << endl;
    int n = min(A, min(B, C));
    int res = 0;
    res = max(res, A / 3 + B / 3 + C / 3);
    for (int i = n; i > max(-1, n - 4); i--) {
      res = max(res, i + (A - i) / 3 + (B - i) / 3 + (C - i) / 3);
    }
    cout << res << endl;
  }
}

Error: TLE

Fixed submission:

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

typedef long long ll;
int A, B, C;

int main() {
  int a, b, c, d, e, f;
  while (cin >> a >> b >> c >> d >> e >> f && (a || b || c || d || e || f)) {
    A = a + d;
    B = b + e;
    C = c + f;
    //    cout<< A << " "<< B << " " << C << endl;
    int n = min(A, min(B, C));
    int res = 0;
    res = max(res, A / 3 + B / 3 + C / 3);
    for (int i = n; i > min(-1, n - 4); i--) {
      res = max(res, i + (A - i) / 3 + (B - i) / 3 + (C - i) / 3);
    }
    cout << res << endl;
  }
}