prithivMLmods/Coder-Stat huggingface dataset:
Problem p02716 (Python)

Buggy submission (status: Runtime Error):
def main():
    from functools import lru_cache

    inf = 2 * 10**14 + 1

    N = int(input())
    (*a,) = map(int, input().split())

    @lru_cache(maxsize=None)
    def recursion(cur, need):
        """
        cur: pickableなindex
        """
        if cur >= N:
            if need == 0:
                return 0
            else:
                return -inf

        rest = N - cur
        if (rest + 1) // 2 < need:
            return -inf

        return max(a[cur] + recursion(cur + 2, need - 1), recursion(cur + 1, need))

    ans = recursion(0, N // 2)

    print(ans)


if __name__ == "__main__":
    main()


Fixed submission:
def main():
    from functools import lru_cache
    import sys

    sys.setrecursionlimit(10**7)

    inf = 2 * 10**14 + 1

    N = int(input())
    (*a,) = map(int, input().split())

    @lru_cache(maxsize=None)
    def recursion(cur, need):
        """
        cur: pickableなindex
        """
        if cur >= N:
            if need == 0:
                return 0
            else:
                return -inf

        rest = N - cur
        if (rest + 1) // 2 < need:
            return -inf

        return max(a[cur] + recursion(cur + 2, need - 1), recursion(cur + 1, need))

    ans = recursion(0, N // 2)

    print(ans)


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

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 1000000000
#define LINF 1000000000000000000
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define bit(n) (1LL << (n))
using namespace std;

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

int main() {

  int N;
  cin >> N;
  vector<long long> A(N);
  rep(i, N) cin >> A[i];

  vector<vector<long long>> dp(N, vector<long long>(3, (-1) * LINF));
  dp[0][0] = A[0];
  dp[1][1] = A[1];
  dp[2][0] = A[0] + A[2];
  dp[2][2] = A[2];
  for (int i = 3; i < N; i++) {
    dp[i][0] = dp[i - 2][0] + A[i];
    dp[i][1] = max(dp[i - 2][1] + A[i], dp[i - 3][0] + A[i]);
    dp[i][2] = max(
        dp[i - 2][2] + A[i],
        max(dp[i - 3][1] + A[i], i > 3 ? dp[i - 4][0] + A[i] : (-1) * LINF));
  }

  if (N % 2 == 0)
    cout << max(dp[N - 2][0], dp[N - 1][1]) << endl;
  else
    cout << max(dp[N - 3][0], max(dp[N - 2][1], dp[N - 1][2])) << endl;

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 1000000000
#define LINF 1000000000000000000
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define bit(n) (1LL << (n))
using namespace std;

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

int main() {

  int N;
  cin >> N;
  vector<long long> A(N);
  rep(i, N) cin >> A[i];

  if (N == 2) {
    cout << max(A[0], A[1]) << endl;
    return 0;
  }

  vector<vector<long long>> dp(N, vector<long long>(3, (-1) * LINF));
  dp[0][0] = A[0];
  dp[1][1] = A[1];
  dp[2][0] = A[0] + A[2];
  dp[2][2] = A[2];
  for (int i = 3; i < N; i++) {
    dp[i][0] = dp[i - 2][0] + A[i];
    dp[i][1] = max(dp[i - 2][1] + A[i], dp[i - 3][0] + A[i]);
    dp[i][2] = max(
        dp[i - 2][2] + A[i],
        max(dp[i - 3][1] + A[i], i > 3 ? dp[i - 4][0] + A[i] : (-1) * LINF));
  }

  if (N % 2 == 0)
    cout << max(dp[N - 2][0], dp[N - 1][1]) << endl;
  else
    cout << max(dp[N - 3][0], max(dp[N - 2][1], dp[N - 1][2])) << endl;

  return 0;
}
Problem p02716 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < int(n); ++i)
#define all(a) (a).begin(), (a).end()
typedef long long ll;
#define INF (ll)1e16

int main(void) {
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  int MAX_JUMP = (n % 2 == 0) ? 2 : 3;
  vector<ll> dp[MAX_JUMP];
  rep(i, MAX_JUMP) dp[i] = vector<ll>(n, -INF);
  rep(i, MAX_JUMP) dp[i][i] = a[i];
  rep(i, n) {
    rep(k, MAX_JUMP) {
      if (i < k)
        continue;
      rep(j, MAX_JUMP) {
        if (k + j <= 2 && i + j + 2 < n) {
          dp[k + j][i + j + 2] =
              max(dp[k + j][i + j + 2], dp[k][i] + a[i + j + 2]);
        }
      }
    }
  }
  if (n % 2 == 0) {
    cout << max({dp[1][n - 1], dp[0][n - 2]}) << endl;
  } else {
    cout << max({dp[2][n - 1], dp[1][n - 2], dp[0][n - 3]}) << endl;
  }

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < int(n); ++i)
#define all(a) (a).begin(), (a).end()
typedef long long ll;
#define INF (ll)1e16

int main(void) {
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  int MAX_JUMP = (n % 2 == 0) ? 2 : 3;
  vector<ll> dp[MAX_JUMP];
  rep(i, MAX_JUMP) dp[i] = vector<ll>(n, -INF);
  rep(i, MAX_JUMP) dp[i][i] = a[i];
  rep(i, n) {
    rep(k, MAX_JUMP) {
      if (i < k)
        continue;
      rep(j, MAX_JUMP) {
        if (k + j <= MAX_JUMP - 1 && i + j + 2 < n) {
          dp[k + j][i + j + 2] =
              max(dp[k + j][i + j + 2], dp[k][i] + a[i + j + 2]);
        }
      }
    }
  }
  if (n % 2 == 0) {
    cout << max({dp[1][n - 1], dp[0][n - 2]}) << endl;
  } else {
    cout << max({dp[2][n - 1], dp[1][n - 2], dp[0][n - 3]}) << endl;
  }

  return 0;
}
Problem p02716 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ll long long
#define AC                                                                     \
  ios::sync_with_stdio(false);                                                 \
  cin.tie(0);
const ll N = 20005;
ll dp[N][2];
ll arr[N];

int main() {
  AC ll n;
  cin >> n;
  for (int i = 1; i <= n; i++)
    cin >> arr[i];
  dp[2][0] = arr[1];
  dp[2][1] = arr[2];
  for (int i = 3; i <= n; i++) {
    if (i & 1) {
      dp[i][1] = max({dp[i - 2][1], dp[i - 2][0], dp[i - 3][1], dp[i - 3][0]}) +
                 arr[i];
      dp[i][0] = max(dp[i - 1][0], dp[i - 1][1]);
    } else {
      dp[i][1] = max(dp[i - 2][1], dp[i - 2][0]) + arr[i];
      dp[i][0] = arr[i - 1] + dp[i - 2][0];
    }
  }
  cout << max(dp[n][0], dp[n][1]) << '\n';
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ll long long
#define AC                                                                     \
  ios::sync_with_stdio(false);                                                 \
  cin.tie(0);
const ll N = 2e5;
ll dp[N][2];
ll arr[N];

int main() {
  AC ll n;
  cin >> n;
  for (int i = 1; i <= n; i++)
    cin >> arr[i];
  dp[2][0] = arr[1];
  dp[2][1] = arr[2];
  for (int i = 3; i <= n; i++) {
    if (i & 1) {
      dp[i][1] = max({dp[i - 2][1], dp[i - 2][0], dp[i - 3][1], dp[i - 3][0]}) +
                 arr[i];
      dp[i][0] = max(dp[i - 1][0], dp[i - 1][1]);
    } else {
      dp[i][1] = max(dp[i - 2][1], dp[i - 2][0]) + arr[i];
      dp[i][0] = arr[i - 1] + dp[i - 2][0];
    }
  }
  cout << max(dp[n][0], dp[n][1]) << '\n';
}
Problem p02716 (C++)

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

using namespace std;

const int N = 1e5 + 10;
long long dp[N][2][2];
int n;
int a[N];

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

  int n;
  cin >> n;
  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < 2; ++j) {
      for (int k = 0; k < 2; ++k) {
        dp[i][j][k] = -1e18;
      }
    }
  }
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
  }
  dp[0][0][0] = dp[0][1][0] = dp[0][0][1] = dp[0][1][1] = 0;
  for (int i = 1; i <= n; ++i) {
    for (int j = 0; j < 2; ++j) {
      for (int k = 0; k < 2; ++k) {
        if (!(j & k)) {
          for (int g = 0; g < 2; ++g) {
            for (int t = 0; t < 2; ++t) {
              int x = (i + 1) / 2 - g, y = i / 2 - t;
              if (y + j == x and y >= 0) {
                dp[i][g][j] = max(dp[i][g][j], dp[i - 1][t][k] + j * a[i]);
              }
            }
          }
        }
      }
    }
  }
  long long ans = -1e18;
  for (int i = 1; i <= n; ++i) {
    for (int j = 0; j < 2; ++j) {
      if ((i + 1) / 2 - j == n / 2) {
        for (int k = 0; k < 2; ++k) {
          ans = max(ans, dp[i][j][k]);
        }
      }
    }
  }
  cout << ans;

  return 0;
}

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

using namespace std;

const int N = 2e5 + 10;
long long dp[N][2][2];
int n;
int a[N];

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

  int n;
  cin >> n;
  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < 2; ++j) {
      for (int k = 0; k < 2; ++k) {
        dp[i][j][k] = -1e18;
      }
    }
  }
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
  }
  dp[0][0][0] = dp[0][1][0] = dp[0][0][1] = dp[0][1][1] = 0;
  for (int i = 1; i <= n; ++i) {
    for (int j = 0; j < 2; ++j) {
      for (int k = 0; k < 2; ++k) {
        if (!(j & k)) {
          for (int g = 0; g < 2; ++g) {
            for (int t = 0; t < 2; ++t) {
              int x = (i + 1) / 2 - g, y = i / 2 - t;
              if (y + j == x and y >= 0) {
                dp[i][g][j] = max(dp[i][g][j], dp[i - 1][t][k] + j * a[i]);
              }
            }
          }
        }
      }
    }
  }
  long long ans = -1e18;
  for (int i = 1; i <= n; ++i) {
    for (int j = 0; j < 2; ++j) {
      if ((i + 1) / 2 - j == n / 2) {
        for (int k = 0; k < 2; ++k) {
          ans = max(ans, dp[i][j][k]);
        }
      }
    }
  }
  cout << ans;

  return 0;
}
Problem p02716 (C++)

Buggy submission (status: Runtime Error):
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define re register
#define pb push_back
#define fi first
#define se second
const int N = 1e5 + 10;
const int M = 1e6;
const int mod7 = 1e9 + 7;
const int mod = 1e9 + 7;
void read(int &a) {
  a = 0;
  int d = 1;
  char ch;
  while (ch = getchar(), ch > '9' || ch < '0')
    if (ch == '-')
      d = -1;
  a = ch ^ 48;
  while (ch = getchar(), ch >= '0' && ch <= '9')
    a = (a << 3) + (a << 1) + (ch ^ 48);
  a *= d;
}
void read(ll &a) {
  a = 0;
  int d = 1;
  char ch;
  while (ch = getchar(), ch > '9' || ch < '0')
    if (ch == '-')
      d = -1;
  a = ch ^ 48;
  while (ch = getchar(), ch >= '0' && ch <= '9')
    a = (a << 3) + (a << 1) + (ch ^ 48);
  a *= d;
}
ll f1[N], f2[N], f3[N];
int a[N];
int main() {
  int n;
  read(n);
  for (re int i = 1; i <= n; i++)
    read(a[i]);
  if (n % 2 == 0) {
    f1[1] = a[1];
    f1[2] = a[2];
    for (re int i = 3; i <= n; i++) {
      if (i & 1)
        f1[i] = f1[i - 2] + a[i];
      else
        f1[i] = max(f1[i - 3], f1[i - 2]) + a[i];
    }
    printf("%lld\n", max(f1[n - 1], f1[n]));
  } else {
    f1[1] = a[1];
    f2[1] = a[2];
    f3[1] = a[3];
    for (re int i = 2; i <= n / 2; i++) {
      f1[i] = f1[i - 1] + a[(i << 1) - 1];
      f2[i] = max(f1[i - 1], f2[i - 1]) + a[(i << 1)];
      f3[i] = max(f1[i - 1], max(f2[i - 1], f3[i - 1])) + a[(i << 1) + 1];
    }
    printf("%lld\n", max(f1[n / 2], max(f2[n / 2], f3[n / 2])));
  }
  return 0;
}

Fixed submission:
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define re register
#define pb push_back
#define fi first
#define se second
const int N = 1e6 + 10;
const int M = 1e6;
const int mod7 = 1e9 + 7;
const int mod = 1e9 + 7;
void read(int &a) {
  a = 0;
  int d = 1;
  char ch;
  while (ch = getchar(), ch > '9' || ch < '0')
    if (ch == '-')
      d = -1;
  a = ch ^ 48;
  while (ch = getchar(), ch >= '0' && ch <= '9')
    a = (a << 3) + (a << 1) + (ch ^ 48);
  a *= d;
}
void read(ll &a) {
  a = 0;
  int d = 1;
  char ch;
  while (ch = getchar(), ch > '9' || ch < '0')
    if (ch == '-')
      d = -1;
  a = ch ^ 48;
  while (ch = getchar(), ch >= '0' && ch <= '9')
    a = (a << 3) + (a << 1) + (ch ^ 48);
  a *= d;
}
ll f1[N], f2[N], f3[N];
int a[N];
int main() {
  int n;
  read(n);
  for (re int i = 1; i <= n; i++)
    read(a[i]);
  if (n % 2 == 0) {
    f1[1] = a[1];
    f1[2] = a[2];
    for (re int i = 3; i <= n; i++) {
      if (i & 1)
        f1[i] = f1[i - 2] + a[i];
      else
        f1[i] = max(f1[i - 3], f1[i - 2]) + a[i];
    }
    printf("%lld\n", max(f1[n - 1], f1[n]));
  } else {
    f1[1] = a[1];
    f2[1] = a[2];
    f3[1] = a[3];
    for (re int i = 2; i <= n / 2; i++) {
      f1[i] = f1[i - 1] + a[(i << 1) - 1];
      f2[i] = max(f1[i - 1], f2[i - 1]) + a[(i << 1)];
      f3[i] = max(f1[i - 1], max(f2[i - 1], f3[i - 1])) + a[(i << 1) + 1];
    }
    printf("%lld\n", max(f1[n / 2], max(f2[n / 2], f3[n / 2])));
  }
  return 0;
}
Problem p02716 (C++)

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

// https://atcoder.jp/contests/abc159/submissions/14840254
const long long OO = (long long)1e18;

const int N = 100008;
int n;
long long a[N];

long long dp[N][3];
// dp[i][j] is maximum possible sum choosing (i+1-j)/2 elements from first i
// elements. This is NOT a floor! So half the dp elements will be impossible
// solely because it's impossible to choose half an element.

int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }

  dp[0][0] = -OO;
  dp[0][1] = 0;
  dp[0][2] = -OO;
  dp[1][0] = a[0];
  dp[1][1] = -OO;
  dp[1][2] = 0;

  for (int i = 2; i <= n; i++) {
    // note that we are computing dp[i] using a[i-1] and dp[i-1]
    for (int j = 0; j < 3; j++) {
      // take a[i-1]
      dp[i][j] = dp[i - 2][j] + a[i - 1];

      if (j) {
        // we have slack; don't take a[i-1]
        dp[i][j] = max(dp[i][j], dp[i - 1][j - 1]);
      }
    }
  }

  cout << dp[n][n % 2 == 0 ? 1 : 2];
}


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

// https://atcoder.jp/contests/abc159/submissions/14840254
const long long OO = (long long)1e18;

const int N = 200008;
int n;
long long a[N];

long long dp[N][3];
// dp[i][j] is maximum possible sum choosing (i+1-j)/2 elements from first i
// elements. This is NOT a floor! So half the dp elements will be impossible
// solely because it's impossible to choose half an element.

int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }

  dp[0][0] = -OO;
  dp[0][1] = 0;
  dp[0][2] = -OO;
  dp[1][0] = a[0];
  dp[1][1] = -OO;
  dp[1][2] = 0;

  for (int i = 2; i <= n; i++) {
    // note that we are computing dp[i] using a[i-1] and dp[i-1]
    for (int j = 0; j < 3; j++) {
      // take a[i-1]
      dp[i][j] = dp[i - 2][j] + a[i - 1];

      if (j) {
        // we have slack; don't take a[i-1]
        dp[i][j] = max(dp[i][j], dp[i - 1][j - 1]);
      }
    }
  }

  cout << dp[n][n % 2 == 0 ? 1 : 2];
}
Problem p02716 (C++)

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

int main() {
  int N;
  cin >> N;
  VI a(N);
  rep(i, N) { cin >> a.at(i); }
  ll maxi = max(max(a.at(0), a.at(1)), a.at(2));
  ll left = a.at(0);
  ll emax = max(a.at(0), a.at(1));
  for (int i = 4; i < N + 1; i++) {
    if (i % 2 == 0) {
      left += a.at(i - 2);
      emax = max(emax + a.at(i - 1), left);
    } else {
      maxi = max(emax, maxi + a.at(i - 1));
    }
  }
  if (N % 2 == 0) {
    cout << emax << endl;
  } else {
    cout << maxi << endl;
  }
  return 0;
}


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

int main() {
  int N;
  cin >> N;
  VI a(N);
  rep(i, N) { cin >> a.at(i); }
  if (N == 2) {
    cout << max(a.at(0), a.at(1)) << endl;
    return 0;
  }
  ll maxi = max(max(a.at(0), a.at(1)), a.at(2));
  ll left = a.at(0);
  ll emax = max(a.at(0), a.at(1));
  for (int i = 4; i < N + 1; i++) {
    if (i % 2 == 0) {
      left += a.at(i - 2);
      emax = max(emax + a.at(i - 1), left);
    } else {
      maxi = max(emax, maxi + a.at(i - 1));
    }
  }
  if (N % 2 == 0) {
    cout << emax << endl;
  } else {
    cout << maxi << endl;
  }
  return 0;
}
Problem p02716 (C++)

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

int64_t dp(state stat, const vector<int64_t> &data, map<state, int64_t> *memo) {
  if (memo->count(stat)) {
    return memo->at(stat);
  } else {
    const int N = data.size();
    int rem, id;
    tie(rem, id) = stat;

    if (rem == 0) {
      return memo->operator[](stat) = 0;
    } else if (2 * rem - 1 == N - id) {
      int64_t sum_odd = 0;
      for (int i = id; i < N; i += 2) {
        sum_odd += data.at(i);
      }

      return memo->operator[](stat) = sum_odd;
    } else if (2 * rem - 1 > N - id) {
      return memo->operator[](stat) = INT64_MIN;
    } else {
      state pick = make_pair(rem - 1, id + 2);
      state nopick = make_pair(rem, id + 1);
      return memo->operator[](stat) = max(data.at(id) + dp(pick, data, memo),
                                          dp(nopick, data, memo));
    }
  }
}

int main() {
  int N;
  cin >> N;

  vector<int64_t> data(N);
  for (int i = 0; i < N; i++) {
    cin >> data.at(i);
  }
  map<state, int64_t> memo;

  cout << dp(make_pair(N / 2, 0), data, &memo) << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using state = pair<int, int>;

int64_t dp(state stat, const vector<int64_t> &data, map<state, int64_t> *memo) {
  if (memo->count(stat)) {
    return memo->at(stat);
  } else {
    const int N = data.size();
    int rem, id;
    tie(rem, id) = stat;

    if (rem == 0) {
      return memo->operator[](stat) = 0;
    } else if (2 * rem - 1 > N - id) {
      return memo->operator[](stat) = INT64_MIN;
    } else {
      state pick = make_pair(rem - 1, id + 2);
      state nopick = make_pair(rem, id + 1);
      return memo->operator[](stat) = max(data.at(id) + dp(pick, data, memo),
                                          dp(nopick, data, memo));
    }
  }
}

int main() {
  int N;
  cin >> N;

  vector<int64_t> data(N);
  for (int i = 0; i < N; i++) {
    cin >> data.at(i);
  }
  map<state, int64_t> memo;

  cout << dp(make_pair(N / 2, 0), data, &memo) << endl;
}
Problem p02716 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

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

using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;

ll power(long a, long b) {
  return b ? power(a * a % mod, b / 2) * (b % 2 ? a : 1) % mod : 1;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  int N;
  cin >> N;
  int A[200100];
  rep(i, N) cin >> A[i];

  long dp[100100][2][3];
  rep(i, N + 1) rep(x, 2) rep(y, 3) dp[i][x][y] = -1LL << 60;
  dp[0][1][0] = 0;
  for (int i = 0; i < N; i++) {
    rep(j, 2) rep(k, 3) {
      // not take
      if (k + j < 3)
        dp[i + 1][1][k + j] = max(dp[i + 1][1][k + j], dp[i][j][k]);
      // take
      if (j == 1)
        dp[i + 1][0][k] = max(dp[i + 1][0][k], dp[i][j][k] + A[i]);
    }
  }
  if (N % 2 == 0)
    cout << max(dp[N][1][0], dp[N][0][1]) << "\n";
  else
    cout << max(dp[N][0][2], dp[N][1][1]) << "\n";
}

Fixed submission:
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

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

using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;

ll power(long a, long b) {
  return b ? power(a * a % mod, b / 2) * (b % 2 ? a : 1) % mod : 1;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  int N;
  cin >> N;
  int A[200100];
  rep(i, N) cin >> A[i];

  long dp[200100][2][3];
  rep(i, N + 1) rep(x, 2) rep(y, 3) dp[i][x][y] = -1LL << 60;
  dp[0][1][0] = 0;
  for (int i = 0; i < N; i++) {
    rep(j, 2) rep(k, 3) {
      // not take
      if (k + j < 3)
        dp[i + 1][1][k + j] = max(dp[i + 1][1][k + j], dp[i][j][k]);
      // take
      if (j == 1)
        dp[i + 1][0][k] = max(dp[i + 1][0][k], dp[i][j][k] + A[i]);
    }
  }
  if (N % 2 == 0)
    cout << max(dp[N][1][0], dp[N][0][1]) << "\n";
  else
    cout << max(dp[N][0][2], dp[N][1][1]) << "\n";
}
Problem p02716 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define mp make_pair
#define sqr(x) (x) * (x)
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
const int maxn = 200007;
const ll inf = 0x3f3f3f3f3f3f3f3f;
ll read() {
  ll x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-')
      f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9')
    x = x * 10 + ch - '0', ch = getchar();
  return x * f;
}
ll a[maxn];
ll dp[maxn][11], Sum;
int main() {
  freopen("test.in", "r", stdin);
  int n = read();
  for (int i = 1; i <= n; i++)
    a[i] = read(), Sum += a[i];
  memset(dp, 0x3f, sizeof(dp));
  dp[0][5] = 0;
  dp[1][6] = a[1];
  for (int i = 2; i <= n + 1; i++) {
    for (int k = 0; k <= 10; k++) {
      int now = i / 2 + k - 5;
      if (now >= 1) {
        int p1 = now - 1 - (i - 1) / 2 + 5;
        int p2 = now - 1 - (i - 2) / 2 + 5;
        if (p1 > 10 || p2 > 10 || p1 < 0 || p2 < 0)
          continue;
        dp[i][k] = min(dp[i - 1][p1], dp[i - 2][p2]) + a[i];
      }
    }
  }
  int you = n - (n / 2) + 1;
  int p = you - (n + 1) / 2 + 5;
  cout << Sum - dp[n + 1][p];
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define mp make_pair
#define sqr(x) (x) * (x)
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
const int maxn = 200007;
const ll inf = 0x3f3f3f3f3f3f3f3f;
ll read() {
  ll x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-')
      f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9')
    x = x * 10 + ch - '0', ch = getchar();
  return x * f;
}
ll a[maxn];
ll dp[maxn][11], Sum;
int main() {

  int n = read();
  for (int i = 1; i <= n; i++)
    a[i] = read(), Sum += a[i];
  memset(dp, 0x3f, sizeof(dp));
  dp[0][5] = 0;
  dp[1][6] = a[1];
  for (int i = 2; i <= n + 1; i++) {
    for (int k = 0; k <= 10; k++) {
      int now = i / 2 + k - 5;
      if (now >= 1) {
        int p1 = now - 1 - (i - 1) / 2 + 5;
        int p2 = now - 1 - (i - 2) / 2 + 5;
        if (p1 > 10 || p2 > 10 || p1 < 0 || p2 < 0)
          continue;
        dp[i][k] = min(dp[i - 1][p1], dp[i - 2][p2]) + a[i];
      }
    }
  }
  int you = n - (n / 2) + 1;
  int p = you - (n + 1) / 2 + 5;
  cout << Sum - dp[n + 1][p];
  return 0;
}
Problem p02716 (C++)

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

typedef long long ll;

const int N = 100 * 1000 + 20;
ll n, sum[N], dp[N], a[N];

int main() {
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> a[i];
  for (int i = 0; i < n; i++)
    sum[i] = a[i] + (i > 1 ? sum[i - 2] : 0);
  for (int i = 1; i < n; i++) {
    if (i % 2 == 0)
      dp[i] = max(a[i] + dp[i - 2], dp[i - 1]);
    else
      dp[i] = max(a[i] + dp[i - 2], sum[i - 1]);
  }
  return cout << dp[n - 1] << endl, 0;
}


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

typedef long long ll;

const int N = 2 * 100 * 1000 + 20;
ll n, sum[N], dp[N], a[N];

int main() {
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> a[i];
  for (int i = 0; i < n; i++)
    sum[i] = a[i] + (i > 1 ? sum[i - 2] : 0);
  for (int i = 1; i < n; i++) {
    if (i % 2 == 0)
      dp[i] = max(a[i] + dp[i - 2], dp[i - 1]);
    else
      dp[i] = max(a[i] + dp[i - 2], sum[i - 1]);
  }
  return cout << dp[n - 1] << endl, 0;
}
Problem p02716 (C++)

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

using namespace std;

const long long INF = 1e18;

// long long dp[200005][4];
long long dp[100][4];

// dp[i][j] : i個目まで見てj個余分なｘ（バツ）を入れたときのMAX

int main() {
  int N;
  cin >> N;
  vector<long long> a(N);
  for (int i = 0; i < N; ++i)
    cin >> a[i];

  // K: 何個余分のバツを入れれる？奇数は2で偶数は1
  int K = 1 + N % 2;

  for (int i = 0; i < N + 1; ++i) {
    for (int j = 0; j < K + 1; ++j) {
      dp[i][j] = -INF;
    }
  }

  dp[0][0] = 0;
  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < K + 1; ++j) {
      // バツを一個挿入（今見てる数をスキップ）
      dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j]);
      // 次の数を当てはめる,0からなので割り切れたらそれはカウント
      long long now = dp[i][j];
      if ((i + j) % 2 == 0)
        now += a[i];
      dp[i + 1][j] = max(dp[i + 1][j], now);
    }
  }

  long long ans = dp[N][K];
  cout << ans << endl;
}

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

using namespace std;

const long long INF = 1e18;

long long dp[200005][4];
// long long dp[100][4];

// dp[i][j] : i個目まで見てj個余分なｘ（バツ）を入れたときのMAX

int main() {
  int N;
  cin >> N;
  vector<long long> a(N);
  for (int i = 0; i < N; ++i)
    cin >> a[i];

  // K: 何個余分のバツを入れれる？奇数は2で偶数は1
  int K = 1 + N % 2;

  for (int i = 0; i < N + 1; ++i) {
    for (int j = 0; j < K + 1; ++j) {
      dp[i][j] = -INF;
    }
  }

  dp[0][0] = 0;
  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < K + 1; ++j) {
      // バツを一個挿入（今見てる数をスキップ）
      dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j]);
      // 次の数を当てはめる,0からなので割り切れたらそれはカウント
      long long now = dp[i][j];
      if ((i + j) % 2 == 0)
        now += a[i];
      dp[i + 1][j] = max(dp[i + 1][j], now);
    }
  }

  long long ans = dp[N][K];
  cout << ans << endl;
}
Problem p02716 (C++)

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define rep(i, n) repl(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define dbg(x) cout << #x "=" << x << endl
#define mmax(x, y) (x > y ? x : y)
#define mmin(x, y) (x < y ? x : y)
#define maxch(x, y) x = mmax(x, y)
#define minch(x, y) x = mmin(x, y)
#define uni(x) x.erase(unique(all(x)), x.end())
#define exist(x, y) (find(all(x), y) != x.end())
#define bcnt __builtin_popcountll

#define INF 1e10
#define mod 1000000007

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

  ll n;
  cin >> n;
  vector<ll> a(n + 2, -INF), pre(n + 2, -1), nxt(n + 2, -1);
  repl(i, 1, n + 1) cin >> a[i];
  rep(i, n + 2) {
    pre[i] = i - 1;
    nxt[i] = i + 1;
  }

  set<P> st;
  rep(i, n + 2) { st.insert(P(a[i], i)); }

  ll sum = 0;
  rep(_, n / 2) {
    P p = *st.rbegin();
    sum += p.fi;
    ll idx = p.se;

    st.erase(st.find(P(p.fi, p.se)));
    st.erase(st.find(P(a[pre[idx]], pre[idx])));
    st.erase(st.find(P(a[nxt[idx]], nxt[idx])));

    ll val = a[pre[idx]] + a[nxt[idx]] - a[idx];
    a[idx] = -INF;
    a[nxt[idx]] = -INF;
    ll nnxt = nxt[nxt[idx]];
    nxt[pre[idx]] = nnxt;
    if (nnxt < n + 2)
      pre[nnxt] = pre[idx];
    a[pre[idx]] = val;

    st.insert(P(a[pre[idx]], pre[idx]));
  }
  cout << sum << endl;

  return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define rep(i, n) repl(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define dbg(x) cout << #x "=" << x << endl
#define mmax(x, y) (x > y ? x : y)
#define mmin(x, y) (x < y ? x : y)
#define maxch(x, y) x = mmax(x, y)
#define minch(x, y) x = mmin(x, y)
#define uni(x) x.erase(unique(all(x)), x.end())
#define exist(x, y) (find(all(x), y) != x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

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

  ll n;
  cin >> n;
  vector<ll> a(n + 2, -INF), pre(n + 2, -1), nxt(n + 2, -1);
  repl(i, 1, n + 1) cin >> a[i];
  rep(i, n + 2) {
    pre[i] = i - 1;
    nxt[i] = i + 1;
  }

  set<P> st;
  rep(i, n + 2) { st.insert(P(a[i], i)); }

  ll sum = 0;
  rep(_, n / 2) {
    P p = *st.rbegin();
    sum += p.fi;
    ll idx = p.se;

    st.erase(st.find(P(p.fi, p.se)));
    st.erase(st.find(P(a[pre[idx]], pre[idx])));
    st.erase(st.find(P(a[nxt[idx]], nxt[idx])));

    ll val = a[pre[idx]] + a[nxt[idx]] - a[idx];
    a[idx] = -INF;
    a[nxt[idx]] = -INF;
    ll nnxt = nxt[nxt[idx]];
    nxt[pre[idx]] = nnxt;
    if (nnxt < n + 2)
      pre[nnxt] = pre[idx];
    a[pre[idx]] = val;

    st.insert(P(a[pre[idx]], pre[idx]));
  }
  cout << sum << endl;

  return 0;
}
Problem p02716 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N = 1e5 + 5, inf = 1e17;
ll a[N], prfx[N], dp[N];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll n;
  cin >> n;
  for (ll i = 1; i <= n; i++)
    cin >> a[i];
  prfx[1] = a[1];
  for (ll i = 3; i <= n; i += 2)
    prfx[i] = prfx[i - 2] + a[i];
  for (ll i = 2; i <= n; i++) {
    if (i & 1)
      dp[i] = max(dp[i - 1], dp[i - 2] + a[i]);
    else
      dp[i] = max(prfx[i - 1], a[i] + dp[i - 2]);
  }
  cout << dp[n];
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N = 2e5 + 5;
ll a[N], prfx[N], dp[N];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll n;
  cin >> n;
  for (ll i = 1; i <= n; i++)
    cin >> a[i];
  prfx[1] = a[1];
  for (ll i = 3; i <= n; i += 2)
    prfx[i] = prfx[i - 2] + a[i];
  for (ll i = 2; i <= n; i++) {
    if (i & 1)
      dp[i] = max(dp[i - 1], dp[i - 2] + a[i]);
    else
      dp[i] = max(prfx[i - 1], a[i] + dp[i - 2]);
  }
  cout << dp[n];
}
Problem p02717 (C++)

Buggy submission (status: Runtime Error):

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

#define BeatMeScanf                                                            \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);
#define tc(x)                                                                  \
  int x;                                                                       \
  cin >> x;                                                                    \
  while (x--)
#define ll long long
#define vi vector<int>
#define pii pair<int, int>
#define mii map<int, int>
#define inf 1 << 28
#define mem(x, y) memset(x, y, sizeof(x))
#define ps(x, y) fixed << setprecision(y) << x
#define show(val) cout << #val << " -> " << val << endl
#define Case cout << "Case " << ++cs << ": "
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define mod 1000000007

int main() {
  BeatMeScanf;
#ifndef ONLINE_JUDGE
  freopen("G:/C++/in.txt", "r", stdin);
  freopen("G:/C++/out.txt", "w", stdout);
#endif
  int x, y, z;
  cin >> x >> y >> z;
  cout << z << " " << x << " " << y << '\n';
  return 0;
}


Fixed submission:

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

#define BeatMeScanf                                                            \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);
#define tc(x)                                                                  \
  int x;                                                                       \
  cin >> x;                                                                    \
  while (x--)
#define ll long long
#define vi vector<int>
#define pii pair<int, int>
#define mii map<int, int>
#define inf 1 << 28
#define mem(x, y) memset(x, y, sizeof(x))
#define ps(x, y) fixed << setprecision(y) << x
#define show(val) cout << #val << " -> " << val << endl
#define Case cout << "Case " << ++cs << ": "
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define mod 1000000007

int main() {
  BeatMeScanf;
  int x, y, z;
  cin >> x >> y >> z;
  cout << z << " " << x << " " << y << '\n';
  return 0;
}
Problem p02717 (C++)

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

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  int x, y, z;
  cin >> x >> y >> z;
  cout << z << " " << x << " " << y << endl;

  return 0;
}


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

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

  int x, y, z;
  cin >> x >> y >> z;
  cout << z << " " << x << " " << y << endl;

  return 0;
}
Problem p02717 (C++)

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

using namespace std;
using ll = long long int;
constexpr ll M = 1e9 + 7;
inline ll sum_1(const ll n) { return ((n * (n + 1)) / 2) % M; }
inline ll sum_2(const ll n) { return ((n * (n + 1) * (2 * n + 1)) / 6) % M; }
inline ll sum_3(const ll n) {
  return (((n * (n + 1)) / 2) % M * ((n * (n + 1)) / 2) % M) % M;
}
inline ll sum_1(const ll i, const ll j) {
  return (sum_1(j) - sum_1(i - 1) + M) % M;
}
inline ll sum_2(const ll i, const ll j) {
  return (sum_2(j) - sum_2(i - 1) + M) % M;
}
inline ll sum_3(const ll i, const ll j) {
  return (sum_3(j) - sum_3(i - 1) + M) % M;
}

void solve() {
  int x, y, z;
  cin >> x >> y >> z;
  swap(x, y);
  swap(x, z);
  cout << x << " " << y << " " << z << endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
#ifndef ONLINE_JUDGE
  freopen("in.in", "r", stdin);
  freopen("out.out", "w", stdout);
#endif

  solve();

  return 0;
}

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

using namespace std;
using ll = long long int;
constexpr ll M = 1e9 + 7;
inline ll sum_1(const ll n) { return ((n * (n + 1)) / 2) % M; }
inline ll sum_2(const ll n) { return ((n * (n + 1) * (2 * n + 1)) / 6) % M; }
inline ll sum_3(const ll n) {
  return (((n * (n + 1)) / 2) % M * ((n * (n + 1)) / 2) % M) % M;
}
inline ll sum_1(const ll i, const ll j) {
  return (sum_1(j) - sum_1(i - 1) + M) % M;
}
inline ll sum_2(const ll i, const ll j) {
  return (sum_2(j) - sum_2(i - 1) + M) % M;
}
inline ll sum_3(const ll i, const ll j) {
  return (sum_3(j) - sum_3(i - 1) + M) % M;
}

void solve() {
  int x, y, z;
  cin >> x >> y >> z;
  swap(x, y);
  swap(x, z);
  cout << x << " " << y << " " << z << endl;
}

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

  solve();

  return 0;
}
Problem p02717 (C++)

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;

#define MX 35
#define MOD 1'000'000'007
#define set(N, pos) (N = (1LL << (pos)))
#define clear(N, pos) (N = (~(1LL << (pos))))
#define is_set(N, pos) (N & (1LL << (pos)))
#define all(v) (v).begin(), (v).end()

ll bigMod(ll base, ll pw) {
  ll ret = 1, mul = base;
  while (pw) {
    if (pw & 1)
      ret = (ret * mul) % MOD;
    mul = (mul * mul) % MOD;
    pw >>= 1;
  }
  return ret;
}

vi prime;
vector<bool> mark(MX, 0);
void sieve() {
  int limit = sqrt(MX + 1);
  prime.push_back(2);
  for (int i = 3; i < MX; i += 2) {
    if (!mark[i]) {
      prime.push_back(i);
      if (i < limit) {
        for (int j = i * i; j < MX; j += 2 * i)
          mark[j] = 1;
      }
    }
  }
}

int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
#endif // ONLINE_JUDGE

  ios_base::sync_with_stdio(false);
  cin.tie(0);

  int a, b, c;
  cin >> a >> b >> c;
  cout << c << ' ' << a << ' ' << b << endl;

  return 0;
}


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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;

#define MX 35
#define MOD 1'000'000'007
#define set(N, pos) (N = (1LL << (pos)))
#define clear(N, pos) (N = (~(1LL << (pos))))
#define is_set(N, pos) (N & (1LL << (pos)))
#define all(v) (v).begin(), (v).end()

ll bigMod(ll base, ll pw) {
  ll ret = 1, mul = base;
  while (pw) {
    if (pw & 1)
      ret = (ret * mul) % MOD;
    mul = (mul * mul) % MOD;
    pw >>= 1;
  }
  return ret;
}

vi prime;
vector<bool> mark(MX, 0);
void sieve() {
  int limit = sqrt(MX + 1);
  prime.push_back(2);
  for (int i = 3; i < MX; i += 2) {
    if (!mark[i]) {
      prime.push_back(i);
      if (i < limit) {
        for (int j = i * i; j < MX; j += 2 * i)
          mark[j] = 1;
      }
    }
  }
}

int main() {
#ifndef ONLINE_JUDGE
  // freopen("input.txt", "r", stdin);
#endif // ONLINE_JUDGE

  ios_base::sync_with_stdio(false);
  cin.tie(0);

  int a, b, c;
  cin >> a >> b >> c;
  cout << c << ' ' << a << ' ' << b << endl;

  return 0;
}
Problem p02717 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define ll long long int
#define vi vector<int>
#define vl vector<long long>
#define fin(ar, k, n)                                                          \
  for (int i = k; i < n; i++)                                                  \
  cin >> ar[i]
#define fout(ar, k, n)                                                         \
  for (int i = k; i < n; i++)                                                  \
  cout << ar[i] << ' '
#define vs vector<string>
#define mx INT_MAX
#define mn INT_MIN
#define all(z) z.begin(), z.end()
#define mcc 1000000007
#define mcf 998244353
#define mi map<int, int>
#define mem(a, n) memset(a, n, sizeof(a))
using namespace std;

// ll maxl(ll a,ll b) {return (a>b)? a:b;}
// ll minl(ll a,ll b) {return (a<b)? a:b;}
// ll gcdl(ll a,ll b) {return b ? gcdl(b,a%b):a;}

void solve() {
  int a, b, c;
  cin >> a >> b >> c;
  cout << c << ' ' << a << ' ' << b;
}

#if 1
int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
#endif
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int t = 1;
  // cin>>t;
  while (t--)
    solve();
  return 0;
}
#endif

//------------------------Google-------------------
#if 0
int main()
{
#ifdef __WIN32
    freopen("input.txt","r",stdin);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ll t,ct=0;
    cin>>t;
    while(t--)
    {
        cout<<"Case #"<<++ct<<": ";
        solve();
    }
    return 0;
}
#endif


Fixed submission:
#include <bits/stdc++.h>
#define ll long long int
#define vi vector<int>
#define vl vector<long long>
#define fin(ar, k, n)                                                          \
  for (int i = k; i < n; i++)                                                  \
  cin >> ar[i]
#define fout(ar, k, n)                                                         \
  for (int i = k; i < n; i++)                                                  \
  cout << ar[i] << ' '
#define vs vector<string>
#define mx INT_MAX
#define mn INT_MIN
#define all(z) z.begin(), z.end()
#define mcc 1000000007
#define mcf 998244353
#define mi map<int, int>
#define mem(a, n) memset(a, n, sizeof(a))
using namespace std;

// ll maxl(ll a,ll b) {return (a>b)? a:b;}
// ll minl(ll a,ll b) {return (a<b)? a:b;}
// ll gcdl(ll a,ll b) {return b ? gcdl(b,a%b):a;}

void solve() {
  int a, b, c;
  cin >> a >> b >> c;
  cout << c << ' ' << a << ' ' << b;
}

#if 1
int main() {

  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int t = 1;
  // cin>>t;
  while (t--)
    solve();
  return 0;
}
#endif

//------------------------Google-------------------
#if 0
int main()
{
#ifdef __WIN32
    freopen("input.txt","r",stdin);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ll t,ct=0;
    cin>>t;
    while(t--)
    {
        cout<<"Case #"<<++ct<<": ";
        solve();
    }
    return 0;
}
#endif
Problem p02717 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
#define fastio                                                                 \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);

#define ull unsigned long long int
#define ll long long int
#define ld double
#define ui unsigned int
#define pb push_back
#define mp make_pair
#define ff first
#define ss second

#define fr(i, a, b) for (int i = (a), _b = (b); i <= _b; i++)
#define frr(i, a, b) for (int i = (a), _b = (b); i >= _b; i--)
#define rep(i, n) for (int i = 0, _n = (n); i < _n; i++)
#define repr(i, n) for (long long i = (n)-1; i >= 0; i--)

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

int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  fastio;

  ll t;
  t = 1;
  while (t--) {
    ll x, y, z;
    cin >> x >> y >> z;
    cout << z << " " << x << " " << y;
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
#define fastio                                                                 \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);

#define ull unsigned long long int
#define ll long long int
#define ld double
#define ui unsigned int
#define pb push_back
#define mp make_pair
#define ff first
#define ss second

#define fr(i, a, b) for (int i = (a), _b = (b); i <= _b; i++)
#define frr(i, a, b) for (int i = (a), _b = (b); i >= _b; i--)
#define rep(i, n) for (int i = 0, _n = (n); i < _n; i++)
#define repr(i, n) for (long long i = (n)-1; i >= 0; i--)

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

int main() {

  fastio;

  ll t;
  t = 1;
  while (t--) {
    ll x, y, z;
    cin >> x >> y >> z;
    cout << z << " " << x << " " << y;
  }
  return 0;
}
Problem p02717 (Python)

Buggy submission (status: Runtime Error):
A, B, C = [int(i) for i in input().split()]

A, B, C = B, A, C
A, B, C = C, B, A

print(f"{A} {B} {C}")


Fixed submission:
A, B, C = [int(i) for i in input().split()]

A, B, C = B, A, C
A, B, C = C, B, A

print("%s %s %s" % (A, B, C))
Problem p02717 (Python)

Buggy submission (status: Runtime Error):
#!/usr/bin/env python3

a = int(input())
a, b = map(int, input().split())
a = list(str(input()))


Fixed submission:
#!/usr/bin/env python3

a, b, c = map(int, input().split())
print("{} {} {}".format(c, a, b))
Problem p02717 (Python)

Buggy submission (status: Runtime Error):
x, y, z = map(int, input())
print(z, x, y)


Fixed submission:
x, y, z = map(int, input().split())
print(z, x, y)
Problem p02717 (Python)

Buggy submission (status: Runtime Error):
X, Y, Z = map(int, input())
print(Z, X, Y)


Fixed submission:
X, Y, Z = map(int, input().split())
print(Z, X, Y)
Problem p02717 (C++)

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

int main() {
#ifndef ONLINE_JUDGE
  freopen("inp.txt", "r", stdin);
  freopen("outp.txt", "w", stdout);
#endif
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

  ll a, b, c;

  cin >> a >> b >> c;

  cout << c << " " << a << " " << b;

  return 0;
}

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

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

  ll a, b, c;

  cin >> a >> b >> c;

  cout << c << " " << a << " " << b;

  return 0;
}
Problem p02717 (Python)

Buggy submission (status: Runtime Error):
x, y, z = map(int, input().split())
print(z + " " + x + " " + y)


Fixed submission:
x, y, z = map(str, input().split())
print(z + " " + x + " " + y)
Problem p02717 (Python)

Buggy submission (status: Runtime Error):
X, Y, Z = map(int, input().split())
print(f"{Z} {X} {Y}")


Fixed submission:
X, Y, Z = map(int, input().split())
print(Z, X, Y)
Problem p02717 (Python)

Buggy submission (status: Runtime Error):
XYZ = map(int, input().split())
print(XYZ[2], XYZ[1], XYZ[0])


Fixed submission:
XYZ = input().split()
print(XYZ[2], XYZ[0], XYZ[1])
Problem p02717 (Python)

Buggy submission (status: Runtime Error):
import sys


if __name__ == "__main__":
    print(f"{sys.argv[-1]} {sys.argv[1]} {sys.argv[2]}")


Fixed submission:
import sys


if __name__ == "__main__":
    a, b, c = map(int, input().split())
    print(c, a, b)
Problem p02717 (Python)

Buggy submission (status: Runtime Error):
a = int(input())
b = int(input())
c = int(input())
print(c, a, b)


Fixed submission:
a, b, c = map(int, input().split())
print(c, a, b)
Problem p02717 (Python)

Buggy submission (status: Runtime Error):
x, y, z = input().split()
print(f"{z} {x} {y}")


Fixed submission:
x, y, z = input().split()
print(z, x, y)
Problem p02717 (Python)

Buggy submission (status: Runtime Error):
x, y, z = map(int, input().split())
print(f"{z} {x} {y}")


Fixed submission:
x, y, z = map(int, input().split())
print(z, end=" ")
print(x, end=" ")
print(y)
Problem p02717 (C++)

Buggy submission (status: Runtime Error):
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[]) {
  int a = atoi(argv[1]);
  int b = atoi(argv[2]);
  int c = atoi(argv[3]);
  printf("%d\n ", c);
  printf("%d\n ", a);
  printf("%d\n ", b);
  return 0;
}


Fixed submission:
#include <stdio.h>
#include <stdlib.h>

int main() {
  int a, b, c;
  scanf("%d %d %d", &a, &b, &c);
  printf("%d %d %d\n", c, a, b);
  return 0;
}
Problem p02717 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(v) ((v).begin()), ((v).end())
#define clr(v, val) memset(v, val, sizeof v)
#define watch(x) cout << (#x) << " is " << (x) << endl
#define endl "\n"
void Run() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
#ifndef ONLINE_JUDGE
  freopen("in.txt", "r", stdin); // freopen("out.txt", "w", stdout);
#endif
}
const int N = 1e5 + 20;
/***You***Can***Do***It***/
int main() {
  Run();
  int x, y, z;
  cin >> x >> y >> z;
  cout << z << " " << x << " " << y << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(v) ((v).begin()), ((v).end())
#define clr(v, val) memset(v, val, sizeof v)
#define watch(x) cout << (#x) << " is " << (x) << endl
#define endl "\n"
void Run() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
#ifndef ONLINE_JUDGE
  freopen("in.txt", "r", stdin); // freopen("out.txt", "w", stdout);
#endif
}
const int N = 1e5 + 20;
/***You***Can***Do***It***/
int main() {
  // Run();
  int x, y, z;
  cin >> x >> y >> z;
  cout << z << " " << x << " " << y << endl;
}
Problem p02717 (Python)

Buggy submission (status: Runtime Error):
import sys

a, b, c = map(int, sys.argv[1:])
b2 = a
c2 = b
a2 = c
print(a2, b2, c2)


Fixed submission:
in_ = input()
a, b, c = map(int, in_.split())
b2 = a
c2 = b
a2 = c
print(a2, b2, c2)
Problem p02717 (C++)

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

#define ll long long
#define ld long double
#define F first
#define S second

// #define ONLINE_JUDGE 1

using namespace std;

const int mod = 1e9 + 7;

void solve() {
  int x, y, z;
  cin >> x >> y >> z;
  cout << z << " " << x << " " << y << "\n";
}

int main() {
#ifndef ONLINE_JUDGE
  freopen("in.txt", "r", stdin);
  freopen("out.txt", "w", stdout);
#endif
  ios_base::sync_with_stdio(false);
  cin.tie(NULL), cout.tie(NULL);
  int t = 1;
  // cin >> t;
  while (t--)
    solve();
  return 0;
}

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

#define ll long long
#define ld long double
#define F first
#define S second

#define ONLINE_JUDGE 1

using namespace std;

const int mod = 1e9 + 7;

void solve() {
  int x, y, z;
  cin >> x >> y >> z;
  cout << z << " " << x << " " << y << "\n";
}

int main() {
#ifndef ONLINE_JUDGE
  freopen("in.txt", "r", stdin);
  freopen("out.txt", "w", stdout);
#endif
  ios_base::sync_with_stdio(false);
  cin.tie(NULL), cout.tie(NULL);
  int t = 1;
  // cin >> t;
  while (t--)
    solve();
  return 0;
}