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

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

using i64 = int64_t;

#define rep(i, x, y)                                                           \
  for (i64 i = i64(x), i##_max_for_repmacro = i64(y);                          \
       i < i##_max_for_repmacro; ++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

const int inf = 1.01e9;
const i64 inf64 = 4.01e18;
const double eps = 1e-9;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "[";
  for (const auto &v : vec) {
    os << v << ",";
  }
  os << "]";
  return os;
}

void solve() {
  i64 N, M;
  cin >> N >> M;

  vector<i64> x(N), y(N), z(N);
  vector<int> idx;
  rep(i, 0, N) {
    cin >> x[i] >> y[i] >> z[i];
    idx.push_back(i);
  }

  i64 ans = 0;
  rep(i, 0, 1 << 3) {
    i64 p = (i & 1) ? -1 : 1, q = (i & 2) ? -1 : 1, r = (i & 4) ? -1 : 1;
    sort(begin(idx), end(idx), [&](int a, int b) {
      return p * x[a] + q * y[a] + r * z[a] >= p * x[b] + q * y[b] + r * z[b];
    });

    i64 s = 0, t = 0, u = 0;
    rep(j_, 0, M) {
      int j = idx[j_];
      s += x[j];
      t += y[j];
      u += z[j];
    }
    ans = max(ans, abs(s) + abs(t) + abs(u));
  }

  cout << ans << endl;
}

int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  cout.setf(ios::fixed);
  cout.precision(16);
  solve();
  return 0;
}


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

using i64 = int64_t;

#define rep(i, x, y)                                                           \
  for (i64 i = i64(x), i##_max_for_repmacro = i64(y);                          \
       i < i##_max_for_repmacro; ++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

const int inf = 1.01e9;
const i64 inf64 = 4.01e18;
const double eps = 1e-9;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "[";
  for (const auto &v : vec) {
    os << v << ",";
  }
  os << "]";
  return os;
}

void solve() {
  i64 N, M;
  cin >> N >> M;

  vector<i64> x(N), y(N), z(N);
  vector<int> idx;
  rep(i, 0, N) {
    cin >> x[i] >> y[i] >> z[i];
    idx.push_back(i);
  }

  i64 ans = 0;
  rep(i, 0, 1 << 3) {
    i64 p = (i & 1) ? -1 : 1, q = (i & 2) ? -1 : 1, r = (i & 4) ? -1 : 1;
    sort(begin(idx), end(idx), [&](int a, int b) {
      return p * x[a] + q * y[a] + r * z[a] > p * x[b] + q * y[b] + r * z[b];
    });

    i64 s = 0, t = 0, u = 0;
    rep(j_, 0, M) {
      int j = idx[j_];
      s += x[j];
      t += y[j];
      u += z[j];
    }
    ans = max(ans, abs(s) + abs(t) + abs(u));
  }

  cout << ans << endl;
}

int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  cout.setf(ios::fixed);
  cout.precision(16);
  solve();
  return 0;
}
Problem p03326 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define MEM(a, b) memset((a), (b), sizeof(a))
const LL INF = 1e9 + 7;
const int N = 5e2 + 10;
LL a[N][3];
int main() {
  // freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < 3; j++) {
      cin >> a[i][j];
    }
  }
  LL ans = 0;
  for (int o = 0; o < 8; o++) {
    vector<LL> v;
    for (int i = 1; i <= n; i++) {
      LL sum = 0;
      for (int j = 0; j < 3; j++) {
        if (o >> j & 1)
          sum += a[i][j];
        else
          sum -= a[i][j];
      }
      v.push_back(sum);
    }
    sort(v.rbegin(), v.rend());
    LL res = 0;
    for (int i = 0; i < m; i++)
      res += v[i];
    ans = max(ans, res);
  }
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define MEM(a, b) memset((a), (b), sizeof(a))
const LL INF = 1e9 + 7;
const int N = 1e3 + 10;
LL a[N][3];
int main() {
  // freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < 3; j++) {
      cin >> a[i][j];
    }
  }
  LL ans = 0;
  for (int o = 0; o < 8; o++) {
    vector<LL> v;
    for (int i = 1; i <= n; i++) {
      LL sum = 0;
      for (int j = 0; j < 3; j++) {
        if (o >> j & 1)
          sum += a[i][j];
        else
          sum -= a[i][j];
      }
      v.push_back(sum);
    }
    sort(v.rbegin(), v.rend());
    LL res = 0;
    for (int i = 0; i < m; i++)
      res += v[i];
    ans = max(ans, res);
  }
  cout << ans << endl;
  return 0;
}
Problem p03326 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
  int n, m;
  cin >> n >> m;
  vector<ll> x(n), y(n), z(n);
  for (int i = 0; i < n; i++) {
    cin >> x[i] >> y[i] >> z[i];
  }
  ll r = 0;
  for (auto sx : {-1, 1}) {
    for (auto sy : {-1, 1}) {
      for (auto sz : {-1, 1}) {
        vector<ll> v;
        for (int i = 0; i < n; i++) {
          v[i] = sx * x[i] + sy * y[i] + sz * z[i];
        }
        sort(rbegin(v), rend(v));
        ll s = 0;
        for (int i = 0; i < m; i++) {
          s += v[i];
        }
        r = max(r, s);
      }
    }
  }
  cout << r << endl;
  return 0;
}


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

int main() {
  int n, m;
  cin >> n >> m;
  vector<ll> x(n), y(n), z(n);
  for (int i = 0; i < n; i++) {
    cin >> x[i] >> y[i] >> z[i];
  }
  ll r = 0;
  for (auto sx : {-1, 1}) {
    for (auto sy : {-1, 1}) {
      for (auto sz : {-1, 1}) {
        vector<ll> v(n);
        for (int i = 0; i < n; i++) {
          v[i] = sx * x[i] + sy * y[i] + sz * z[i];
        }
        sort(rbegin(v), rend(v));
        ll s = 0;
        for (int i = 0; i < m; i++) {
          s += v[i];
        }
        r = max(r, s);
      }
    }
  }
  cout << r << endl;
  return 0;
}
Problem p03326 (Python)

Buggy submission (status: Time Limit Exceeded):
# coding: utf-8

n, m = [int(x) for x in input().split()]
xx = []
yy = []
zz = []

for _ in range(n):
    x, y, z = [int(x) for x in input().split()]
    xx.append(x)
    yy.append(y)
    zz.append(z)

result_points = []

for k in range(8):
    max_point = 0
    selected_indexes = []
    for i in range(m):
        max_plus_point = 0
        max_index = 0
        for j in range(n):
            if j in selected_indexes:
                continue
            plus_point = 0
            if k % 2 == 1:
                plus_point += xx[j]
            else:
                plus_point -= xx[j]
            if (k // 2) % 2 == 1:
                plus_point += yy[j]
            else:
                plus_point -= yy[j]
            if (k // 4) % 2 == 1:
                plus_point += zz[j]
            else:
                plus_point -= zz[j]
            if plus_point > max_plus_point:
                max_index = j
                max_plus_point = plus_point
        max_point += max_plus_point
        selected_indexes.append(max_index)
    result_points.append(max_point)

print(max(result_points))


Fixed submission:
# coding: utf-8

n, m = [int(x) for x in input().split()]
xx = []
yy = []
zz = []

for _ in range(n):
    x, y, z = [int(x) for x in input().split()]
    xx.append(x)
    yy.append(y)
    zz.append(z)

result_points = []

results = []

for i in range(8):
    results.append([])
    for j in range(n):
        plus_point = 0
        if i % 2 == 1:
            plus_point += xx[j]
        else:
            plus_point -= xx[j]
        if (i // 2) % 2 == 1:
            plus_point += yy[j]
        else:
            plus_point -= yy[j]
        if (i // 4) % 2 == 1:
            plus_point += zz[j]
        else:
            plus_point -= zz[j]
        results[i].append(plus_point)
    results[i].sort()
    results[i].reverse()

result_points = []

for i in range(8):
    result_points.append(sum(results[i][0:m]))

print(max(result_points))
Problem p03326 (Python)

Buggy submission (status: Runtime Error):
def run(n, m, x, y, z):
    s1 = [x[i] + y[i] + z[i] for i in range(n)]
    s1.sort(reverse=True)
    s2 = [-x[i] + y[i] + z[i] for i in range(n)]
    s2.sort(reverse=True)
    s3 = [x[i] - y[i] + z[i] for i in range(n)]
    s3.sort(reverse=True)
    s4 = [-x[i] - y[i] + z[i] for i in range(n)]
    s4.sort(reverse=True)
    s5 = [x[i] + y[i] - z[i] for i in range(n)]
    s5.sort(reverse=True)
    s6 = [-x[i] + y[i] - z[i] for i in range(n)]
    s6.sort(reverse=True)
    s7 = [x[i] - y[i] - z[i] for i in range(n)]
    s7.sort(reverse=True)
    s8 = [-x[i] - y[i] - z[i] for i in range(n)]
    s8.sort(reverse=True)
    max_sum = sum(s1[0:m])
    tmp_sum = sum(s2[0:m])
    if max_sum < tmp_sum:
        max_sum = tmp_sum
    tmp_sum = sum(s3[0:m])
    if max_sum < tmp_sum:
        max_sum = tmp_sum
    tmp_sum = sum(s4[0:m])
    if max_sum < tmp_sum:
        max_sum = tmp_sum
    tmp_sum = sum(s5[0:m])
    if max_sum < tmp_sum:
        max_sum = tmp_sum
    tmp_sum = sum(s6[0:m])
    if max_sum < tmp_sum:
        max_sum = tmp_sum
    tmp_sum = sum(s7[0:m])
    if max_sum < tmp_sum:
        max_sum = tmp_sum
    tmp_sum = sum(s8[0:m])
    if max_sum < tmp_sum:
        max_sum = tmp_sum
    return max_sum


def read_line():
    n, m = map(int, input().split())
    x = []
    y = []
    z = []
    for i in range(n):
        x[i], y[i], z[i] = map(int, input().split())
    return (n, m, x, y, z)


def main():
    n, m, x, y, z = read_line()
    print(run(n, m, x, y, z))


if __name__ == "__main__":
    main()


Fixed submission:
def run(n, m, x, y, z):
    s1 = [x[i] + y[i] + z[i] for i in range(n)]
    s1.sort(reverse=True)
    s2 = [-x[i] + y[i] + z[i] for i in range(n)]
    s2.sort(reverse=True)
    s3 = [x[i] - y[i] + z[i] for i in range(n)]
    s3.sort(reverse=True)
    s4 = [-x[i] - y[i] + z[i] for i in range(n)]
    s4.sort(reverse=True)
    s5 = [x[i] + y[i] - z[i] for i in range(n)]
    s5.sort(reverse=True)
    s6 = [-x[i] + y[i] - z[i] for i in range(n)]
    s6.sort(reverse=True)
    s7 = [x[i] - y[i] - z[i] for i in range(n)]
    s7.sort(reverse=True)
    s8 = [-x[i] - y[i] - z[i] for i in range(n)]
    s8.sort(reverse=True)
    max_sum = sum(s1[0:m])
    tmp_sum = sum(s2[0:m])
    if max_sum < tmp_sum:
        max_sum = tmp_sum
    tmp_sum = sum(s3[0:m])
    if max_sum < tmp_sum:
        max_sum = tmp_sum
    tmp_sum = sum(s4[0:m])
    if max_sum < tmp_sum:
        max_sum = tmp_sum
    tmp_sum = sum(s5[0:m])
    if max_sum < tmp_sum:
        max_sum = tmp_sum
    tmp_sum = sum(s6[0:m])
    if max_sum < tmp_sum:
        max_sum = tmp_sum
    tmp_sum = sum(s7[0:m])
    if max_sum < tmp_sum:
        max_sum = tmp_sum
    tmp_sum = sum(s8[0:m])
    if max_sum < tmp_sum:
        max_sum = tmp_sum
    return max_sum


def read_line():
    n, m = map(int, input().split())
    x = []
    y = []
    z = []
    for i in range(n):
        tx, ty, tz = map(int, input().split())
        x.append(tx)
        y.append(ty)
        z.append(tz)
    return (n, m, x, y, z)


def main():
    n, m, x, y, z = read_line()
    print(run(n, m, x, y, z))


if __name__ == "__main__":
    main()
Problem p03326 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#pragma GCC optimize(3)
#define CMAX(_a, _b) ((_a < _b) && (_a = _b))
#define R register
using namespace std;
struct node {
  int id;
  long long x;
} A[200010];
bool CMP(node u, node v) { return u.x > v.x; }
long long a[200010][9];
int n, m, K;
long long ans;
int main() {
  scanf("%d%d%d", &n, &m, &K);
  for (R int i = 1; i <= n; i++)
    for (R int j = 1; j <= m; j++)
      scanf("%lld", &a[i][j]);
  for (R int sta = 0; sta < (1 << m); ++sta) {
    for (R int i = 1; i <= n; i++) {
      long long x = 0;
      for (R int j = 1; j <= m; j++) {
        if ((1 << j - 1) & sta)
          x += a[i][j];
        else
          x -= a[i][j];
      }
      A[i].id = i;
      A[i].x = x;
    }
    sort(A + 1, A + n + 1, CMP);
    long long res[9] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
    for (R int i = 1; i <= K; i++)
      for (R int j = 1; j <= m; j++) {
        res[j] += a[A[i].id][j];
      }
    long long Res = 0;
    for (R int i = 1; i <= m; i++)
      Res += abs(res[i]);
    CMAX(ans, Res);
  }
  printf("%lld", ans);
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#pragma GCC optimize(3)
#define CMAX(_a, _b) ((_a < _b) && (_a = _b))
#define R register
using namespace std;
struct node {
  int id;
  long long x;
} A[200010];
bool CMP(node u, node v) { return u.x > v.x; }
long long a[200010][9];
int n, m, K;
long long ans;
int main() {
  scanf("%d%d", &n, &K);
  m = 3;
  for (R int i = 1; i <= n; i++)
    for (R int j = 1; j <= m; j++)
      scanf("%lld", &a[i][j]);
  for (R int sta = 0; sta < (1 << m); ++sta) {
    for (R int i = 1; i <= n; i++) {
      long long x = 0;
      for (R int j = 1; j <= m; j++) {
        if ((1 << j - 1) & sta)
          x += a[i][j];
        else
          x -= a[i][j];
      }
      A[i].id = i;
      A[i].x = x;
    }
    sort(A + 1, A + n + 1, CMP);
    long long res[9] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
    for (R int i = 1; i <= K; i++)
      for (R int j = 1; j <= m; j++) {
        res[j] += a[A[i].id][j];
      }
    long long Res = 0;
    for (R int i = 1; i <= m; i++)
      Res += abs(res[i]);
    CMAX(ans, Res);
  }
  printf("%lld", ans);
  return 0;
}
Problem p03326 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define MD 1000000007
typedef long long int ll;
typedef pair<ll, ll> P;
template <typename T> std::string tostr(const T &t) {
  std::ostringstream os;
  os << t;
  return os.str();
}
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

int main() {
  int n, m;
  cin >> n >> m;
  vector<ll> v1(n), v2(2), v3(n), v4(n), v5(n), v6(n), v7(n), v8(n);
  for (int i = 0; i < n; i++) {
    ll x, y, z;
    cin >> x >> y >> z;
    v1[i] = x + y + z;
    v2[i] = x + y - z;
    v3[i] = x - y + z;
    v4[i] = x - y - z;
    v5[i] = -x + y + z;
    v6[i] = -x + y - z;
    v7[i] = -x - y + z;
    v8[i] = -x - y - z;
  }
  sort(v1.begin(), v1.end());
  sort(v2.begin(), v2.end());
  sort(v3.begin(), v3.end());
  sort(v4.begin(), v4.end());
  sort(v5.begin(), v5.end());
  sort(v6.begin(), v6.end());
  sort(v7.begin(), v7.end());
  sort(v8.begin(), v8.end());
  ll t1 = 0, t2 = 0, t3 = 0, t4 = 0, t5 = 0, t6 = 0, t7 = 0, t8 = 0;
  for (int i = 0; i < m; i++) {
    t1 += v1[n - 1 - i];
    t2 += v2[n - 1 - i];
    t3 += v3[n - 1 - i];
    t4 += v4[n - 1 - i];
    t5 += v5[n - 1 - i];
    t6 += v6[n - 1 - i];
    t7 += v7[n - 1 - i];
    t8 += v8[n - 1 - i];
  }
  cout << max(t1, max(t2, max(t3, max(t4, max(t5, max(t6, max(t7, t8)))))))
       << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define MD 1000000007
typedef long long int ll;
typedef pair<ll, ll> P;
template <typename T> std::string tostr(const T &t) {
  std::ostringstream os;
  os << t;
  return os.str();
}
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

int main() {
  int n, m;
  cin >> n >> m;
  vector<ll> v1(n), v2(n), v3(n), v4(n), v5(n), v6(n), v7(n), v8(n);
  for (int i = 0; i < n; i++) {
    ll x, y, z;
    cin >> x >> y >> z;
    v1[i] = x + y + z;
    v2[i] = x + y - z;
    v3[i] = x - y + z;
    v4[i] = x - y - z;
    v5[i] = -x + y + z;
    v6[i] = -x + y - z;
    v7[i] = -x - y + z;
    v8[i] = -x - y - z;
  }
  sort(v1.begin(), v1.end());
  sort(v2.begin(), v2.end());
  sort(v3.begin(), v3.end());
  sort(v4.begin(), v4.end());
  sort(v5.begin(), v5.end());
  sort(v6.begin(), v6.end());
  sort(v7.begin(), v7.end());
  sort(v8.begin(), v8.end());
  ll t1 = 0, t2 = 0, t3 = 0, t4 = 0, t5 = 0, t6 = 0, t7 = 0, t8 = 0;
  for (int i = 0; i < m; i++) {
    t1 += v1[n - 1 - i];
    t2 += v2[n - 1 - i];
    t3 += v3[n - 1 - i];
    t4 += v4[n - 1 - i];
    t5 += v5[n - 1 - i];
    t6 += v6[n - 1 - i];
    t7 += v7[n - 1 - i];
    t8 += v8[n - 1 - i];
  }
  cout << max(t1, max(t2, max(t3, max(t4, max(t5, max(t6, max(t7, t8)))))))
       << endl;
  return 0;
}
Problem p03326 (C++)

Buggy submission (status: Runtime Error):
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
#define FOR(i, a, b) for (long long i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define ITR(itr, mp) for (auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define dump(x) cout << #x << " = " << (x) << endl;
#define debug(x)                                                               \
  cout << #x << " = " << (x) << " (L" << __LINE__ << ")"                       \
       << " " << __FILE__ << endl;
typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<P> Graph;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  int n, m;
  cin >> n >> m;

  vector<ll> a[8];

  REP(i, n) {
    ll x, y, z;
    cin >> x >> y >> z;
    a[0].push_back(x + y - z);
    a[1].push_back(-x + y - z);
    a[2].push_back(x + y + z);
    a[3].push_back(-x + y + z);
    a[4].push_back(x - y - z);
    a[5].push_back(-x - y - z);
    a[6].push_back(x - y + z);
    a[7].push_back(-x - y + z);
  }

  REP(i, n) { sort(a[i].begin(), a[i].end()); }

  ll ans = 0;

  REP(i, 8) {
    ll sum = 0;
    vector<ll> b;
    REP(j, m) { sum += a[i][n - 1 - j]; }
    ans = max(ans, sum);
  }

  cout << ans << endl;

  return 0;
}

Fixed submission:
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
#define FOR(i, a, b) for (long long i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define ITR(itr, mp) for (auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define dump(x) cout << #x << " = " << (x) << endl;
#define debug(x)                                                               \
  cout << #x << " = " << (x) << " (L" << __LINE__ << ")"                       \
       << " " << __FILE__ << endl;
typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<P> Graph;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  int n, m;
  cin >> n >> m;

  vector<ll> a[8];

  REP(i, n) {
    ll x, y, z;
    cin >> x >> y >> z;
    a[0].push_back(x + y - z);
    a[1].push_back(-x + y - z);
    a[2].push_back(x + y + z);
    a[3].push_back(-x + y + z);
    a[4].push_back(x - y - z);
    a[5].push_back(-x - y - z);
    a[6].push_back(x - y + z);
    a[7].push_back(-x - y + z);
  }

  REP(i, 8) { sort(a[i].begin(), a[i].end()); }

  ll ans = 0;

  REP(i, 8) {
    ll sum = 0;
    vector<ll> b;
    REP(j, m) { sum += a[i][n - 1 - j]; }
    ans = max(ans, sum);
  }

  cout << ans << endl;

  return 0;
}
Problem p03326 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, N) for (int i = 0; i < (int)N; i++)

int N, M;

struct cake {
  ll x, y, z;

  ll ord(const int s) const {
    ll v = (s & 1) ? x : -x;
    v += ((s >> 1) & 1) ? y : -y;
    v += ((s >> 2) & 1) ? z : -z;
    return v;
  }

  ll val() const { return abs(x) + abs(y) + abs(z); }

  const cake operator+(const cake &rhs) const {
    return cake{x + rhs.x, y + rhs.y, z + rhs.z};
  }
};

vector<cake> cakes;

int main() {
  cin >> N >> M;
  cakes.resize(N);
  rep(i, N) cin >> cakes[i].x >> cakes[i].y >> cakes[i].z;

  ll ans = 0;
  for (int s = 0; s < 8; s++) {
    sort(cakes.begin(), cakes.end(),
         [&s](const cake &a, const cake &b) { return a.ord(s) >= b.ord(s); });
    cake c = cake{0, 0, 0};
    rep(i, M) c = c + cakes[i];
    ans = max(ans, c.val());
  }

  cout << ans << endl;

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, N) for (int i = 0; i < (int)N; i++)

int N, M;

struct cake {
  ll x, y, z;

  ll ord(const int s) const {
    ll v = (s & 1) ? x : -x;
    v += ((s >> 1) & 1) ? y : -y;
    v += ((s >> 2) & 1) ? z : -z;
    return v;
  }

  ll val() const { return abs(x) + abs(y) + abs(z); }

  const cake operator+(const cake &rhs) const {
    return cake{x + rhs.x, y + rhs.y, z + rhs.z};
  }
};

vector<cake> cakes;

int main() {
  cin >> N >> M;
  cakes.resize(N);
  rep(i, N) cin >> cakes[i].x >> cakes[i].y >> cakes[i].z;

  ll ans = 0;
  for (int s = 0; s < 8; s++) {
    sort(cakes.begin(), cakes.end(),
         [&s](const cake &a, const cake &b) { return a.ord(s) > b.ord(s); });
    cake c = cake{0, 0, 0};
    rep(i, M) c = c + cakes[i];
    ans = max(ans, c.val());
  }

  cout << ans << endl;

  return 0;
}
Problem p03326 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main(void) {
  int N, M;
  cin >> N >> M;
  ll A[N][3];
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < 3; j++) {
      cin >> A[i][j];
    }
  }

  ll ans = 0;

  for (int i = 0; i < 8; i++) {
    vector<ll> V;
    for (int j = 0; j < N; j++)
      V[j] = 0;

    for (int j = 0; j < N; j++) {
      ll tmp = 0;
      for (int k = 0; k < 3; k++) {
        if ((i & (1 << (2 - k))) != 0)
          tmp += A[j][k];
        else
          tmp -= A[j][k];
      }
      V.push_back(tmp);
    }

    sort(V.begin(), V.end());
    reverse(V.begin(), V.end());
    ll t = 0;
    for (int j = 0; j < M; j++)
      t += V[j];

    ans = max(ans, t);
  }

  cout << ans << endl;
}

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

int main(void) {
  int N, M;
  cin >> N >> M;
  ll A[N][3];
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < 3; j++) {
      cin >> A[i][j];
    }
  }

  ll ans = 0;

  for (int i = 0; i < 8; i++) {
    vector<ll> V;

    for (int j = 0; j < N; j++) {
      ll tmp = 0;
      for (int k = 0; k < 3; k++) {
        if ((i & (1 << (2 - k))) != 0)
          tmp += A[j][k];
        else
          tmp -= A[j][k];
      }
      V.push_back(tmp);
    }

    sort(V.begin(), V.end());
    reverse(V.begin(), V.end());
    ll t = 0;
    for (int j = 0; j < M; j++)
      t += V[j];

    ans = max(ans, t);
  }

  cout << ans << endl;
}
Problem p03326 (C++)

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

int main() {
  long long n, m, a[100009][3], maxn = -(1LL << 60);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < 3; j++)
      cin >> a[i][j];
  }
  for (int i = 0; i < 8; i++) {
    vector<long long> vec;
    for (int j = 1; j <= n; i++) {
      long long sum = 0;
      for (int k = 0; k < 3; k++) {
        if ((i / (1 << k)) % 2 == 0)
          sum += a[j][k];
        else
          sum -= a[j][k];
      }
      vec.push_back(sum);
    }
    sort(vec.begin(), vec.end());
    reverse(vec.begin(), vec.end());
    long long ans = 0;
    for (int j = 0; j < m; j++)
      ans += vec[j];
    maxn = max(maxn, ans);
  }
  cout << maxn << endl;
  return 0;
}

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

int main() {
  long long n, m, a[100009][3], maxn = -(1LL << 60);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < 3; j++)
      cin >> a[i][j];
  }
  for (int i = 0; i < 8; i++) {
    vector<long long> vec;
    for (int j = 1; j <= n; j++) {
      long long sum = 0;
      for (int k = 0; k < 3; k++) {
        if ((i / (1 << k)) % 2 == 0)
          sum += a[j][k];
        else
          sum -= a[j][k];
      }
      vec.push_back(sum);
    }
    sort(vec.begin(), vec.end());
    reverse(vec.begin(), vec.end());
    long long ans = 0;
    for (int j = 0; j < m; j++)
      ans += vec[j];
    maxn = max(maxn, ans);
  }
  cout << maxn << endl;
  return 0;
}
Problem p03326 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define INF 1e16
using namespace std;

typedef long long ll;
ll p[2] = {1, -1};

template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int main() {
  ll N, M;
  cin >> N >> M;
  vector<ll> x(N), y(N), z(N);
  for (int i = 0; i < N; i++) {
    cin >> x[i] >> y[i] >> z[i];
  }

  ll ans = 0;
  for (int i = 0; i < 2; i++) {
    for (int j = 0; j < 2; j++) {
      for (int k = 0; k < 2; k++) {
        vector<vector<ll>> dp(N + 1, vector<ll>(M + 1, -INF));
        dp[0][0] = 0;
        for (int n = 0; n < N; n++) {
          ll X = x[n] * p[i], Y = y[n] * p[j], Z = z[n] * p[k];
          ll sum = X + Y + Z;
          for (int m = 0; m <= M; m++) {
            if (dp[n][m] == -INF)
              continue;
            chmax(dp[n + 1][m], dp[n][m]);
            chmax(dp[n + 1][m + 1], dp[n][m] + sum);
          }
        }
        chmax(ans, dp[N][M]);
      }
    }
  }

  cout << ans << endl;
}


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

typedef long long ll;
ll p[2] = {1, -1};

template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int main() {
  ll N, M;
  cin >> N >> M;
  vector<ll> x(N), y(N), z(N);
  for (int i = 0; i < N; i++) {
    cin >> x[i] >> y[i] >> z[i];
  }

  ll ans = 0;
  for (int i = 0; i < 2; i++) {
    for (int j = 0; j < 2; j++) {
      for (int k = 0; k < 2; k++) {
        vector<vector<ll>> dp(N + 1, vector<ll>(M + 2, -INF));
        dp[0][0] = 0;
        for (int n = 0; n < N; n++) {
          ll X = x[n] * p[i], Y = y[n] * p[j], Z = z[n] * p[k];
          ll sum = X + Y + Z;
          for (int m = 0; m <= M; m++) {
            if (dp[n][m] == -INF)
              continue;
            chmax(dp[n + 1][m], dp[n][m]);
            chmax(dp[n + 1][m + 1], dp[n][m] + sum);
          }
        }
        chmax(ans, dp[N][M]);
      }
    }
  }

  cout << ans << endl;
}
Problem p03327 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

using namespace std;

int n;

int main() {
  scanf("%d", n);

  if (n < 1000) {
    cout << "ABC" << endl;
  } else {
    cout << "ABD" << endl;
  }
}

Fixed submission:
#include <bits/stdc++.h>

using namespace std;

int n;

int main() {
  scanf("%d", &n);

  if (n < 1000) {
    cout << "ABC" << endl;
  } else {
    cout << "ABD" << endl;
  }
}
Problem p03327 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  int i = stoi(s.substr(3, 3));
  if (i <= 999)
    cout << "ABC" << endl;
  else
    cout << "ABD" << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int i;
  cin >> i;
  if (i <= 999)
    cout << "ABC" << endl;
  else
    cout << "ABD" << endl;
}
Problem p03327 (C++)

Buggy submission (status: Runtime Error):
#include <stdio.h>
int main() {
  int n;
  scanf("%d", n);
  if (n >= 1000)
    printf("ABD");
  else
    printf("ABC");
}

Fixed submission:
#include <stdio.h>
int main() {
  int n;
  scanf("%d", &n);
  if (n >= 1000)
    printf("ABD");
  else
    printf("ABC");
}
Problem p03327 (C++)

Buggy submission (status: Runtime Error):
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
ll mod = 1000000007, oo = 1000000009;

void Emsawy() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}

#define clr(v, d) memset(v, d, sizeof(v))
#define sz(v) ((int)((v).size()))
#define all(v) ((v).begin()), ((v).end())
#define allr(v) ((v).rbegin()), ((v).rend())
#define V vector
#define MP make_pair
#define bug(n) cout << #n << " = " << n << endl;
int dx[] = {1, -1, 0, 0, 1, -1, 1, -1};
int dy[] = {0, 0, 1, -1, 1, -1, -1, 1};

V<V<int>> adj;
const ll N = 1000 + 5;
int n, m, k, w;

int main() {

  Emsawy();
  while (cin >> n) {
    if (n < 1000)
      cout << "ABC" << endl;
    else
      cout << "ABD" << endl;
  }
  return 0;
}


Fixed submission:
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
ll mod = 1000000007, oo = 1000000009;

void Emsawy() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}

#define clr(v, d) memset(v, d, sizeof(v))
#define sz(v) ((int)((v).size()))
#define all(v) ((v).begin()), ((v).end())
#define allr(v) ((v).rbegin()), ((v).rend())
#define V vector
#define MP make_pair
#define bug(n) cout << #n << " = " << n << endl;
int dx[] = {1, -1, 0, 0, 1, -1, 1, -1};
int dy[] = {0, 0, 1, -1, 1, -1, -1, 1};

V<V<int>> adj;
const ll N = 1000 + 5;
int n, m, k, w;

int main() {

  // Emsawy();
  while (cin >> n) {
    if (n < 1000)
      cout << "ABC" << endl;
    else
      cout << "ABD" << endl;
  }
  return 0;
}
Problem p03327 (Python)

Buggy submission (status: Runtime Error):
N = input()
if N < 1000:
    print("ABC")
else:
    print("ABD")


Fixed submission:
N = int(input())
if N < 1000:
    print("ABC")
else:
    print("ABD")
Problem p03327 (Python)

Buggy submission (status: Runtime Error):
N = int(input().split())

if N < 1000:
    print("ABC")
else:
    print("ABD")


Fixed submission:
N = int(input())

if N < 1000:
    print("ABC")
else:
    print("ABD")
Problem p03328 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#define rep(i, f, n) for (int i = (f); i < (int)(n); i++)
#define repe(i, f, n) for (int i = (f); i <= (int)(n); i++)
using namespace std;
using ll = long long;
using pint = pair<int, int>;

const int INF = 1001001001;

int main() {
  int a, b;
  cin >> a >> b;

  // 0 1 3 6 10 15
  vector<int> v(b + 1);
  v[0] = 0;

  int mia = INF;
  repe(i, 1, b + 1) {
    v[i] = v[i - 1] + i;
    mia = min(mia, abs(a - v[i]));
  }

  cout << mia << endl;

  return 0;
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#define rep(i, f, n) for (int i = (f); i < (int)(n); i++)
#define repe(i, f, n) for (int i = (f); i <= (int)(n); i++)
using namespace std;
using ll = long long;
using pint = pair<int, int>;

const int INF = 1001001001;

int main() {
  int a, b;
  cin >> a >> b;
  int c = b - a;
  cout << c * (c + 1) / 2 - b << endl;
  return 0;
}
Problem p03328 (C++)

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

typedef long long ll;
int main() {
  //    ll  n,ans=0;
  //    scanf("%lld",&n);
  //    long long  a[20],b[20];
  //    a[0]=9,b[0]=6;
  //    for(int i=1; i<14; i++)
  //    {
  //        a[i]=a[i-1]*9;
  //        b[i]=b[i-1]*6;
  //    }
  //    for(int i=14; i>=0; i--)
  //    {
  //        while(n>=a[i] || n>=b[i])
  //        {
  //            if(n>=a[i])
  //            {
  //                ans++;
  //                n-=a[i];
  //            }
  //            if(n>=b[i])
  //            {
  //                ans++;
  //                n-=b[i];
  //            }
  //        }
  //    }
  //    printf("%lld\n",ans+n);
  int a, b;
  int t[105];
  t[0] = 0;
  for (int i = 1; i < 1005; i++)
    t[i] = t[i - 1] + i;
  cin >> a >> b;
  cout << t[b - a] - b << endl;
  return 0;
}


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

typedef long long ll;
int main() {
  //    ll  n,ans=0;
  //    scanf("%lld",&n);
  //    long long  a[20],b[20];
  //    a[0]=9,b[0]=6;
  //    for(int i=1; i<14; i++)
  //    {
  //        a[i]=a[i-1]*9;
  //        b[i]=b[i-1]*6;
  //    }
  //    for(int i=14; i>=0; i--)
  //    {
  //        while(n>=a[i] || n>=b[i])
  //        {
  //            if(n>=a[i])
  //            {
  //                ans++;
  //                n-=a[i];
  //            }
  //            if(n>=b[i])
  //            {
  //                ans++;
  //                n-=b[i];
  //            }
  //        }
  //    }
  //    printf("%lld\n",ans+n);
  int a, b;
  int t[1010];
  t[0] = 0;
  for (int i = 1; i < 1005; i++)
    t[i] = t[i - 1] + i;
  cin >> a >> b;
  cout << t[b - a] - b << endl;
  return 0;
}
Problem p03328 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < n; i++)

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int a, b;
  cin >> a >> b;

  map<int, int> mp;
  int idx = 1, r = 3, j = 2;
  while (r < 499500) {
    mp[idx] = r;
    idx += j;
    j++;
    r += j;
  }

  REP(i, 10000000) {
    int aa = a + i;
    int bb = b + i;
    if (mp[aa] == bb) {
      cout << i << endl;
      return 0;
    }
  }

  return 0;
}

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int a, b;
  cin >> a >> b;
  cout << (b - a) * (1 + b - a) / 2 - b << endl;

  return 0;
}
Problem p03328 (Python)

Buggy submission (status: Runtime Error):
if int(input()) < 1000:
    print("ABC")
else:
    print("ABD")


Fixed submission:
a, b = map(int, input().split())
n = b - a  # 右の塔はｎ本目
hidari = n * (n - 1) / 2  # 右（ｎ－１本目）の塔の高さ
ans = hidari - a
print(int(ans))
Problem p03328 (Python)

Buggy submission (status: Runtime Error):
a, b = list(map(int, input()))
answer = (b - a) * (b - a + 1) / 2 - b
print(int(answer))


Fixed submission:
a, b = list(map(int, input().split()))
answer = (b - a) * (b - a + 1) / 2 - b
print(int(answer))
Problem p03328 (Python)

Buggy submission (status: Runtime Error):
from sys import stdin
from itertools import accumulate


def main():
    a, b = [int(x) for x in stdin.readline().rstrip().split()]
    c = list(accumulate(range(1, 1000)))
    for i in range(len(c) - 1):
        if (c[i + 1] - c[i]) == (b - a):
            print(f"{c[i] - a}")
            return


if __name__ == "__main__":
    main()


Fixed submission:
from sys import stdin
from itertools import accumulate


def main():
    a, b = [int(x) for x in stdin.readline().rstrip().split()]
    c = list(accumulate(range(1, 1000)))
    for i in range(len(c) - 1):
        if (c[i + 1] - c[i]) == (b - a):
            print(c[i] - a)
            return


if __name__ == "__main__":
    main()
Problem p03328 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bits/stdc++.h>
#include <math.h>
using namespace std;

template <class T> using V = vector<T>;

using ll = long long;
using db = double;
using st = string;
using ch = char;
using vll = V<ll>;
using vpll = V<pair<ll, ll>>;
using vst = V<st>;
using vdb = V<db>;
using vch = V<ch>;

#define FOR(i, a, b) for (ll i = (a); i < (ll)(b); i++)
#define rFOR(i, a, b) for (ll i = (a); i > (ll)(b); i--)
#define oFOR(i, a, b) for (ll i = (a); i < (ll)(b); i += 2)
#define bgn begin()
#define en end()
#define SORT(a) sort((a).bgn, (a).en)
#define REV(a) reverse((a).bgn, (a).en)
#define M(a, b) max(a, b)
#define rM(a, b) min(a, b)
#define fi first
#define se second
#define sz size()
#define gcd(a, b) __gcd(a, b)
#define co(a) cout << a << endl;
#define ci(a) cin >> a;

ll sum(ll n) {
  ll m = 0;
  FOR(i, 0, 20) {
    m += n % 10;
    n /= 10;
    if (n == 0) {
      break;
    }
  }
  return m;
}

ll combi(ll n, ll m) {
  ll ans = 1;
  rFOR(i, n, n - m) { ans *= i; }
  FOR(i, 1, m + 1) { ans /= i; }
  return ans;
}

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

/****************************************\
| Thank you for viewing my code:)        |
| Written by RedSpica a.k.a. RanseMirage |
| Twitter:@asakaakasaka                  |
\****************************************/

signed main() {
  vll A(999);
  A[0] = 1;
  FOR(i, 1, 1000) { A[i] += A[i - 1] + i + 1; }
  ll a, b;
  ci(a >> b);
  co(A[b - a - 1] - b)
}

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

template <class T> using V = vector<T>;

using ll = long long;
using db = double;
using st = string;
using ch = char;
using vll = V<ll>;
using vpll = V<pair<ll, ll>>;
using vst = V<st>;
using vdb = V<db>;
using vch = V<ch>;

#define FOR(i, a, b) for (ll i = (a); i < (ll)(b); i++)
#define rFOR(i, a, b) for (ll i = (a); i > (ll)(b); i--)
#define oFOR(i, a, b) for (ll i = (a); i < (ll)(b); i += 2)
#define bgn begin()
#define en end()
#define SORT(a) sort((a).bgn, (a).en)
#define REV(a) reverse((a).bgn, (a).en)
#define M(a, b) max(a, b)
#define rM(a, b) min(a, b)
#define fi first
#define se second
#define sz size()
#define gcd(a, b) __gcd(a, b)
#define co(a) cout << a << endl;
#define ci(a) cin >> a;

ll sum(ll n) {
  ll m = 0;
  FOR(i, 0, 20) {
    m += n % 10;
    n /= 10;
    if (n == 0) {
      break;
    }
  }
  return m;
}

ll combi(ll n, ll m) {
  ll ans = 1;
  rFOR(i, n, n - m) { ans *= i; }
  FOR(i, 1, m + 1) { ans /= i; }
  return ans;
}

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

/****************************************\
| Thank you for viewing my code:)        |
| Written by RedSpica a.k.a. RanseMirage |
| Twitter:@asakaakasaka                  |
\****************************************/

signed main() {
  vll A(999);
  A[0] = 1;
  FOR(i, 1, 999) { A[i] += A[i - 1] + i + 1; }
  ll a, b;
  ci(a >> b);
  co(A[b - a - 1] - b)
}
Problem p03328 (C++)

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

int main(void) {
  int a, b;
  cin >> a >> b;
  int tower[1000];
  tower[0] = 1;
  for (int i = 2; i < 1000; i++) {
    tower[i - 1] = tower[i - 2] + i;
  }
  int temp;
  for (int i = 0; i < 999; i++) {
    if (tower[i] > a && tower[i + 1] > b) {
      temp = i;
      break;
    }
  }
  int ans = 1;
  while (1) {
    tower[temp] = tower[temp] - 1;
    tower[temp + 1] = tower[temp + 1] - 1;
    if (tower[temp] == a && tower[temp + 1] == b)
      break;
    ans++;
  }
  cout << ans << endl;
  return 0;
}


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

int main(void) {
  int a, b;
  cin >> a >> b;
  int ans = (1 + b - a) * (b - a) / 2 - b;
  cout << ans << endl;
  return 0;
}
Problem p03328 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <cmath>
#include <iostream>
using namespace std;
int main() {
  int a, b;
  cin >> a >> b;
  int ca = 1, cb = 1, sumb = 0, suma = 0;
  while (1) {
    if (suma >= a && sumb >= b) {
      if (suma - a == sumb - b) {
        cout << suma - a;
        break;
      }
    } else if (abs(suma - a) < abs(sumb - b)) {
      //  cout<<"suma is "<<suma<<endl;
      sumb += cb;
      cb++;
    } else {
      // cout<<"sumb is "<<sumb<<endl;
      suma += ca;
      ca++;
    }
  }

  return 0;
}

Fixed submission:
#include <cmath>
#include <iostream>
using namespace std;
int main() {
  int a, b;
  cin >> a >> b;
  int dif = b - a;
  int sum = dif * (dif + 1) / 2;
  cout << sum - b;

  return 0;
}
Problem p03328 (C++)

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

int main() {
  int a, b, log = 0;
  cin >> a >> b;
  int num[999];
  num[0] = 1;
  for (int i = 1; i < 999; i++) {
    num[i] = num[i - 1] + i + 1;
    if (num[i] < a)
      log = i;
  }
  int ans = 0;
  while (true) {
    for (int i = log; ans + num[i] <= a; i++) {
      if (ans + num[i] == a && ans + num[i + 1] == b) {
        cout << ans << endl;
        return 0;
      }
    }
    ans++;
  }
  cout << ans << endl;
}

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

int main() {
  int a, b, log = 0;
  cin >> a >> b;
  int num[999];
  num[0] = 1;
  for (int i = 1; i < 999; i++) {
    num[i] = num[i - 1] + i + 1;
    if (num[i] < a)
      log = i;
  }
  int ans = 0;
  while (num[log] <= a + ans) {
    for (int i = log; num[i] <= a + ans; i++) {
      if (num[i] == a + ans && num[i + 1] == ans + b) {
        cout << ans << endl;
        return 0;
      }
    }
    ans++;
  }
  cout << ans << endl;
}
Problem p03328 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define int long long
using namespace std;

int a, b, A[500000];

signed main() {

  cin >> a >> b;

  A[0] = 1;

  for (int i = 1; i <= 500000; i++)
    A[i] = A[i - 1] + (i + 1);

  for (int i = 0; i < 500000; i++) {
    if (A[i] - a == A[i + 1] - b)
      cout << A[i] - a << endl;
  }

  return 0;
}


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

int a, b, A[500005];

signed main() {

  cin >> a >> b;

  A[0] = 1;

  for (int i = 1; i <= 500000; i++)
    A[i] = A[i - 1] + (i + 1);

  for (int i = 0; i < 500000; i++) {
    if (A[i] - a == A[i + 1] - b)
      cout << A[i] - a << endl;
  }

  return 0;
}
Problem p03328 (C++)

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int a, b;
  cin >> a >> b;
  map<int, int> mp;
  for (int i = 1, cur = 0; i <= 105; i++) {
    cur += i;
    mp[cur] = i;
  }
  int cnt = 1;
  while (1) {
    if (mp[a + cnt] + 1 == mp[b + cnt])
      break;
    cnt++;
  }
  cout << cnt << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int a, b;
  cin >> a >> b;
  int t = b - a;
  int n1 = t * (t - 1) / 2, n2 = t * (t + 1) / 2;
  cout << n1 - a << endl;
  return 0;
}
Problem p03329 (C++)

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

int N;

int sub(int base, int num, int current) {
  if (num == 0) {
    // cout << N - current << endl;
    return N - current;
  } else {
    int min = 1000;
    for (int i = 0; i < base; i++) {
      if (current + pow(base, num) * i > N) {
        break;
      }
      int nextBase = 6;
      int nextNum = num;
      if (base == 6) {
        nextBase = 9;
        nextNum--;
      }
      int temp = sub(nextBase, nextNum, current + pow(base, num) * i);
      if (temp + i < min) {
        min = temp + i;
      }
    }
    return min;
  }
}

int main() {
  cin >> N;
  int result = 0;

  result = sub(9, 6, 0);

  cout << result << endl;

  return 0;
}

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

int N;

int sub(int base, int num, int current) {
  if (num == 0) {
    // cout << N - current << endl;
    return N - current;
  } else {
    int min = 1000;

    // ashikiri
    if ((N - current) / pow(base, num) > pow(base, 2)) {
      return N - current;
    }

    for (int i = 0; i < base; i++) {
      if (current + pow(base, num) * i > N) {
        break;
      }
      int nextBase = 6;
      int nextNum = num;
      if (base == 6) {
        nextBase = 9;
        nextNum--;
      }
      int temp = sub(nextBase, nextNum, current + pow(base, num) * i);
      if (temp + i < min) {
        min = temp + i;
      }
    }
    return min;
  }
}

int main() {
  cin >> N;
  int result = 0;

  result = sub(9, 6, 0);

  cout << result << endl;

  return 0;
}
Problem p03329 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;
  long long dp[114514];
  for (int i = 0; i <= n; i++) {
    dp[i] = 1e9;
  }
  dp[0] = 0;
  for (int i = 0; i < n; i++) {
    dp[i + 1] = min(dp[i + 1], dp[i] + 1);
    for (int j = 6; j <= n; j *= 6) {
      dp[i + j] = min(dp[i + j], dp[i] + 1);
    }
    for (int j = 9; j <= n; j *= 9) {
      dp[i + j] = min(dp[i + j], dp[i] + 1);
    }
  }
  cout << dp[n] << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;
  long long dp[1000000];
  for (int i = 0; i <= n; i++) {
    dp[i] = 1e9;
  }
  dp[0] = 0;
  for (int i = 0; i < n; i++) {
    dp[i + 1] = min(dp[i + 1], dp[i] + 1);
    for (int j = 6; j <= n; j *= 6) {
      dp[i + j] = min(dp[i + j], dp[i] + 1);
    }
    for (int j = 9; j <= n; j *= 9) {
      dp[i + j] = min(dp[i + j], dp[i] + 1);
    }
  }
  cout << dp[n] << endl;
  return 0;
}
Problem p03329 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>

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

int main() {
  int N;
  vector<int> T(100000, 100001);
  vector<int> mv = {1};
  T[0] = 0;
  cin >> N;
  for (int i = 6; i <= N; i *= 6)
    mv.push_back(i);
  for (int i = 9; i <= N; i *= 9)
    mv.push_back(i);
  for (int i = 0; i < N; i++) {
    for (int m = 0; m < mv.size(); m++) {
      T[i + mv[m]] = min(T[i + mv[m]], T[i] + 1);
    }
  }
  cout << T[N] << endl;
}

Fixed submission:
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>

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

int main() {
  int N;
  vector<int> T(200000, 100001);
  vector<int> mv = {1};
  T[0] = 0;
  cin >> N;
  for (int i = 6; i <= N; i *= 6)
    mv.push_back(i);
  for (int i = 9; i <= N; i *= 9)
    mv.push_back(i);
  for (int i = 0; i < N; i++) {
    for (int m = 0; m < mv.size(); m++) {
      T[i + mv[m]] = min(T[i + mv[m]], T[i] + 1);
    }
  }
  cout << T[N] << endl;
}
Problem p03329 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <vector>

#define REP(i, n) for (int i = 0; i < n; i++)
#define REP2(i, s, n) for (int i = s; i < n; i++)
#define REP_1(i, n) for (int i = 1; i < n + 1; i++)
using namespace std;
typedef long long ll;
typedef unsigned long ul;
typedef long double ld;

template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

ll INF = 1000000000;
ll dp[100100];

int main() {
  ll N;
  cin >> N;
  REP(i, N + 1) { dp[i] = INF; }
  dp[0] = 0;
  REP(i, N + 1) {
    chmin(dp[i + 1], dp[i] + 1);
    ll c6 = 6, c9 = 9;
    while (c6 <= N) {
      chmin(dp[i + c6], dp[i] + 1);
      c6 *= 6;
    }
    while (c9 <= N) {
      chmin(dp[i + c9], dp[i] + 1);
      c9 *= 9;
    }
  }
  cout << dp[N] << endl;
}

Fixed submission:
#include <algorithm>
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <vector>

#define REP(i, n) for (int i = 0; i < n; i++)
#define REP2(i, s, n) for (int i = s; i < n; i++)
#define REP_1(i, n) for (int i = 1; i < n + 1; i++)
using namespace std;
typedef long long ll;
typedef unsigned long ul;
typedef long double ld;

template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

ll INF = 1000000000;
ll dp[1000000];

int main() {
  ll N;
  cin >> N;
  REP(i, N + 1) { dp[i] = INF; }
  dp[0] = 0;
  REP(i, N + 1) {
    chmin(dp[i + 1], dp[i] + 1);
    ll c6 = 6, c9 = 9;
    while (c6 <= N) {
      chmin(dp[i + c6], dp[i] + 1);
      c6 *= 6;
    }
    while (c9 <= N) {
      chmin(dp[i + c9], dp[i] + 1);
      c9 *= 9;
    }
  }
  cout << dp[N] << endl;
}