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

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <random>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)n; i++)

int main() {
  int a, b, k;
  cin >> a >> b >> k;
  vector<int> n(b - a + 1);
  int size = b - a + 1;
  rep(i, size) { n[i] = a++; }
  for (int i = 0; i < min(k, size); i++) {
    cout << n[i] << endl;
  }
  for (int i = max(k, size - k); i < size; i++) {
    cout << n[i] << endl;
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <random>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)n; i++)

int main() {
  int a, b, k;
  cin >> a >> b >> k;
  for (int i = a; i <= min(b, a + k - 1); i++)
    cout << i << endl;
  for (int i = max(b - k + 1, a + k); i <= b; i++)
    cout << i << endl;
  return 0;
}
Problem p03386 (Python)

Buggy submission (status: Runtime Error):
a, b, k = map(int, input().split())

num = list(range(a, b + 1))

a_k = num[:k]
k_e = num[-k:]

# print(a_k, k_e)
ans_set = set(a_k + k_e)
ans_list = list(ans_set)
ans_list.sort()
for i in ans_list:
    print(i)


Fixed submission:
a, b, k = map(int, input().split())
r = range(a, b + 1)
for i in sorted(set(r[:k]) | set(r[-k:])):
    print(i)
Problem p03386 (Python)

Buggy submission (status: Runtime Error):
a, b, k = map(int, input().split())

z = list(range(a, b + 1))
ans = sorted(list(set(z[:k]) | set(z[-k:])))
for x in ans:
    print(x)


Fixed submission:
a, b, k = map(int, input().split())

for i in range(a, min(a + k, b - k + 1)):
    print(i)
for i in range(max(a, b - k + 1), b + 1):
    print(i)
Problem p03386 (Python)

Buggy submission (status: Time Limit Exceeded):
#!/usr/bin/env python3
A, B, K = map(int, input().split())
for i in range(A, B + 1):
    if i < A + K or B - K < i:
        print(i)


Fixed submission:
#!/usr/bin/env python3
A, B, K = map(int, input().split())
for i in range(A, min(B + 1, A + K)):
    print(i)
for i in range(max(0, B - K + 1), B + 1):
    if i < A + K:
        continue
    print(i)
Problem p03386 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int A, B, K;
  cin >> A >> B >> K;
  if (K > B - A)
    K = B - A;
  set<int> opt;
  for (int i = 0; i < K; i++)
    opt.insert(A + i);
  for (int i = 0; i < K; i++)
    opt.insert(B - i);
  vector<int> vec(opt.begin(), opt.end());
  cout << vec.at(0);
  for (int i = 1; i < vec.size(); i++)
    cout << endl << vec.at(i);
  cout << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int A, B, K;
  cin >> A >> B >> K;
  if (K > B - A)
    K = B - A + 1;
  set<int> opt;
  for (int i = 0; i < K; i++)
    opt.insert(A + i);
  for (int i = 0; i < K; i++)
    opt.insert(B - i);
  vector<int> vec(opt.begin(), opt.end());
  cout << vec.at(0);
  for (int i = 1; i < vec.size(); i++)
    cout << endl << vec.at(i);
  cout << endl;
}
Problem p03386 (Python)

Buggy submission (status: Runtime Error):
A, B, K = map(int, input().split())
for n in sorted({*range(A, A + K), *range(B - K + 1, B + 1)}):
    print(n)


Fixed submission:
A, B, K = map(int, input().split())
for n in sorted(
    filter(lambda n: A <= n <= B, set(range(A, A + K)) | set(range(B - K + 1, B + 1)))
):
    print(n)
Problem p03386 (C++)

Buggy submission (status: Time Limit Exceeded):
#include "algorithm"
#include "iostream"
#include "set"
#include "string"

using namespace std;

long long int N, M, K, L, R, H, W;

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

  cin >> N >> M >> K;
  set<int> s;
  for (int i = N; i <= min(M, N + K - 1); i++) {
    s.insert(i);
  }
  for (int i = M; i >= max(N, M - K + 1); i++) {
    s.insert(i);
  }
  for (auto i : s) {
    cout << i << endl;
  }
  return 0;
}

Fixed submission:
#include "algorithm"
#include "iostream"
#include "set"
#include "string"

using namespace std;

long long int N, M, K, L, R, H, W;

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

  cin >> N >> M >> K;
  set<int> s;
  for (int i = N; i <= min(M, N + K - 1); i++) {
    s.insert(i);
  }
  for (int i = M; i >= max(N, M - K + 1); i--) {
    s.insert(i);
  }
  for (auto i : s) {
    cout << i << endl;
  }
  return 0;
}
Problem p03386 (Python)

Buggy submission (status: Runtime Error):
A, B, K = map(int, input().split())
nums = []
num_range = list(range(A, B + 1))
if A == B:
    print(A)
else:
    for i in range(K if len(num_range) > K else len(num_range)):
        nums.append(num_range[i])
        nums.append(num_range[-(i + 1)])
    for num in sorted(list(set(nums))):
        print(num)


Fixed submission:
A, B, K = map(int, input().split())
num_range = range(A, B + 1)
for i in sorted(set(num_range[:K]) | set(num_range[-K:])):
    print(i)
Problem p03386 (Python)

Buggy submission (status: Time Limit Exceeded):
A, B, K = map(int, input().split())
for i in range(A, B + 1):
    if i - A < K or B - i < K:
        print(i)


Fixed submission:
A, B, K = map(int, input().split())
ret = range(A, B + 1)
for i in sorted(set(ret[:K]) | set(ret[-K:])):
    print(i)
Problem p03386 (Python)

Buggy submission (status: Time Limit Exceeded):
a, b, k = map(int, input().split())
r = [x for x in range(a, b + 1)]
for x in sorted(set(r[:k]) | set(r[-k:])):
    print(x)


Fixed submission:
a, b, k = map(int, input().split())
r = range(a, b + 1)
for x in sorted(set(r[:k]) | set(r[-k:])):
    print(x)
Problem p03386 (Python)

Buggy submission (status: Time Limit Exceeded):
text = input()

a = int(text.split(" ")[0])
b = int(text.split(" ")[1])
k = int(text.split(" ")[2])

for i in range(a, b + 1):
    if i < a + k or i > b - k:
        print(i)


Fixed submission:
text = input()

a = int(text.split(" ")[0])
b = int(text.split(" ")[1])
k = int(text.split(" ")[2])

t = min(a + k, b + 1)
for i in range(a, t):
    print(i)

if max(b - k + 1, t) < b + 1:
    for i in range(max(b - k + 1, t), b + 1):
        print(i)
Problem p03386 (C++)

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

int main(int argc, char const *argv[]) {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  // freopen("output.txt","w",stdout);
#endif
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(0);
  int a, b, k;
  cin >> a >> b >> k;
  for (int i = a; i < a + k && i <= b; i++)
    cout << i << endl;
  for (int i = b - k + 1; i <= b; i++) {
    if (i < a + k)
      continue;
    cout << i << endl;
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'

int main(int argc, char const *argv[]) {
  /*#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
  #endif */
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(0);
  int a, b, k;
  cin >> a >> b >> k;
  for (int i = a; i < a + k && i <= b; i++)
    cout << i << endl;
  for (int i = b - k + 1; i <= b; i++) {
    if (i < a + k)
      continue;
    cout << i << endl;
  }
}
Problem p03386 (C++)

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

int main() {
  ll A, B, K;
  vector<ll> num(300, 0);
  vector<ll> num2(300, 0);
  cin >> A >> B >> K;

  for (int i = A; i < min(B, A + K); i++) {
    num[i - A] = 1;
  }
  if (B - A <= 100) {
    for (int i = A; i < min(B, A + K); i++) {
      num[i - A] = 1;
    }
    for (int i = B - K + 1; i <= B; i++) {
      num[i - A] = 1;
    }

    for (int i = A; i <= B; i++) {
      if (num[i - A] == 1)
        cout << i << endl;
    }
    return 0;
  } else {
    for (int i = B - K + 1; i <= B; i++) {
      num2[i - (B - K + 1)] = 1;
    }

    for (int i = A; i <= A + K; i++) {
      if (num[i - A] == 1)
        cout << i << endl;
    }

    for (int i = B - K + 1; i <= B; i++) {
      if (num2[i - (B - K + 1)] == 1)
        cout << i << endl;
    }
  }
}


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

int main() {
  ll A, B, K;
  vector<ll> num(300, 0);
  vector<ll> num2(300, 0);
  cin >> A >> B >> K;

  for (int i = A; i < min(B, A + K); i++) {
    num[i - A] = 1;
  }
  if (B - A <= 100) {
    for (int i = A; i < min(B, A + K); i++) {
      num[i - A] = 1;
    }
    for (int i = max(A, B - K + 1); i <= B; i++) {
      num[i - A] = 1;
    }

    for (int i = A; i <= B; i++) {
      if (num[i - A] == 1)
        cout << i << endl;
    }
    return 0;
  } else {
    for (int i = B - K + 1; i <= B; i++) {
      num2[i - (B - K + 1)] = 1;
    }

    for (int i = A; i <= A + K; i++) {
      if (num[i - A] == 1)
        cout << i << endl;
    }

    for (int i = B - K + 1; i <= B; i++) {
      if (num2[i - (B - K + 1)] == 1)
        cout << i << endl;
    }
  }
}
Problem p03386 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;

int main() {
  long a, b, k;
  cin >> a >> b >> k;
  long len = b - a + 1;
  long n[len];
  long i = 0;
  while (i < len) {
    n[i] = a + i;
    i++;
  }
  i = 0;
  if (len <= 2 * k) {
    while (i < len)
      cout << n[i++] << endl;
  } else {
    while (i < len) {
      if (i < k)
        cout << n[i] << endl;
      else if (i >= (len - k))
        cout << n[i] << endl;
      i++;
    }
  }
  return (0);
}


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

int main() {
  long a, b, k;
  cin >> a >> b >> k;
  for (long i = a; i <= min(b, a + k - 1); i++)
    cout << i << endl;
  for (long i = max(b - k + 1, a + k); i <= b; i++)
    cout << i << endl;
  return (0);
}
Problem p03386 (C++)

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

int main(void) {
  long long A, B, K;
  cin >> A >> B >> K;
  vector<long long> ans(B + 1, 0);
  for (long long i = A; i <= B; i++) {
    if (i <= A + K - 1 || i >= B - K + 1) {
      cout << i << endl;
    }
  }
  return 0;
}

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

int main(void) {
  long long A, B, K;
  cin >> A >> B >> K;
  for (long long i = A; i <= B; i++) {
    if (i <= A + K - 1 || i >= B - K + 1) {
      cout << i << endl;
    }
  }
  return 0;
}
Problem p03386 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, f, n) for (ll i = (f); i < (ll)(n); i++)
#define repe(i, f, n) for (ll i = (f); i <= (ll)(n); i++)
using namespace std;
using ll = long long;
using pint = pair<int, int>;

int main() {
  int A, B, K;
  cin >> A >> B >> K;
  vector<int> v(B + 1, 0);
  int cnt = 1;
  repe(i, A, B) {
    if (cnt <= K) {
      v[i]++;
      cnt++;
      continue;
    }
    break;
  }

  cnt = 1;
  for (int i = B; i >= A; i--) {
    if (cnt <= K) {
      v[i]++;
      cnt++;
      continue;
    }
    break;
  }

  repe(i, A, B) if (v[i] > 0) cout << i << endl;

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define rep(i, f, n) for (ll i = (f); i < (ll)(n); i++)
#define repe(i, f, n) for (ll i = (f); i <= (ll)(n); i++)
using namespace std;
using ll = long long;
using pint = pair<int, int>;

int main() {
  int A, B, K;
  cin >> A >> B >> K;
  for (int i = A; i <= min(B, A + K - 1); i++)
    cout << i << endl;
  for (int i = max(B - K + 1, A + K); i <= B; i++)
    cout << i << endl;
  return 0;
}
Problem p03386 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
#define FOR(i, a, b) for (int i = a; i < b; ++i)
using namespace std;

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

  int a, b, k;
  cin >> a >> b >> k;
  FOR(i, a, b + 1) {
    cout << i << endl;
    if (i == a + k - 1) {
      if (i == b - k + 1)
        i = b - k + 1;
      else
        i = b - k;
    }
  }
}

Fixed submission:
#include <iostream>
#define FOR(i, a, b) for (int i = a; i < b; ++i)
using namespace std;

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

  int a, b, k;
  cin >> a >> b >> k;
  FOR(i, a, min(a + k, b + 1)) cout << i << endl;
  FOR(i, max(a + k, b - k + 1), b + 1) cout << i << endl;
}
Problem p03386 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>

using namespace std;

int main() {
  while (1) {
    int a, b, k;
    cin >> a >> b >> k;
    for (int i = a; i <= b; i++) {
      if ((i - a) < k || (b - i) < k)
        cout << i << endl;
    }
  }
  return 0;
}


Fixed submission:
#include <iostream>

using namespace std;

int main() {
  int a, b, k;
  cin >> a >> b >> k;
  for (int i = a; i <= b; i++) {
    if ((i - a) < k || (b - i) < k)
      cout << i << endl;
  }
  return 0;
}
Problem p03386 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> llP;

int main() {
  int a, b, k;
  cin >> a >> b >> k;
  if (a + k - 1 >= b - k + 1) {
    for (int i = a; i <= b; i++) {
      cout << i << endl;
    }
  } else {
    for (int i = a; i <= a + k - 1; i++) {
      cout << i << endl;
    }
    for (int i = b - k + 1; i = b; i++) {
      cout << i << endl;
    }
  }
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> llP;

int main() {
  int a, b, k;
  cin >> a >> b >> k;
  if (a + k - 1 >= b - k + 1) {
    for (int i = a; i <= b; i++) {
      cout << i << endl;
    }
  } else {
    for (int i = a; i <= a + k - 1; i++) {
      cout << i << endl;
    }
    for (int i = b - k + 1; i <= b; i++) {
      cout << i << endl;
    }
  }
  return 0;
}
Problem p03386 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
const long double PI = (acos(-1));
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
int ctoi(char c) {
  switch (c) {
  case '0':
    return 0;
  case '1':
    return 1;
  case '2':
    return 2;
  case '3':
    return 3;
  case '4':
    return 4;
  case '5':
    return 5;
  case '6':
    return 6;
  case '7':
    return 7;
  case '8':
    return 8;
  case '9':
    return 9;
  default:
    return 0;
  }
}
int main() {
  int a, b, k;
  cin >> a >> b >> k;
  if (b >= k) {
    k = b;
  }
  vector<pair<int, int>> vec;
  for (int i = a; i <= b; i++) {
    vec.emplace_back(i, 0);
  }
  for (int i = 0; i < k; i++) {
    vec[i].second = 1;
  }
  for (int i = vec.size() - 1; i > vec.size() - 1 - k; i--) {
    vec[i].second = 1;
  }
  for (int i = 0; i < vec.size(); i++) {
    if (vec[i].second == 1) {
      cout << vec[i].first << endl;
    }
  }
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
const long double PI = (acos(-1));
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
int ctoi(char c) {
  switch (c) {
  case '0':
    return 0;
  case '1':
    return 1;
  case '2':
    return 2;
  case '3':
    return 3;
  case '4':
    return 4;
  case '5':
    return 5;
  case '6':
    return 6;
  case '7':
    return 7;
  case '8':
    return 8;
  case '9':
    return 9;
  default:
    return 0;
  }
}
int main() {
  int a, b, k;
  cin >> a >> b >> k;
  if (b - a + 1 >= 2 * k) {
    for (int i = 0; i < k; i++) {
      cout << a + i << endl;
    }
    for (int i = k - 1; i >= 0; i--) {
      cout << b - i << endl;
    }
  } else {
    for (int i = a; i <= b; i++) {
      cout << i << endl;
    }
  }
}
Problem p03386 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define whole(f, x, ...)                                                       \
  ([&](decltype((x)) whole) {                                                  \
    return (f)(begin(whole), end(whole), ##__VA_ARGS__);                       \
  })(x) // decltypeで型取得、引数があればva_argsのところに入れる
using namespace std;
typedef long long ll; // long longをllでかけるようにした
const int INF = 1e9;

int main(void) {
  int a, b, k;
  cin >> a >> b >> k;
  if (k > b)
    k = b - 1;
  vector<int> ans(0);
  for (int i = a; i < k + a; i++)
    ans.push_back(i);
  int num = b - k + 1;
  if (num <= ans.back())
    num = ans.back() + 1;
  for (int i = num; i <= b; i++)
    ans.push_back(i);
  REP(i, ans.size()) cout << ans[i] << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define whole(f, x, ...)                                                       \
  ([&](decltype((x)) whole) {                                                  \
    return (f)(begin(whole), end(whole), ##__VA_ARGS__);                       \
  })(x) // decltypeで型取得、引数があればva_argsのところに入れる
using namespace std;
typedef long long ll; // long longをllでかけるようにした
const int INF = 1e9;

int main(void) {
  int a, b, k;
  cin >> a >> b >> k;
  if (a == b) {
    cout << a << endl;
    return 0;
  }
  if (k > b or b - a < k) {
    for (int i = a; i <= b; i++)
      cout << i << endl;
    return 0;
  }
  vector<int> ans(0);
  for (int i = a; i < k + a; i++)
    ans.push_back(i);
  int num = b - k + 1;
  if (num <= ans.back())
    num = ans.back() + 1;
  for (int i = num; i <= b; i++)
    ans.push_back(i);
  REP(i, ans.size()) cout << ans[i] << endl;
}
Problem p03386 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <stack>
#include <string>
#include <vector>

using namespace std;
#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(i, s, n) for (int i = (s); i < (n); i++)
#define repr(i, n) for (int i = n - 1; i >= 0; i--)
#define REPR(i, s, n) for (int i = (s); i >= (g); (i)--)
#define all(a) (a).begin(), (a).end()
#define reall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define pf push_front
#define MIN(a, b) a = min((a), (b))
#define MAX(a, b) a = max((a), (b))
#define SIZE(v) (int)v.size()
const double pi = acos(-1.0);

typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef deque<ll> dll;
ll mod = 1e9 + 7;

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

  int a, b, c;
  cin >> a >> b >> c;
  map<int, int> x;
  rep(i, c) { x[a + i]++; }
  repr(i, c) { x[b - i]++; }
  rep(i, x.size()) {
    if (x[i] > 0)
      cout << i << endl;
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <stack>
#include <string>
#include <vector>

using namespace std;
#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(i, s, n) for (int i = (s); i < (n); i++)
#define repr(i, n) for (int i = n - 1; i >= 0; i--)
#define REPR(i, s, n) for (int i = (s); i >= (g); (i)--)
#define all(a) (a).begin(), (a).end()
#define reall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define pf push_front
#define MIN(a, b) a = min((a), (b))
#define MAX(a, b) a = max((a), (b))
#define SIZE(v) (int)v.size()
const double pi = acos(-1.0);

typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef deque<ll> dll;
ll mod = 1e9 + 7;

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

  int a, b, c;
  cin >> a >> b >> c;
  vi v;
  v.pb(0);
  rep(i, c) {
    int x = a + i;
    if (x >= a && x <= b)
      v.pb(x);
  }
  repr(i, c) {
    int x = b - i;
    if (x >= a && x <= b)
      v.pb(x);
  }
  sort(all(v));
  REP(i, 1, v.size()) {
    if (v[i - 1] != v[i])
      cout << v[i] << endl;
  }
  return 0;
}
Problem p03386 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#include <algorithm>
#include <complex>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#include <cassert>
#include <functional>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

template <typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}

template <typename T> ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v)
    out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000007              // 1e9+7(prime number)
#define INF 1000000000              // 1e9
#define LLINF 2000000000000000000LL // 2e18
#define SIZE 200010

int main() {
  int A, B, K;

  cin >> A >> B >> K;

  for (int i = A; i <= B; i++) {
    if (i < A + K || B - K < i) {
      printf("%d\n", i);
    } else {
      i = B - K - 1;
    }
  }

  return 0;
}


Fixed submission:
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#include <algorithm>
#include <complex>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#include <cassert>
#include <functional>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

template <typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}

template <typename T> ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v)
    out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000007              // 1e9+7(prime number)
#define INF 1000000000              // 1e9
#define LLINF 2000000000000000000LL // 2e18
#define SIZE 200010

int main() {
  int A, B, K;

  cin >> A >> B >> K;

  for (int i = A; i <= B; i++) {
    if (i < A + K || B - K < i) {
      printf("%d\n", i);
    } else {
      i = B - K;
    }
  }

  return 0;
}
Problem p03386 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
using namespace std;
int main() {
  int a, b, c, i;
  cin >> a >> b >> c;
  for (i = a; i <= b; ++a)
    if (i - c <= 0 || i + c >= b)
      cout << i << "\n";
  cout << endl;
}

Fixed submission:
#include <iostream>
using namespace std;
int main() {
  int a, b, c, i;
  cin >> a >> b >> c;
  for (i = a; i <= b; ++i)
    if (i - a < c || i + c > b)
      cout << i << "\n";
  cout << endl;
}
Problem p03386 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <math.h>
#include <string.h>
#include <string>
using namespace std;

int main() {
  int A, B, K, j = 0, ans[100] = {};
  cin >> A >> B >> K;
  for (int i = A; i < min(B + 1, A + K); i++) {
    ans[j] = i;
    j++;
  }
  for (int i = max(B - K + 1, A + K); i < B + 1; i++) {
    ans[j] = i;
    j++;
  }
  for (int i = 0; i < j; i++) {
    cout << ans[i] << endl;
  }
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <math.h>
#include <string.h>
#include <string>
using namespace std;

int main() {
  int A, B, K, j = 0, ans[200] = {};
  cin >> A >> B >> K;
  for (int i = A; i < min(B + 1, A + K); i++) {
    ans[j] = i;
    j++;
  }
  for (int i = max(B - K + 1, A + K); i < B + 1; i++) {
    ans[j] = i;
    j++;
  }
  for (int i = 0; i < j; i++) {
    cout << ans[i] << endl;
  }
}
Problem p03386 (Python)

Buggy submission (status: Time Limit Exceeded):
def resolve():
    A, B, K = [int(i) for i in input().split()]
    numbers = [i for i in range(A, B + 1)]
    ans = numbers[:K]
    ans.extend(numbers[-K:])
    print(*sorted(set(ans)), sep="\n")


resolve()


Fixed submission:
def resolve():
    A, B, K = [int(i) for i in input().split()]
    offset = 0
    while offset < K and A + offset <= B:
        print(A + offset)
        offset += 1
    begin = A + offset
    r = max(B - K + 1, begin)
    while r <= B:
        print(r)
        r += 1


resolve()
Problem p03387 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b, c;
  cin >> a >> b >> c;

  int a1, b1, c1;
  a1 = a % 2;
  b1 = b % 2;
  c1 = c % 2;
  int st = 0;
  while (a1 != b1 || b1 != c1 || c1 != a1) {
    if (a1 == b1) {
      a1++;
      b1++;
      a++;
      b++;
      st++;
    } else if (b1 == c1) {
      b1++;
      c1++;
      c++;
      b++;
      st++;
    } else if (c1 == a1) {
      a1++;
      c1++;
      a++;
      c++;
      st++;
    }
  }
  int ma = max(a, max(b, c));
  st += (ma - a) / 2;
  st += (ma - b) / 2;
  st += (ma - c) / 2;
  cout << st << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b, c;
  cin >> a >> b >> c;

  int a1, b1, c1;
  a1 = a % 2;
  b1 = b % 2;
  c1 = c % 2;
  int st = 0;
  if (a1 == b1 && b1 == c1) {
    st += 0;
  } else if (a1 == b1) {
    a++;
    b++;
    st++;
  } else if (b1 == c1) {
    c++;
    b++;
    st++;
  } else if (c1 == a1) {
    a++;
    c++;
    st++;
  }
  int ma = max(a, max(b, c));
  st += (ma - a) / 2;
  st += (ma - b) / 2;
  st += (ma - c) / 2;
  cout << st << endl;
}
Problem p03387 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
int m[111][111][111];
int a, b, c;
int f(int x, int y, int z) {
  if (x > 100 || y > 100 || z > 100)
    return 1e9;
  if (x == y && y == z && z == x)
    return 0;
  auto &r = m[x][y][z];
  if (r == -1) {
    r = min(r, f(x + 1, y + 1, z));
    r = min(r, f(x, y + 1, z + 1));
    r = min(r, f(x + 1, y, z + 1));
    r = min(r, f(x + 2, y, z));
    r = min(r, f(x, y + 2, z));
    r = min(r, f(x, y, z + 2));
  }
  return r;
}
int main() {
  for (int i = 0; i < 101; i++)
    for (int j = 0; j < 101; j++)
      for (int k = 0; k < 101; k++)
        m[i][j][k] = -1;
  cin >> a >> b >> c;
  cout << f(a, b, c) << '\n';
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int m[111][111][111];
int a, b, c;
int f(int x, int y, int z) {
  if (x > 100 || y > 100 || z > 100)
    return 1e9;
  if (x == y && y == z && z == x)
    return 0;
  auto &r = m[x][y][z];
  if (r == -1) {
    r = 1e9;
    r = min(r, f(x + 1, y + 1, z) + 1);
    r = min(r, f(x, y + 1, z + 1) + 1);
    r = min(r, f(x + 1, y, z + 1) + 1);
    r = min(r, f(x + 2, y, z) + 1);
    r = min(r, f(x, y + 2, z) + 1);
    r = min(r, f(x, y, z + 2) + 1);
  }
  return r;
}
int main() {
  for (int i = 0; i < 101; i++)
    for (int j = 0; j < 101; j++)
      for (int k = 0; k < 101; k++)
        m[i][j][k] = -1;
  cin >> a >> b >> c;
  cout << f(a, b, c) << '\n';
}
Problem p03387 (C++)

Buggy submission (status: Runtime Error):

#include <bits/stdc++.h>
using namespace std;
int ans = 987654321;
int dp[51][51][51];
int f(int a, int b, int c) {
  // printf("%d %d %d\n", a, b, c);

  if (dp[a][b][c] > 0)
    return dp[a][b][c];
  if (a == b && b == c) {
    return 0;
  }
  int t[6] = {987654321, 987654321, 987654321, 987654321, 987654321, 987654321};
  if (a < c && b < c)
    t[0] = f(a + 1, b + 1, c) + 1;
  if (a < b && c < b)
    t[1] = f(a + 1, b, c + 1) + 1;

  if (b < a && c < a)
    t[2] = f(a, b + 1, c + 1) + 1;

  if (a < b && a < c)
    t[3] = f(a + 2, b, c) + 1;

  if (b < a && b < c)
    t[4] = f(a, b + 2, c) + 1;

  if (c < a && c < b)
    t[5] = f(a, b, c + 2) + 1;

  sort(t, t + 6);

  dp[a][b][c] = t[0];

  return dp[a][b][c];
}

int main() {

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

  cout << f(a, b, c) << endl;

  return 0;
}

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int ans = 987654321;
int dp[100][100][100];
int f(int a, int b, int c) {
  // printf("%d %d %d\n", a, b, c);

  if (dp[a][b][c] > 0)
    return dp[a][b][c];
  if (a == b && b == c) {
    return 0;
  }
  int t[6] = {987654321, 987654321, 987654321, 987654321, 987654321, 987654321};
  if (a < c && b < c)
    t[0] = f(a + 1, b + 1, c) + 1;
  if (a < b && c < b)
    t[1] = f(a + 1, b, c + 1) + 1;

  if (b < a && c < a)
    t[2] = f(a, b + 1, c + 1) + 1;

  if (a < b && a < c)
    t[3] = f(a + 2, b, c) + 1;

  if (b < a && b < c)
    t[4] = f(a, b + 2, c) + 1;

  if (c < a && c < b)
    t[5] = f(a, b, c + 2) + 1;

  sort(t, t + 6);

  dp[a][b][c] = t[0];

  return dp[a][b][c];
}

int main() {

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

  cout << f(a, b, c) << endl;

  return 0;
}
Problem p03387 (C++)

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

int main() {
  int A, B, C;
  int a, b, c;
  int d = 0;
  int e = 1;
  cin >> A >> B >> C;
  if (A >= B && A >= C) {
    a = A;
    b = B;
    c = C;
  }
  if (B >= A && B >= C) {
    a = B;
    b = A;
    c = C;
  }
  if (C >= A && C >= B) {
    a = C;
    b = A;
    c = B;
  }
  b = a - b;
  c = a - c;
  while (e != d)
    if (b % 2 == 1 || c % 2 == 1) {
      e = d;
      b = b - 1;
      c = c - 1;
      d++;
    }
  d += b / 2;
  d += c / 2;
  cout << d;
}


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

int main() {
  int A, B, C;
  int a, b, c;
  int d = 0;
  int e = 1;
  cin >> A >> B >> C;
  if (A >= B && A >= C) {
    a = A;
    b = B;
    c = C;
  }
  if (B >= A && B >= C) {
    a = B;
    b = A;
    c = C;
  }
  if (C >= A && C >= B) {
    a = C;
    b = A;
    c = B;
  }
  b = a - b;
  c = a - c;
  if (b % 2 == 0 && c % 2 == 1) {
    b = b;
    c = c + 1;
    d++;
  }
  if (b % 2 == 1 && c % 2 == 0) {
    b = b;
    c = c + 1;
    d++;
  }
  if (b % 2 == 1 || c % 2 == 1) {
    b = b - 1;
    c = c - 1;
    d++;
  }
  d += b / 2;
  d += c / 2;
  cout << d;
}
Problem p03387 (C++)

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

int main() {
  int a, b, c, x;
  scanf("%d%d%d", a, b, c);
  x = 3 * max(max(a, b), c) - a - b - c;
  printf("%d", x / 2 + x % 2 * 2);
}


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

int main() {
  int a, b, c, x;
  scanf("%d%d%d", &a, &b, &c);
  x = 3 * max(max(a, b), c) - a - b - c;
  printf("%d", x / 2 + x % 2 * 2);
}
Problem p03387 (C++)

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

int main() {
  int a, b, c;
  bool chk = false;
  int cnt = 0;

  cin >> a >> b >> c;

  while (chk == false) {
    if (a == b && b == c) {
      chk = true;
      break;
    }

    if (a <= b && a <= c) {
      if (a == b) {
        a++;
        b++;
        cnt++;
      } else if (a == c) {
        a++;
        c++;
        cnt++;
      } else {
        a += 2;
        cnt++;
      }
    } else if (b <= a && b <= c) {
      if (b == a) {
        b++;
        a++;
        cnt++;
      } else if (b == c) {
        b++;
        c++;
        cnt++;
      } else {
        c += 2;
        cnt++;
      }
    } else {
      if (c == a) {
        c++;
        a++;
        cnt++;
      } else if (c == b) {
        c++;
        b++;
        cnt++;
      } else {
        c += 2;
        cnt++;
      }
    }
  }

  cout << cnt;
}


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

int main() {
  int a, b, c;
  bool chk = false;
  int cnt = 0;

  cin >> a >> b >> c;

  while (chk == false) {
    if (a == b && b == c) {
      chk = true;
      break;
    }

    if (a <= b && a <= c) {
      if (a == b) {
        a++;
        b++;
        cnt++;
      } else if (a == c) {
        a++;
        c++;
        cnt++;
      } else {
        a += 2;
        cnt++;
      }
    } else if (b <= a && b <= c) {
      if (b == a) {
        b++;
        a++;
        cnt++;
      } else if (b == c) {
        b++;
        c++;
        cnt++;
      } else {
        b += 2;
        cnt++;
      }
    } else {
      if (c == a) {
        c++;
        a++;
        cnt++;
      } else if (c == b) {
        c++;
        b++;
        cnt++;
      } else {
        c += 2;
        cnt++;
      }
    }
  }

  cout << cnt;
}
Problem p03387 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int a;
  std::deque<int> deq;
  for (int i = 0; i < 3; i++) {
    cin >> a;
    deq.emplace_back(a);
  }
  sort(deq.begin(), deq.end());
  int count = 0;
  while (1) {
    if (deq[0] == deq[1] && deq[1] == deq[2]) {
      cout << count << endl;
      break;
    } else if (deq[0] == deq[1] && deq[0] + 1 == deq[2]) {
      deq[0]++;
      deq[1]++;
      count++;
    } else if (deq[1] != deq[2]) {
      deq[0] += 2;
      count++;
    } else if (deq[1] == deq[2]) {
      if (deq[0] + 2 != deq[2]) {
        deq[1]++;
        deq[2]++;
        count++;
      } else if (deq[0] + 2 == deq[2]) {
        deq[0] += 2;
        count++;
      }
    }
    sort(deq.begin(), deq.end());
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int a;
  std::deque<int> deq;
  for (int i = 0; i < 3; i++) {
    cin >> a;
    deq.emplace_back(a);
  }
  sort(deq.begin(), deq.end());
  int count = 0;
  while (1) {
    if (deq[0] == deq[1] && deq[1] == deq[2]) {
      cout << count << endl;
      break;
    } else if (deq[0] == deq[1] && deq[0] + 1 == deq[2]) {
      deq[0]++;
      deq[1]++;
      count++;
    } else if (deq[1] != deq[2]) {
      deq[0] += 2;
      count++;
    } else if (deq[1] == deq[2]) {
      if (deq[0] + 2 < deq[2]) {
        deq[0] += 2;
        count++;
      } else if (deq[0] + 2 > deq[2]) {
        deq[1]++;
        deq[2]++;
        count++;
      } else if (deq[0] + 2 == deq[2]) {
        deq[0] += 2;
        count++;
      }
    }
    sort(deq.begin(), deq.end());
  }
}
Problem p03387 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(void) {
  vector<int> V;
  cin >> V[0] >> V[1] >> V[2];
  sort(V.begin(), V.end());
  int x = V[1] - V[0];
  if (x % 2 == 0)
    cout << x / 2 + V[2] - V[1] << endl;
  else
    cout << (x + 3) / 2 + V[2] - V[1] << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(void) {
  vector<int> V(3);
  cin >> V[0] >> V[1] >> V[2];
  sort(V.begin(), V.end());
  int x = V[1] - V[0];
  if (x % 2 == 0)
    cout << x / 2 + V[2] - V[1] << endl;
  else
    cout << (x + 3) / 2 + V[2] - V[1] << endl;
}
Problem p03387 (C++)

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

int main(void) {
  int a, b, c;
  cin >> a >> b >> c;
  int sum = 0;
  int x = max({a, b, c});

  if ((x * 3 - (a - b - c)) % 2 == 0) {
    cout << (x * 3 - (a + b + c)) / 2 << endl;
  } else {
    cout << ((x + 1) * 3 - (a + b + c)) / 2 << endl;
  }

  while (1)
    ;
  return 0;
}


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

int main(void) {
  int a, b, c;
  cin >> a >> b >> c;
  int sum = 0;
  int x = max({a, b, c});

  if ((x * 3 - (a - b - c)) % 2 == 0) {
    cout << (x * 3 - (a + b + c)) / 2 << endl;
  } else {
    cout << ((x + 1) * 3 - (a + b + c)) / 2 << endl;
  }

  return 0;
}
Problem p03387 (C++)

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

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

  int A, B, C;
  cin >> A >> B >> C;
  int ans = 0;
  int m = max(max(A, B), C);
  vector<int> mList;
  if (m - A != 0)
    mList.push_back(m - A);
  if (m - B != 0)
    mList.push_back(m - B);
  if (m - C != 0)
    mList.push_back(m - C);
  ans += min(mList[0], mList[1]);
  ans += (max(mList[0], mList[1]) - min(mList[0], mList[1]) + 1) / 2;
  if ((max(mList[0], mList[1]) - min(mList[0], mList[1])) % 2 == 1)
    ans++;
  cout << ans << endl;
}

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

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

  int A, B, C;
  cin >> A >> B >> C;
  int ans = 0;
  int m = max(max(A, B), C);
  vector<int> mList;
  if (m - A != 0)
    mList.push_back(m - A);
  if (m - B != 0)
    mList.push_back(m - B);
  if (m - C != 0)
    mList.push_back(m - C);

  if (mList.size() == 1) {
    ans += (mList[0] + 1) / 2;
    if (mList[0] % 2 == 1)
      ans++;
  } else if (mList.size() == 2) {
    ans += min(mList[0], mList[1]);
    ans += (max(mList[0], mList[1]) - min(mList[0], mList[1]) + 1) / 2;
    if ((max(mList[0], mList[1]) - min(mList[0], mList[1])) % 2 == 1)
      ans++;
  }
  cout << ans << endl;
}
Problem p03387 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <stdio.h>

void swap(int *, int *);

int main(void) {
  int a, b, c, count = 0;
  scanf("%d%d%d", &a, &b, &c);
  if (a > b)
    swap(&a, &b);
  if (b > c)
    swap(&b, &c);
  if (a > b)
    swap(&a, &b);
  while (1) {
    if (a == b && b == c)
      break;
    if (b == c)
      a += 2;
    else {
      a++;
      b++;
    }
    count++;
  }
  printf("%d\n", count);
  return 0;
}

void swap(int *a, int *b) {
  int mv;
  mv = *a;
  *a = *b;
  *b = mv;
}


Fixed submission:
#include <stdio.h>

void swap(int *, int *);

int main(void) {
  int a, b, c, count = 0;
  scanf("%d%d%d", &a, &b, &c);
  if (a > b)
    swap(&a, &b);
  if (b > c)
    swap(&b, &c);
  if (a > b)
    swap(&a, &b);
  count += (c - b);
  a += count;
  if ((c - a) % 2 == 0)
    count += ((c - a) / 2);
  else
    count += (((c - a) / 2) + 2);
  printf("%d\n", count);
  return 0;
}

void swap(int *a, int *b) {
  int mv;
  mv = *a;
  *a = *b;
  *b = mv;
}
Problem p03387 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
// #include <cstdio>
// #include <functional>
#include <iostream>
// #include <cfloat>
// #include <climits>
// #include <cstdlib>
// #include <cstring>
// #include <cmath>
// #include <map>
// #include <queue>
// #include <set>
// #include <sstream>
// #include <stack>
// #include <string>
// #include <time.h>
#include <vector>
// #include <random>
// #include <unordered_set>
// #include <complex>
#define rt0 return 0
using namespace std;
int main() {
  vector<int> a;
  cin >> a[0] >> a[1] >> a[2];
  sort(a.begin(), a.end());
  if (((a[2] - a[0]) + (a[2] - a[1])) % 2 == 0)
    cout << ((a[2] - a[0]) + (a[2] - a[1])) / 2;
  else
    cout << ((a[2] - a[0]) + (a[2] - a[1]) + 3) / 2;
  rt0;
}

Fixed submission:
#include <algorithm>
// #include <cstdio>
// #include <functional>
#include <iostream>
// #include <cfloat>
// #include <climits>
// #include <cstdlib>
// #include <cstring>
// #include <cmath>
// #include <map>
// #include <queue>
// #include <set>
// #include <sstream>
// #include <stack>
// #include <string>
// #include <time.h>
#include <vector>
// #include <random>
// #include <unordered_set>
// #include <complex>
#define rt0 return 0
using namespace std;
int main() {
  vector<int> a(3);
  cin >> a[0] >> a[1] >> a[2];
  sort(a.begin(), a.end());
  if (((a[2] - a[0]) + (a[2] - a[1])) % 2 == 0)
    cout << ((a[2] - a[0]) + (a[2] - a[1])) / 2;
  else
    cout << ((a[2] - a[0]) + (a[2] - a[1]) + 3) / 2;
  rt0;
}
Problem p03387 (C++)

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

int main() {
  vector<int> x(3);
  cin >> x[0] >> x[1] >> x[2];
  sort(x.begin(), x.end(), greater<int>());

  int cnt = 0;
  while (true) {
    if (x[0] == x[1] && x[1] == x[2])
      break;
    if (x[0] == x[1]) {
      int tmp = x[0] - x[2];
      if (tmp == 1) {
        x[2] += 2;
      } else {
        x[2] += (2 * (tmp / 2));
        cnt += (tmp / 2) - 1;
      }
    } else if (x[1] == x[2]) {
      if (x[0] - x[1] == 1) {
        x[1]++;
        x[2]++;
      } else {
        x[0] += 2;
      }
    } else if (x[0] - x[1] >= 2) {
      int tmp = x[0] - x[1];
      x[1] += (2 * (tmp / 2));
      cnt += (tmp / 2) - 1;
    } else if (x[0] - x[1] == 1) {
      x[1]++;
      x[2]++;
    } else if (x[0] - x[2] >= 2) {
      int tmp = x[0] - x[2];
      x[2] += (2 * (tmp / 2));
      cnt += (tmp / 2) - 1;
    } else if (x[0] - x[2] == 1) {
      x[2]++;
    }
    cnt++;
    sort(x.begin(), x.end(), greater<int>());
  }
  cout << cnt << endl;
}

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

int main() {
  vector<int> x(3);
  cin >> x[0] >> x[1] >> x[2];
  sort(x.begin(), x.end(), greater<int>());

  int cnt = 0;
  while (true) {
    if (x[0] == x[1] && x[1] == x[2])
      break;
    if (x[0] == x[1]) {
      int tmp = x[0] - x[2];
      if (tmp == 1) {
        x[2] += 2;
      } else {
        x[2] += (2 * (tmp / 2));
        cnt += (tmp / 2) - 1;
      }
    } else if (x[1] == x[2]) {
      if (x[0] - x[1] == 1) {
        x[1]++;
        x[2]++;
      } else {
        int tmp = x[0] - x[1];
        x[1] += tmp;
        x[2] += tmp;
        cnt += tmp - 1;
      }
    } else if (x[0] - x[1] >= 2) {
      int tmp = x[0] - x[1];
      x[1] += (2 * (tmp / 2));
      cnt += (tmp / 2) - 1;
    } else if (x[0] - x[1] == 1) {
      x[1]++;
      x[2]++;
    } else if (x[0] - x[2] >= 2) {
      int tmp = x[0] - x[2];
      x[2] += (2 * (tmp / 2));
      cnt += (tmp / 2) - 1;
    } else if (x[0] - x[2] == 1) {
      x[2]++;
    }
    cnt++;
    sort(x.begin(), x.end(), greater<int>());
  }
  cout << cnt << endl;
}
Problem p03387 (C++)

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

int main() {
  int A, B, C;
  cin >> A >> B >> C;
  vector<int> data(2);
  data.at(0) = A;
  data.at(1) = B;
  data.at(2) = C;
  sort(data.begin(), data.end());
  if ((data.at(0) + data.at(1)) % 2 != 0) {
    cout << ((data.at(2) + 1) * 2 - data.at(1) - data.at(0) + 1) / 2 << endl;
  } else {
    cout << (data.at(2) * 2 - data.at(1) - data.at(0)) / 2 << endl;
  }
}


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

int main() {
  int A, B, C;
  cin >> A >> B >> C;
  vector<int> data(3);
  data.at(0) = A;
  data.at(1) = B;
  data.at(2) = C;
  sort(data.begin(), data.end());
  if ((data.at(0) + data.at(1)) % 2 != 0) {
    cout << ((data.at(2) + 1) * 2 - data.at(1) - data.at(0) + 1) / 2 << endl;
  } else {
    cout << (data.at(2) * 2 - data.at(1) - data.at(0)) / 2 << endl;
  }
}
Problem p03387 (Python)

Buggy submission (status: Runtime Error):
A, B, C = map(int, input().split())
diff = max(A, B, C) * 3 - sum(A, B, C)
if diff % 2 == 0:
    print(diff // 2)
else:
    print(diff // 2 + 2)


Fixed submission:
A, B, C = map(int, input().split())
diff = max(A, B, C) * 3 - (A + B + C)
if diff % 2 == 0:
    print(diff // 2)
else:
    print(diff // 2 + 2)
Problem p03387 (C++)

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

int ori[3], head, tail, que[100010][4], ans;
bool vis[60][60][60];

int main() {
  scanf("%d%d%d", &ori[0], &ori[1], &ori[2]);
  sort(ori, ori + 3, greater<int>());
  que[0][0] = ori[0];
  que[0][1] = ori[1];
  que[0][2] = ori[2];
  que[0][3] = 0;
  while (head <= tail) {
    register int aa = que[head][0], bb = que[head][1], cc = que[head][2],
                 dd = que[head++][3];
    if (vis[aa][bb][cc])
      continue;
    vis[aa][bb][cc] = 1;
    if (aa == bb && bb == cc) {
      ans = dd;
      break;
    }
    que[++tail][0] = aa + 1;
    que[tail][1] = bb + 1;
    que[tail][2] = cc;
    que[tail][3] = dd + 1;
    que[++tail][0] = aa + 1;
    que[tail][1] = bb;
    que[tail][2] = cc + 1;
    que[tail][3] = dd + 1;
    que[++tail][0] = aa;
    que[tail][1] = bb + 1;
    que[tail][2] = cc + 1;
    que[tail][3] = dd + 1;
    que[++tail][0] = aa;
    que[tail][1] = bb + 2;
    que[tail][2] = cc;
    que[tail][3] = dd + 1;
    que[++tail][0] = aa;
    que[tail][1] = bb;
    que[tail][2] = cc + 2;
    que[tail][3] = dd + 1;
  }
  printf("%d", ans);
  return 0;
}

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

int ori[3], head, tail, que[10000010][4], ans;
bool vis[60][60][60];

int main() {
  scanf("%d%d%d", &ori[0], &ori[1], &ori[2]);
  sort(ori, ori + 3, greater<int>());
  que[0][0] = ori[0];
  que[0][1] = ori[1];
  que[0][2] = ori[2];
  que[0][3] = 0;
  while (head <= tail) {
    register int aa = que[head][0], bb = que[head][1], cc = que[head][2],
                 dd = que[head++][3];
    if (vis[aa][bb][cc])
      continue;
    vis[aa][bb][cc] = 1;
    if (aa == bb && bb == cc) {
      ans = dd;
      break;
    }
    que[++tail][0] = aa + 1;
    que[tail][1] = bb + 1;
    que[tail][2] = cc;
    que[tail][3] = dd + 1;
    que[++tail][0] = aa + 1;
    que[tail][1] = bb;
    que[tail][2] = cc + 1;
    que[tail][3] = dd + 1;
    que[++tail][0] = aa;
    que[tail][1] = bb + 1;
    que[tail][2] = cc + 1;
    que[tail][3] = dd + 1;
    que[++tail][0] = aa;
    que[tail][1] = bb + 2;
    que[tail][2] = cc;
    que[tail][3] = dd + 1;
    que[++tail][0] = aa;
    que[tail][1] = bb;
    que[tail][2] = cc + 2;
    que[tail][3] = dd + 1;
  }
  printf("%d", ans);
  return 0;
}
Problem p03387 (C++)

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

using namespace std;
typedef long long ll;
typedef long double ld;
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }

const int q = 1e9 + 9;
int a[1007], b[1007];

int main() {
  int ma[3], ans = 0;
  cin >> ma[0] >> ma[1] >> ma[2];
  sort(ma, ma + 3);
  ans += ma[2] - ma[1];
  ma[0] += ans;

  if (ma[2] - ma[0] == 1) {
    ans += 2;
    ma[0]++;
  }
  while (ma[0] != ma[2]) {
    if (ma[2] - ma[0] > 1) {
      ans++;
      ma[0] += 2;
    } else if (ma[2] - ma[0] == 1) {
      ans += 2;
    } else
      break;
  }

  cout << ans << endl;

  return 0;
}
// gotcha;


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

using namespace std;
typedef long long ll;
typedef long double ld;
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }

const int q = 1e9 + 9;
int a[1007], b[1007];

int main() {
  int ma[3], ans = 0;
  cin >> ma[0] >> ma[1] >> ma[2];
  sort(ma, ma + 3);
  ans += ma[2] - ma[1];
  ma[0] += ans;

  if (ma[2] - ma[0] == 1) {
    ans += 2;
    ma[0]++;
  }
  while (ma[0] != ma[2]) {
    if (ma[2] - ma[0] > 1) {
      ans++;
      ma[0] += 2;
    } else if (ma[2] - ma[0] == 1) {
      ans += 2;
      break;
    } else
      break;
  }

  cout << ans << endl;

  return 0;
}
// gotcha;
Problem p03388 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int q;
  cin >> q;
  rep(_, q) {
    ll a, b;
    cin >> a >> b;
    ll c = min(a, b);
    while (c * c < a * b)
      ++c;
    --c;
    ll ans = 2 * c - 2;
    if (c * (c + 1) < a * b)
      ++ans;
    if (a == b)
      ++ans;
    cout << ans << endl;
  }
}

Fixed submission:
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int q;
  cin >> q;
  rep(_, q) {
    ll a, b;
    cin >> a >> b;
    ll l = min(a, b), r = max(a, b);
    while (l + 1 < r) {
      ll x = (l + r) / 2;
      if (x * x < a * b) {
        l = x;
      } else {
        r = x;
      }
    }
    ll ans = 2 * l - 2;
    if (l * (l + 1) < a * b)
      ++ans;
    cout << ans << endl;
  }
}