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

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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template <class T> void debug(T itr1, T itr2) {
  auto now = itr1;
  while (now < itr2) {
    cout << *now << " ";
    now++;
  }
  cout << endl;
}
#define repr(i, from, to) for (int i = (int)from; i < (int)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i, N) repr(i, 0, N)
#define per(i, N) for (int i = (int)N - 1; i >= 0; i--)

const ll MOD = pow(10, 9) + 7;
const ll LLINF = pow(2, 61) - 1;
const int INF = pow(2, 30) - 1;

int main() {
  int N, K, Q;
  cin >> N >> K >> Q;
  ll A[N];
  rep(i, N) cin >> A[i];
  ll result = INF;
  rep(i, N) {
    vector<ll> num, now;
    rep(j, N + 1) {
      if (j != i && j != N && A[j] >= A[i])
        now.push_back(A[j]);
      else if (j != i) {
        sort(all(now));
        rep(i, now.size() - K + 1) num.push_back(now[i]);
        now.clear();
      }
    }
    sort(all(num));
    // debug(all(num));
    if (num.size() >= Q - 1)
      result = min(result, num[Q - 2] - A[i]);
  }
  cout << result << endl;
  return 0;
}

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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template <class T> void debug(T itr1, T itr2) {
  auto now = itr1;
  while (now < itr2) {
    cout << *now << " ";
    now++;
  }
  cout << endl;
}
#define repr(i, from, to) for (int i = (int)from; i < (int)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i, N) repr(i, 0, N)
#define per(i, N) for (int i = (int)N - 1; i >= 0; i--)

const ll MOD = pow(10, 9) + 7;
const ll LLINF = pow(2, 61) - 1;
const int INF = pow(2, 30) - 1;

int main() {
  int N, K, Q;
  cin >> N >> K >> Q;
  ll A[N];
  rep(i, N) cin >> A[i];

  if (Q == 1) {
    cout << 0 << endl;
    return 0;
  }
  ll result = INF;
  rep(i, N) {
    vector<ll> num, now;
    rep(j, N + 1) {
      if (j != i && j != N && A[j] >= A[i])
        now.push_back(A[j]);
      else if (j != i) {
        sort(all(now));
        rep(i, now.size() - K + 1) num.push_back(now[i]);
        now.clear();
      }
    }
    sort(all(num));
    // debug(all(num));
    if (num.size() >= Q - 1)
      result = min(result, num[Q - 2] - A[i]);
  }
  cout << result << endl;
  return 0;
}
Problem p03343 (C++)

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

const int maxn = 1e3 + 5, INF = 1e9;
int n, k, q, cntc, a[maxn], b[maxn], dable[maxn], ans = INF;
int fa[maxn], len[maxn]; // len表示一个结点所代表的区间长度

struct Node { // 对能选的数排序
  int v, id;
} c[maxn];

bool cmp(const Node &a, const Node &b) { return a.v < b.v; }

int main() {
  scanf("%d%d%d", &n, &k, &q);
  int x, cnt, minm, t;
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
    b[i] = a[i];
  }
  sort(b + 1, b + n + 1);
  for (int i = 1; i <= n; ++i) {
    x = b[i]; // x表示最小的最小元素
    memset(dable, 0, sizeof(dable));
    memset(fa, 0, sizeof(fa));
    cntc = 0;
    t = 1;
    for (int j = 1; j <= n; ++j)
      if (a[j] < x)
        dable[j] = 1;              // 比x小的数不能选
    for (int j = 1; j <= n; ++j) { // j-t表示区间长度 t是区间起点
      if (!dable[j])
        fa[j] = t, c[++cntc].v = a[j], c[cntc].id = j;
      if (dable[j])
        len[t] = j - t, t = j + 1;
    }
    len[t] = n + 1 - t;
    sort(c + 1, c + cntc + 1, cmp);
    cnt = 1;
    for (int j = 1; cnt <= q && j <= cntc; ++j) { // 取q个数
      if (len[fa[c[j].id]] < k)
        continue;
      --len[fa[c[j].id]]; // 取完以后所在的区间长度-1
      minm = c[j].v;
      ++cnt; // minm表示最小的最大元素
    }
    if (cnt <= q)
      break;
    ans = min(ans, minm - x);
  }
  printf("%d\n", ans);
  return 0;
}


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

const int maxn = 4e3 + 5, INF = 1e9;
int n, k, q, cntc, a[maxn], b[maxn], dable[maxn], ans = INF;
int fa[maxn], len[maxn]; // len表示一个结点所代表的区间长度

struct Node { // 对能选的数排序
  int v, id;
} c[maxn];

bool cmp(const Node &a, const Node &b) { return a.v < b.v; }

int main() {
  scanf("%d%d%d", &n, &k, &q);
  int x, cnt, minm, t;
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
    b[i] = a[i];
  }
  sort(b + 1, b + n + 1);
  for (int i = 1; i <= n; ++i) {
    x = b[i]; // x表示最小的最小元素
    memset(dable, 0, sizeof(dable));
    memset(fa, 0, sizeof(fa));
    cntc = 0;
    t = 1;
    for (int j = 1; j <= n; ++j)
      if (a[j] < x)
        dable[j] = 1;              // 比x小的数不能选
    for (int j = 1; j <= n; ++j) { // j-t表示区间长度 t是区间起点
      if (!dable[j])
        fa[j] = t, c[++cntc].v = a[j], c[cntc].id = j;
      if (dable[j])
        len[t] = j - t, t = j + 1;
    }
    len[t] = n + 1 - t;
    sort(c + 1, c + cntc + 1, cmp);
    cnt = 1;
    for (int j = 1; cnt <= q && j <= cntc; ++j) { // 取q个数
      if (len[fa[c[j].id]] < k)
        continue;
      --len[fa[c[j].id]]; // 取完以后所在的区间长度-1
      minm = c[j].v;
      ++cnt; // minm表示最小的最大元素
    }
    if (cnt <= q)
      break;
    ans = min(ans, minm - x);
  }
  printf("%d\n", ans);
  return 0;
}
Problem p03343 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
typedef long long ll;
ll n, m, k, a[2000], ans = 1000000000;
vector<ll> u, v;
int main(void) {
  cin >> n >> m >> k;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < n; i++) {
    v = {};
    u = {};
    for (int j = 0; j < n; j++) {
      if (i == j)
        continue;
      if (a[i] <= a[j]) {
        v.push_back(a[j]);
      } else {
        if (v.size() >= m) {
          sort(v.begin(), v.end());
          for (int i = 0; i < min((ll)v.size() - m + 1LL, k - 1LL); i++)
            u.push_back(v[i]);
        }
        v = {};
      }
    }
    if (v.size() >= m) {
      sort(v.begin(), v.end());
      for (int i = 0; i < min((ll)v.size() - m + 1, k - 1); i++)
        u.push_back(v[i]);
    }
    // cout<<u.size()<<" "<<i<<endl;
    if (u.size() < k - 1)
      continue;
    sort(u.begin(), u.end());
    // cout<<u[0]<<endl;
    ans = min(ans, u[k - 2] - a[i]);
    // cout<<ans<<endl;
  }
  cout << ans << endl;
}


Fixed submission:
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
typedef long long ll;
ll n, m, k, a[2000], ans = 1000000000;
vector<ll> u, v;
int main(void) {
  cin >> n >> m >> k;
  if (k == 1) {
    cout << 0 << endl;
    return 0;
  }
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < n; i++) {
    v = {};
    u = {};
    for (int j = 0; j < n; j++) {
      if (i == j)
        continue;
      if (a[i] <= a[j]) {
        v.push_back(a[j]);
      } else {
        if (v.size() >= m) {
          sort(v.begin(), v.end());
          for (int i = 0; i < min((ll)v.size() - m + 1LL, k - 1LL); i++)
            u.push_back(v[i]);
        }
        v = {};
      }
    }
    if (v.size() >= m) {
      sort(v.begin(), v.end());
      for (int i = 0; i < min((ll)v.size() - m + 1, k - 1); i++)
        u.push_back(v[i]);
    }
    // cout<<u.size()<<" "<<i<<endl;
    if (u.size() < k - 1)
      continue;
    sort(u.begin(), u.end());
    // cout<<u[0]<<endl;
    ans = min(ans, u[k - 2] - a[i]);
    // cout<<ans<<endl;
  }
  cout << ans << endl;
}
Problem p03343 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef set<int> si;
typedef pair<int, int> pii;
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define per(i, a, b) for (int i = (b)-1; i >= (a); --i)
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define F first
#define S second

const int INF = 1e9;
int n, k, q;
vi a;

int solve(int mn) {
  vector<vi> b;
  vi loc;
  for (int i = 0; i < n; ++i) {
    if (a[i] >= mn) {
      loc.pb(a[i]);
    } else {
      if (!loc.empty()) {
        b.pb(loc);
        loc.clear();
      }
    }
  }
  if (!loc.empty())
    b.pb(loc);

  vi cand;
  for (int i = 0; i < (int)b.size(); ++i) {
    sort(all(b[i]));
    int m = sz(b[i]);
    for (int j = 0; j < m - k + 1; ++j) {
      cand.pb(b[i][j]);
    }
  }
  if (sz(cand) < q) {
    return INF;
  }
  sort(all(cand));
  return cand[q - 1] - cand[0];
}

int main(void) {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  freopen("in.txt", "r", stdin);
  cin >> n >> k >> q;
  a.resize(n);
  set<int> s;
  rep(i, 0, n) {
    cin >> a[i];
    s.insert(a[i]);
  }
  int ret = INF;
  for (auto mn : s) {
    ret = min(ret, solve(mn));
  }
  cout << ret << '\n';
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef set<int> si;
typedef pair<int, int> pii;
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define per(i, a, b) for (int i = (b)-1; i >= (a); --i)
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define F first
#define S second

const int INF = 1e9;
int n, k, q;
vi a;

int solve(int mn) {
  vector<vi> b;
  vi loc;
  for (int i = 0; i < n; ++i) {
    if (a[i] >= mn) {
      loc.pb(a[i]);
    } else {
      if (!loc.empty()) {
        b.pb(loc);
        loc.clear();
      }
    }
  }
  if (!loc.empty())
    b.pb(loc);

  vi cand;
  for (int i = 0; i < (int)b.size(); ++i) {
    sort(all(b[i]));
    int m = sz(b[i]);
    for (int j = 0; j < m - k + 1; ++j) {
      cand.pb(b[i][j]);
    }
  }
  if (sz(cand) < q) {
    return INF;
  }
  sort(all(cand));
  return cand[q - 1] - cand[0];
}

int main(void) {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  // freopen("in.txt", "r", stdin);
  cin >> n >> k >> q;
  a.resize(n);
  set<int> s;
  rep(i, 0, n) {
    cin >> a[i];
    s.insert(a[i]);
  }
  int ret = INF;
  for (auto mn : s) {
    ret = min(ret, solve(mn));
  }
  cout << ret << '\n';
  return 0;
}
Problem p03343 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int main() {
  int N, K, Q;
  while (cin >> N >> K >> Q) {
    vector<int> A(N);
    for (int &t : A)
      cin >> t;
    vector<int> thr = A;
    thr.push_back(0);
    sort(thr.begin(), thr.end());
    thr.erase(unique(thr.begin(), thr.end()), thr.end());
    vector<int> part;
    part.reserve(N);
    vector<int> cur;
    cur.reserve(N);
    long long res = 1LL << 60;
    for (const auto &wall : thr) {
      part.clear();
      cur.clear();
      auto pushPart = [&]() {
        if (part.empty())
          return;
        sort(part.begin(), part.end());
        for (int j = 0; j < part.size() - K + 1; j++) {
          cur.push_back(part[j]);
        }
        part.clear();
      };
      for (int i = 0; i < N; i++) {
        if (A[i] <= wall) {
          pushPart();
        } else {
          part.push_back(A[i]);
        }
      }
      if (!part.empty()) {
        pushPart();
      }
      if (cur.size() < Q)
        break;
      sort(cur.begin(), cur.end());
      res = min(res, (long long)cur[Q - 1] - cur[0]);
    }
    cout << res << endl;
  }
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int main() {
  int N, K, Q;
  while (cin >> N >> K >> Q) {
    vector<int> A(N);
    for (int &t : A)
      cin >> t;
    vector<int> thr = A;
    thr.push_back(0);
    sort(thr.begin(), thr.end());
    thr.erase(unique(thr.begin(), thr.end()), thr.end());
    vector<int> part;
    part.reserve(N);
    vector<int> cur;
    cur.reserve(N);
    long long res = 1LL << 60;
    for (const auto &wall : thr) {
      part.clear();
      cur.clear();
      auto pushPart = [&]() {
        if (part.empty())
          return;
        sort(part.begin(), part.end());
        for (int j = 0; j < (int)part.size() - K + 1; j++) {
          cur.push_back(part[j]);
        }
        part.clear();
      };
      for (int i = 0; i < N; i++) {
        if (A[i] <= wall) {
          pushPart();
        } else {
          part.push_back(A[i]);
        }
      }
      if (!part.empty()) {
        pushPart();
      }
      if (cur.size() < Q)
        break;
      sort(cur.begin(), cur.end());
      res = min(res, (long long)cur[Q - 1] - cur[0]);
    }
    cout << res << endl;
  }
}
Problem p03344 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
typedef long long ll;
const int N = 1000005;
struct Edge {
  int u, v;
  int w;
  inline bool operator<(const Edge &b) const { return w < b.w; }
} e[N];
ll f[N], sum[N];
int fa[N];
int a[N], b[N];
int find(int x) { return fa[x] == x ? x : find(fa[x]); }
int main() {
  // freopen("input.txt","r",stdin);
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m, tmp = 0;
  cin >> n >> m;
  for (int i = 1; i <= n; i++)
    cin >> a[i] >> b[i], fa[i] = i, sum[i] = b[i], f[i] = max(a[i], b[i]);
  for (int i = 1; i <= m; i++)
    cin >> e[i].u >> e[i].v, e[i].w = max(max(a[e[i].u] - b[e[i].u], 0),
                                          max(a[e[i].v] - b[e[i].v], 0));
  sort(e + 1, e + 1 + m);
  for (int i = 1; i <= m; i++)
    if ((e[i].u = find(e[i].u)) != (e[i].v = find(e[i].v))) {
      f[e[i].u] = min(max(f[e[i].u], (ll)e[i].w) + sum[e[i].v],
                      max(f[e[i].v], (ll)e[i].w) + sum[e[i].u]);
      fa[e[i].v] = e[i].u;
      sum[e[i].u] += sum[e[i].v];
    }
  cout << f[find(1)] << endl;
  // cout <<tmp<<n;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
typedef long long ll;
const int N = 1000005;
struct Edge {
  int u, v;
  int w;
  inline bool operator<(const Edge &b) const { return w < b.w; }
} e[N];
ll f[N], sum[N];
int fa[N];
int a[N], b[N];
int find(int x) { return fa[x] = (fa[x] == x ? x : find(fa[x])); }
int main() {
  // freopen("input.txt","r",stdin);
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m, tmp = 0;
  cin >> n >> m;
  for (int i = 1; i <= n; i++)
    cin >> a[i] >> b[i], fa[i] = i, sum[i] = b[i], f[i] = max(a[i], b[i]);
  for (int i = 1; i <= m; i++)
    cin >> e[i].u >> e[i].v, e[i].w = max(max(a[e[i].u] - b[e[i].u], 0),
                                          max(a[e[i].v] - b[e[i].v], 0));
  sort(e + 1, e + 1 + m);
  for (int i = 1; i <= m; i++)
    if ((e[i].u = find(e[i].u)) != (e[i].v = find(e[i].v))) {
      f[e[i].u] = min(max(f[e[i].u], (ll)e[i].w) + sum[e[i].v],
                      max(f[e[i].v], (ll)e[i].w) + sum[e[i].u]);
      fa[e[i].v] = e[i].u;
      sum[e[i].u] += sum[e[i].v];
    }
  cout << f[find(1)] << endl;
  // cout <<tmp<<n;
  return 0;
}
Problem p03345 (C++)

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

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  vector<long long> v(3);
  int k;
  cin >> v[0] >> v[1] >> v[2] >> k;
  if (v[0] == v[1]) {
    cout << 0 << endl;
    return 0;
  }
  for (int i = 1; i <= k; ++i) {
    vector<long long> u(3);
    for (int j = 0; j < 3; ++j) {
      u[j] = v[(j + 1) % 3] + v[(j + 2) % 3];
    }
    v = u;
    if (abs(v[0] - v[1]) > 1e18) {
      cout << "Unfair" << endl;
      return 0;
    }
  }
  cout << v[0] - v[1] << endl;
  return 0;
}


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

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long a, b, c, k;
  cin >> a >> b >> c >> k;
  cout << (k % 2 == 0 ? a - b : b - a) << endl;
  return 0;
}
Problem p03345 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
using namespace std;
int main(void) {
  long a, b, c, k;
  cin >> a >> b >> c >> k;
  long ta, tb, tc;
  if (a == b && b == c) {
    cout << 0 << endl;
    return 0;
  }
  for (int i = 0; i < k; i++) {
    ta = b + c;
    tb = a + c;
    tc = a + b;
    a = ta;
    b = tb;
    c = tc;
  }

  if ((a - b) > 10e18) {
    cout << "unfair" << endl;
  } else {
    cout << a - b << endl;
  }
}


Fixed submission:
#include <iostream>
using namespace std;
int main(void) {
  long a, b, c, k;
  cin >> a >> b >> c >> k;
  cout << ((k % 2 == 0) ? a - b : b - a) << endl;
}
Problem p03345 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
long long a, b, c, a1, b1, c1;
long long k;
int main() {
  scanf("%lld%lld%lld%lld", &a, &b, &c, &k);
  while (k--) {
    a1 = b + c;
    b1 = a + c;
    c1 = a + b;
    a = 0, b = b1 - a1, c = c1 - a1;
    if (abs(a - b) > 1e18) {
      printf("Unfair\n");
      return 0;
    }
    if (a == 0 && b == 0 && c == 0) {
      printf("%d\n", 0);
      return 0;
    }
  }
  printf("%lld\n", a - b);
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
long long a, b, c, a1, b1, c1;
long long k;
int main() {
  scanf("%lld%lld%lld%lld", &a, &b, &c, &k);
  k %= 2;
  while (k--) {
    a1 = b + c;
    b1 = a + c;
    c1 = a + b;
    a = 0, b = b1 - a1, c = c1 - a1;
    if (abs(a - b) > 1e18) {
      printf("Unfair\n");
      return 0;
    }
    if (a == 0 && b == 0 && c == 0) {
      printf("%d\n", 0);
      return 0;
    }
  }
  printf("%lld\n", a - b);
  return 0;
}
Problem p03345 (C++)

Buggy submission (status: Time Limit Exceeded):
/*https://atcoder.jp/contests/agc024/tasks/agc024_a*/
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
#ifndef ONLINE_JUDGE
  // for getting input from input.txt
  freopen("input.txt", "r", stdin);
  // for writing output to output.txt
  freopen("output.txt", "w", stdout);
#endif
  long long a, b, c, d, e, f, k;
  cin >> a >> b >> c >> k;
  if (a == b && a == c) {
    cout << "0";
    return 0;
  }
  while (k--) {
    d = b + c, e = a + c, f = a + b;
    a = d, b = e, c = f;
  }
  cout << a - b;
}

Fixed submission:
/*https://atcoder.jp/contests/agc024/tasks/agc024_a*/
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
#ifndef ONLINE_JUDGE
  // for getting input from input.txt
  freopen("input.txt", "r", stdin);
  // for writing output to output.txt
  freopen("output.txt", "w", stdout);
#endif
  long long a, b, c, d, e, f, k;
  cin >> a >> b >> c >> k;
  if (a == b && a == c) {
    cout << "0";
    return 0;
  }
  if (k % 2 == 0)
    cout << a - b;
  else
    cout << b - a;
}
Problem p03345 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
signed main() {
  long long b = 0, c = 0, d = 1, e, f = 1000000, t, g[100000];
  long long a;
  cin >> a >> b >> c >> d;
  for (int i = 0; i < d; i++) {
    e = a + b;
    f = a + c;
    t = b + c;
    a = t;
    b = f;
    c = e;
  }
  if (abs(a - b) >= 100000000000000000ll)
    cout << "Unfair";
  else
    cout << a - b;
  cout << "\n";
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
signed main() {
  long long b = 0, c = 0, d = 1, e, f = 1000000, t, g[100000];
  long long a;
  cin >> a >> b >> c >> d;
  if (d % 2 == 1)
    swap(a, b);
  if (abs(a - b) >= 100000000000000000ll)
    cout << "Unfair";
  else
    cout << a - b;
  cout << "\n";
}
Problem p03345 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

#define int long long

const int INF = 1e18 + 3;

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

  int k, a, b, c;
  cin >> a >> b >> c >> k;
  if (a == b) {
    cout << 0 << endl;
    return 0;
  }
  while (k--) {
    int na = b + c;
    int nb = a + c;
    int nc = a + b;
    a = na;
    b = nb;
    c = nc;
    int t = min({a, b, c});
    a -= t;
    b -= t;
    c -= t;
    if (max({a, b, c}) > INF) {
      cout << "Unfair" << endl;
      return 0;
    }
  }
  cout << a - b << endl;
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

#define int long long

const int INF = 1e18 + 3;

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

  int k, a, b, c;
  cin >> a >> b >> c >> k;
  if (a == b) {
    cout << 0 << endl;
    return 0;
  }
  k %= 120;
  while (k--) {
    int na = b + c;
    int nb = a + c;
    int nc = a + b;
    a = na;
    b = nb;
    c = nc;
    int t = min({a, b, c});
    a -= t;
    b -= t;
    c -= t;
    if (max({a, b, c}) > INF) {
      cout << "Unfair" << endl;
      return 0;
    }
  }
  cout << a - b << endl;
}
Problem p03345 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define MAXN 505
typedef long long ll;

using namespace std;

ll n, a[MAXN];

int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
#endif
  ios_base::sync_with_stdio(false);
  for (int i = 0; i < 3; i++) {
    cin >> a[i];
  }
  cin >> n;
  ll ans;
  if (n % 2 == 0) {
    ans = a[0] - a[1];
  } else {
    ans = a[1] - a[0];
  }
  cout << ans;
}


Fixed submission:
#include <bits/stdc++.h>
#define MAXN 505
typedef long long ll;

using namespace std;

ll n, a[MAXN];

int main() {
  ios_base::sync_with_stdio(false);
  for (int i = 0; i < 3; i++) {
    cin >> a[i];
  }
  cin >> n;
  ll ans;
  if (n % 2 == 0) {
    ans = a[0] - a[1];
  } else {
    ans = a[1] - a[0];
  }
  cout << ans;
}
Problem p03345 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL << 62
#define inf 1000000007

int main() {
  ll a, b, c, k;
  cin >> a >> b >> c >> k;
  ll ans = 0;
  for (int i = 0; i < k; i++) {
    ll A = b + c;
    ll B = a + c;
    ll C = a + b;
    a = A, b = B, c = C;
  }
  if (abs(a - b) > 1000000000000000000) {
    cout << "unfair";
    return 0;
  }
  cout << a - b;
  // your code goes here
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL << 62
#define inf 1000000007

int main() {
  ll a, b, c, k;
  cin >> a >> b >> c >> k;
  cout << (k % 2 == 0 ? a - b : b - a);
  // your code goes here
  return 0;
}
Problem p03345 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <queue>
#include <string.h>
#include <vector>

using namespace std;

int main(int argc, char *argv[]) {
  long long int a, b, c, k;
  scanf("%d%d%d%d", &a, &b, &c, &k);
  long long int aa, bb, cc;
  aa = a;
  bb = b;
  cc = c;
  for (long long int i = 0; i < k; i++) {
    a = bb + cc;
    b = aa + cc;
    c = aa + bb;
    aa = a;
    bb = b;
    cc = c;
  }
  long long int ans = a - b;
  if (ans > 1000000000000000000) {
    puts("Unfair");
    return 0;
  }
  printf("%lld\n", ans);
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <queue>
#include <string.h>
#include <vector>

using namespace std;

int main(int argc, char *argv[]) {
  long long int a, b, c, k;
  scanf("%d%d%d%d", &a, &b, &c, &k);
  long long int ans;
  if (k % 2 == 0)
    ans = a - b;
  else
    ans = b - a;
  if (abs(ans) > 1000000000000000000) {
    puts("Unfair");
    return 0;
  }
  printf("%lld\n", ans);
  return 0;
}
Problem p03345 (C++)

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

#define MP make_pair
#define FF first
#define SS second
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pie;
const int MOD = 1e9 + 7;
const int INF = 2e9;
const ll LINF = 1e18;
const ll delta = 96181;

ll a, b, c, k;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> a >> b >> c >> k;
  if (a == b && b == c)
    return cout << 0 << endl, 0;
  while (k--) {
    ll S = a + b + c;
    a = S - a;
    b = S - b;
    c = S - c;
    if (abs(a - b) > LINF)
      return cout << "Unfair" << endl, 0;
  }
  cout << a - b << endl;
}


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

#define MP make_pair
#define FF first
#define SS second
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pie;
const int MOD = 1e9 + 7;
const int INF = 2e9;
const ll LINF = 1e18;
const ll delta = 96181;

ll a, b, c, k;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> a >> b >> c >> k;
  cout << (k % 2 ? b - a : a - b) << endl;
}
Problem p03345 (C++)

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

using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
// #define rep(i, n) for (ll i = 0; i < (n); ++i)
// typedef pair<ll, ll> P;
typedef pair<double, double> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) { return fabs(a - b) < DBL_EPSILON; }

std::istream &operator>>(std::istream &in, set<string> &o) {
  string a;
  in >> a;
  o.insert(a);
  return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
  ll a;
  in >> a;
  o.push(a);
  return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

// ofstream outfile("log.txt");
// outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0')
// << rank << endl;
//  std::cout << std::bitset<8>(9);
// const ll mod = 1e10;

typedef priority_queue<ll, vector<ll>, greater<ll>> PQ_ASK;

int main() {

  ll a, b, c, k;
  cin >> a >> b >> c >> k;

  if (a == b && b == c) {
    cout << 0 << endl;
    ret();
  }

  ll lim = 10e17;
  ll prev = -INF;
  rep(i, k) {
    ll na = b + c;
    ll nb = a + c;
    ll nc = a + b;

    a = na;
    b = nb;
    c = nc;

    if (abs(a - b) > lim) {
      cout << "Unfair" << endl;
    }
    ll next = a - b;
    if (next == prev) {
      cout << a - b << endl;
      ret();
    }
    prev = next;
  }
  cout << a - b << endl;
}


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

using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
// #define rep(i, n) for (ll i = 0; i < (n); ++i)
// typedef pair<ll, ll> P;
typedef pair<double, double> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) { return fabs(a - b) < DBL_EPSILON; }

std::istream &operator>>(std::istream &in, set<string> &o) {
  string a;
  in >> a;
  o.insert(a);
  return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
  ll a;
  in >> a;
  o.push(a);
  return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

// ofstream outfile("log.txt");
// outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0')
// << rank << endl;
//  std::cout << std::bitset<8>(9);
// const ll mod = 1e10;

typedef priority_queue<ll, vector<ll>, greater<ll>> PQ_ASK;

int main() {

  ll a, b, c, k;
  cin >> a >> b >> c >> k;
  ll ans = (k % 2 == 1) ? b - a : a - b;
  cout << ans << endl;
}
Problem p03345 (C++)

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

int main() {
  long long a, b, c, x;
  cin >> a >> b >> c >> x;
  if (a == b && b == c) {
    cout << 0 << endl;
    return 0;
  }
  long long ai = a, bi = b, ci = c;
  for (int i = 0; i < x; i++) {
    a = bi + ci;
    b = ai + ci;
    c = ai + bi;
    ai = a;
    bi = b;
    ci = c;
  }

  long long ans = ai - bi;
  if (b > 1e18) {
    cout << "Unfair" << endl;
    return 0;
  }
  cout << ai - bi << endl;
}

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

int main() {
  long long a, b, c, x;
  cin >> a >> b >> c >> x;
  if (x % 2 == 0)
    cout << a - b << endl;
  else
    cout << b - a << endl;
}
Problem p03345 (C++)

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

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

int main() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(0);
  ll a, b, c, k;
  cin >> a >> b >> c >> k;
  if (!k) {
    cout << a - b << endl;
    return 0;
  }
  while (k--) {
    if (a == b && b == c) {
      cout << 0 << endl;
      return 0;
    }
    if (abs(a - b) > 1e18) {
      cout << "Unfair" << endl;
      return 0;
    }
    ll sum = a + b + c;
    a = sum - a, b = sum - b, c = sum - c;
  }
  cout << a - b << endl;
  return 0;
}


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

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

int main() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(0);
  ll a, b, c, k;
  cin >> a >> b >> c >> k;
  cout << (k % 2 ? b - a : a - b) << endl;
  return 0;
}
Problem p03345 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> PLL;
#define rep(i, n) for (int i = 0; i < (n); ++i)
ll MOD = 1e4 + 7;
int main() {
  ll a, b, c, k;
  cin >> a >> b >> c >> k;
  rep(i, k) {
    ll tmp_a = a;
    ll tmp_b = b;
    ll tmp_c = c;
    a = tmp_b + tmp_c;
    b = tmp_a + tmp_c;
    c = tmp_a + tmp_b;
  }
  if (abs(a - b) >= 1e18)
    cout << "Unfair" << endl;
  else
    cout << a - b << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> PLL;
#define rep(i, n) for (int i = 0; i < (n); ++i)
ll MOD = 1e4 + 7;
int main() {
  ll a, b, c, k;
  cin >> a >> b >> c >> k;
  //    rep(i, k) {
  //        ll tmp_a = a;
  //        ll tmp_b = b;
  //        ll tmp_c = c;
  //        a = tmp_b + tmp_c;
  //        b = tmp_a + tmp_c;
  //        c = tmp_a + tmp_b;
  //    }
  if (k & 1)
    swap(a, b);
  if (abs(a - b) >= 1e18)
    cout << "Unfair" << endl;
  else
    cout << a - b << endl;
  return 0;
}
Problem p03345 (C++)

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

#define ll long long
#define INF 99999999
#define INF_LL 1LL << 60
#define MOD (ll)1000000007
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, a, n) for (int i = a; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()

template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}

void put_double(double obj) { printf("%.12f\n", obj); };

template <typename T> std::string to_string(const T &n) {
  std::ostringstream stm;
  stm << n;
  return stm.str();
}

int main() {
  ll A, B, C, K;
  cin >> A >> B >> C >> K;

  ll ans = A - B;
  if ((K + 2) % 2 != 0)
    ans = -ans;

  if (A == B & A == C) {
    cout << 0 << endl;
    return 0;
  }

  while (K >= 0 || max(A, max(B, C)) > 1e17) {
    ll tmp_A = B + C;
    ll tmp_B = A + C;
    ll tmp_C = A + B;
    A = tmp_A;
    B = tmp_B;
    C = tmp_C;
    K--;
  }

  if (K < 0)
    cout << ans << endl;
  else
    cout << "Unfair" << endl;
}


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

#define ll long long
#define INF 99999999
#define INF_LL 1LL << 60
#define MOD (ll)1000000007
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, a, n) for (int i = a; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()

template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}

void put_double(double obj) { printf("%.12f\n", obj); };

template <typename T> std::string to_string(const T &n) {
  std::ostringstream stm;
  stm << n;
  return stm.str();
}

int main() {
  ll A, B, C, K;
  cin >> A >> B >> C >> K;

  ll ans = A - B;
  if ((K + 2) % 2 != 0)
    ans = -ans;

  if (abs(ans) <= 1e17)
    cout << ans << endl;
  else
    cout << "Unfair" << endl;
}
Problem p03345 (C++)

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

int main() {
  int A, B, C, a, b, c;
  long long K;
  cin >> A >> B >> C >> K;
  if (A == B && B == C)
    cout << 0 << endl;
  else {
    for (int i = 0; i < K; i++) {
      a = A;
      b = B;
      c = C;
      A = b + c;
      B = a + c;
      C = a + b;
    }
    if (abs(A - B) >= 1000000000000000000)
      cout << "Unfair" << endl;
    else
      cout << A - B << endl;
  }
}

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

int main() {
  int A, B, C, a, b, c;
  long long K;
  cin >> A >> B >> C >> K;
  if (K % 2 == 0)
    cout << A - B << endl;
  else
    cout << B - A << endl;
}
Problem p03345 (C++)

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

using namespace std;

/***TEMPLATE***/
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()

#define F first
#define S second
#define pb push_back

#define endl '\n'

const int max4 = 10004;
const int maxx = 100005;
const int max6 = 1000006;
const int lg5 = 17;

const int INF = 2 * 1000000007;
const long long INFLL = 4LL * 1000000000 * 1000000000;

/***************/

int powmod(int a, int b, int mod) {
  int res = 1;
  a %= mod;
  for (; b; b >>= 1) {
    if (b & 1) {
      res = 1LL * res * a % mod;
    }
    a = 1LL * a * a % mod;
  }
  return res;
}

int gcd(int a, int b) {
  while (b > 0) {
    int t = a % b;
    a = b, b = t;
  }
  return a;
}

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

int is_prime(int n) {
  if (n <= 1 || n > 3 && (n % 2 == 0 || n % 3 == 0))
    return 0;
  for (int i = 5, t = 2; i * i <= n; i += t, t = 6 - t)
    if (n % i == 0)
      return 0;
  return 1;
}

/******Don't forget to use long long when needed!!******/

int main() {
  // freopen("in.txt","r",stdin);
  // freopen("out.txt","w",stdout);
  ios_base ::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  long long a, b, c, k;
  cin >> a >> b >> c >> k;
  if (a == b && b == c) {
    cout << 0 << endl;
    return 0;
  }
  while (k > 0) {
    long long aa = b + c, bb = a + c, cc = a + b;
    a = aa, b = bb, c = cc;
    if (abs(a - b) > (long long)1e18) {
      cout << "Unfair" << endl;
      return 0;
    }
    k--;
  }
  cout << a - b << endl;
  return 0;
}


Fixed submission:
/****Author: Barish Namazov****/
#include <bits/stdc++.h>

using namespace std;

/***TEMPLATE***/
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()

#define F first
#define S second
#define pb push_back

#define endl '\n'

const int max4 = 10004;
const int maxx = 100005;
const int max6 = 1000006;
const int lg5 = 17;

const int INF = 2 * 1000000007;
const long long INFLL = 4LL * 1000000000 * 1000000000;

/***************/

int powmod(int a, int b, int mod) {
  int res = 1;
  a %= mod;
  for (; b; b >>= 1) {
    if (b & 1) {
      res = 1LL * res * a % mod;
    }
    a = 1LL * a * a % mod;
  }
  return res;
}

int gcd(int a, int b) {
  while (b > 0) {
    int t = a % b;
    a = b, b = t;
  }
  return a;
}

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

int is_prime(int n) {
  if (n <= 1 || n > 3 && (n % 2 == 0 || n % 3 == 0))
    return 0;
  for (int i = 5, t = 2; i * i <= n; i += t, t = 6 - t)
    if (n % i == 0)
      return 0;
  return 1;
}

/******Don't forget to use long long when needed!!******/

int main() {
  // freopen("in.txt","r",stdin);
  // freopen("out.txt","w",stdout);
  ios_base ::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  long long a, b, c, k;
  cin >> a >> b >> c >> k;
  cout << (k & 1 ? b - a : a - b) << endl;
  return 0;
}
Problem p03345 (C++)

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

int main() {
  ll a, b, c, k;
  cin >> a >> b >> c >> k;
  ll x, y, z;
  rep(i, k) {
    x = b + c;
    y = a + c;
    z = a + b;
    a = x, b = y, c = z;
    if (a - b > pow(10, 18)) {
      cout << "Unfair" << endl;
      return 0;
    }
  }
  cout << a - b << endl;
}

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

int main() {
  ll a, b, c, k;
  cin >> a >> b >> c >> k;
  if (k % 2 == 0)
    cout << a - b << endl;
  else
    cout << b - a << endl;
}
Problem p03345 (C++)

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

int main() {
  long long int a, b, c, k, bb;
  cin >> a >> b >> c >> k;
  for (long long int i = 0; i < k; i++) {
    bb = b;
    b = a;
    a = bb;
    if (abs(a - b) >= 1000000000000000000) {
      cout << "Unfair" << endl;
      return 0;
    }
  }
  cout << a - b << endl;
}


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

int main() {
  long long int a, b, c, k, bb;
  cin >> a >> b >> c >> k;
  if (abs(a - b) >= 1000000000000000000)
    cout << "Unfair" << endl;
  else if (k % 2 == 0)
    cout << a - b << endl;
  else
    cout << b - a << endl;
}
Problem p03345 (C++)

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

using namespace std;

int main() {
  long long A, B, C, K;
  cin >> A >> B >> C >> K;
  for (int i = 0; i < K; i++) {
    int na = B + C;
    int nb = A + C;
    int nc = A + B;
    A = na, B = nb, C = nc;
    if (A == B && B == C)
      break;
  }
  cout << A - B << endl;
  return 0;
}

Fixed submission:
#include <iostream>

using namespace std;

int main() {
  long long A, B, C, K;
  cin >> A >> B >> C >> K;
  cout << (A - B) * (K % 2 ? -1 : 1) << endl;
  return 0;
}
Problem p03345 (Python)

Buggy submission (status: Time Limit Exceeded):
if __name__ == "__main__":
    inputList = input().split()

    A = int(inputList[0])
    B = int(inputList[1])
    C = int(inputList[2])
    K = int(inputList[3])
    limit = pow(10, 18)

    for num in range(K):
        _A = B + C
        _B = A + C
        _C = A + B

        A = _A
        B = _B
        C = _C

        if A - B > limit:
            break

    result = A - B

    if result > limit:
        result = "Unfair"

    print(result)


Fixed submission:
if __name__ == "__main__":
    inputList = input().split()

    A = int(inputList[0])
    B = int(inputList[1])
    C = int(inputList[2])
    K = int(inputList[3])
    limit = pow(10, 18)

    if K % 2 == 0:
        result = A - B
    else:
        result = B - A

    if result > limit:
        result = "Unfair"

    print(result)
Problem p03345 (Python)

Buggy submission (status: Time Limit Exceeded):
a, b, c, k = map(int, input().split())

if a == b == c:
    print(0)
    exit(0)
for i in range(k):
    w_a = b + c
    w_b = a + c
    w_c = a + b
    a = w_a
    b = w_b
    c = w_c
print(a - b)


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

if k % 2 == 0:
    print(a - b if abs(a - b) < 10**18 else "Unfair")
else:
    print(b - a if abs(b - a) < 10**18 else "Unfair")
Problem p03345 (Python)

Buggy submission (status: Time Limit Exceeded):
a, b, c, k = map(int, input().split())

sum = (a + b + c) * (2**k)

ans = b - a if k % 2 == 1 else a - b

print(ans if ans <= 10**18 else "Unfair")


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

ans = b - a if k % 2 == 1 else a - b

print(ans if ans <= 10**18 else "Unfair")
Problem p03346 (C++)

Buggy submission (status: Runtime Error):
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <algorithm>
#include <array>
#include <bitset>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
// #define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;
typedef tuple<int, int, int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
int dx[8] = {0, 0, -1, 1, 1, 1, -1, -1};
int dy[8] = {-1, 1, 0, 0, 1, -1, 1, -1};
const int SIZE = 100050;
// ここまでテンプレ
int main() {
  int N;
  cin >> N;
  vint A;
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    A.pb(a);
  }
  int B[SIZE] = {};
  for (int i = 0; i < N; i++) {
    B[A[i]] = i;
  }
  int maxi = 1, temp = 1;
  for (int i = 1; i <= N; i++) {
    if (B[i + 1] > B[i])
      temp++;
    else {
      maxi = max(maxi, temp);
      temp = 1;
    }
  }
  cout << N - maxi << endl;
  return 0;
}

Fixed submission:
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <algorithm>
#include <array>
#include <bitset>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
// #define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;
typedef tuple<int, int, int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
int dx[8] = {0, 0, -1, 1, 1, 1, -1, -1};
int dy[8] = {-1, 1, 0, 0, 1, -1, 1, -1};
const int SIZE = 200050;
// ここまでテンプレ
int main() {
  int N;
  cin >> N;
  vint A;
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    A.pb(a);
  }
  int B[SIZE] = {};
  for (int i = 0; i < N; i++) {
    B[A[i]] = i;
  }
  int maxi = 1, temp = 1;
  for (int i = 1; i <= N; i++) {
    if (B[i + 1] > B[i])
      temp++;
    else {
      maxi = max(maxi, temp);
      temp = 1;
    }
  }
  cout << N - maxi << endl;
  return 0;
}
Problem p03346 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define sanyes                                                                 \
  ios_base::sync_with_stdio(0), cout.tie(0);                                   \
  cin.tie(0);
#define llong long long int
#define pb push_back
#define bpc __builtin_popcount
#define f first
#define s second

const llong mxn = 1e5 + 7;
const llong mod = 1e9 + 7;
const llong inf = 1e18 + 9;

using namespace std;

llong n, a[mxn], dp[mxn], mx = -inf;

int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (int i = 1; i <= n; i++) {
    dp[a[i]] = dp[a[i] - 1] + 1;
    mx = max(dp[a[i]], mx);
  }
  cout << n - mx;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define sanyes                                                                 \
  ios_base::sync_with_stdio(0), cout.tie(0);                                   \
  cin.tie(0);
#define llong long long int
#define pb push_back
#define bpc __builtin_popcount
#define f first
#define s second

const llong mxn = 2 * 1e5 + 7;
const llong mod = 1e9 + 7;
const llong inf = 1e18 + 9;

using namespace std;

llong n, a[mxn], dp[mxn], mx = -inf;

int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (int i = 1; i <= n; i++) {
    dp[a[i]] = dp[a[i] - 1] + 1;
    mx = max(dp[a[i]], mx);
  }
  cout << n - mx;
  return 0;
}
Problem p03346 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cassert>
// #include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
// #include <random>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

/*
unsigned seed1 = std::chrono::system_clock::now().time_since_epoch().count();
mt19937 g1.seed(seed1);
*/
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<pii, pii> ppiipii;
typedef pair<int, ppiipii> pippiipii;
typedef pair<int, pii> pipii;
typedef pair<pii, int> ppiii;
typedef pair<int, ppiii> pippiii;
typedef pair<int, ll> pill;
typedef pair<int, double> pid;
typedef pair<string, string> pss;
// note to self, the below two triggers someone
typedef pair<ll, ll> pll;
typedef pair<ll, int> plli;
typedef long double ld;

int loc[100005];
int n;

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    int t;
    scanf("%d", &t);
    loc[t] = i;
  }
  int maxLen = 0;
  for (int i = 1; i <= n;) {
    int last = loc[i];
    int j = i + 1;
    while (j <= n && loc[j] > last) {
      last = loc[j++];
    }
    maxLen = max(maxLen, j - i);
    i = j;
  }
  printf("%d\n", n - maxLen);
}


Fixed submission:
#include <algorithm>
#include <cassert>
// #include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
// #include <random>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

/*
unsigned seed1 = std::chrono::system_clock::now().time_since_epoch().count();
mt19937 g1.seed(seed1);
*/
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<pii, pii> ppiipii;
typedef pair<int, ppiipii> pippiipii;
typedef pair<int, pii> pipii;
typedef pair<pii, int> ppiii;
typedef pair<int, ppiii> pippiii;
typedef pair<int, ll> pill;
typedef pair<int, double> pid;
typedef pair<string, string> pss;
// note to self, the below two triggers someone
typedef pair<ll, ll> pll;
typedef pair<ll, int> plli;
typedef long double ld;

int loc[200005];
int n;

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    int t;
    scanf("%d", &t);
    loc[t] = i;
  }
  int maxLen = 0;
  for (int i = 1; i <= n;) {
    int last = loc[i];
    int j = i + 1;
    while (j <= n && loc[j] > last) {
      last = loc[j++];
    }
    maxLen = max(maxLen, j - i);
    i = j;
  }
  printf("%d\n", n - maxLen);
}