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

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxx = 1e5 + 7;
const int Inf = 1 << 30;
const ll INF = 1ll << 60;
ll s;
int a, b, c, d;

int main() {
  scanf("%lld", &s);
  // 定一顶点在(0, 0), 构造向量(a, b)和(c, d)
  // 叉积求面积: s = ad - bc
  a = d = (int)sqrt(s);
  while (s > a * d * 1ll) {
    if (a < d)
      a++;
    else
      d++;
  }
  ll chk = 1ll * a * d - s;
  for (int i = 1; i <= sqrt(chk); i++) {
    if (!(chk % i)) {
      if (i <= 1e9 && chk / i <= 1e9) {
        b = i;
        c = chk / i;
        break;
      }
    }
  }
  printf("0 0 %d %d %d %d\n", a, b, c, d);
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxx = 1e5 + 7;
const int Inf = 1 << 30;
const ll INF = 1ll << 60;
ll s;
int a, b, c, d;

int main() {
  scanf("%lld", &s);
  // 定一顶点在(0, 0), 构造向量(a, b)和(c, d)
  // 叉积求面积: s = ad - bc
  a = d = (int)sqrt(s);
  while (s > 1ll * a * d) {
    if (a < d)
      a++;
    else
      d++;
  }
  ll chk = 1ll * a * d - s;
  for (int i = 1; i <= sqrt(chk); i++) {
    if (!(chk % i)) {
      if (i <= 1e9 && chk / i <= 1e9) {
        b = i;
        c = chk / i;
        break;
      }
    }
  }
  printf("0 0 %d %d %d %d\n", a, b, c, d);
  return 0;
}
Problem p02963 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define pf printf
#define sc scanf
#define pb push_back
#define eb emplace_back
#define present(c, x) ((c).find(x) != (c).end())
#define mp make_pair
#define xx first
#define yy second
#define endl '\n'
#define SZ(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
typedef long long ll;
typedef long double LD;
typedef unsigned long long ull;
typedef pair<int, int> pii;
const LD EPS = 1e-9;
const LD PI = acos(-1.0);
const int MX = 6e5 + 5;
ll mod = 1e9 + 7;

int main() {
  ll s;
  cin >> s;
  if (s <= 1000000000LL) {
    cout << "0 0 " << s << " 0 0 1\n";

  } else {

    ll x3 = ceil(sqrt(s));
    ll y2 = x3 ? (s / x3 + (s % x3 != 0)) : 0;
    ll y3 = x3 * y2 - s, x2;
    if (y3 == 0) {
      x2 = y3 = 0;
    } else {
      x2 = 1;
    }

    cout << "0 0 " << x2 << " " << y2 << " " << x3 << " " << y3 / x2 << endl;
  }
  return 0;
}

/**
                                                Md. Tariqul Islam
                                                        IIT,JU
                                                  fb/tariqiitju
                                          tarik.amtoly@gmail.com
*/

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define pf printf
#define sc scanf
#define pb push_back
#define eb emplace_back
#define present(c, x) ((c).find(x) != (c).end())
#define mp make_pair
#define xx first
#define yy second
#define endl '\n'
#define SZ(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
typedef long long ll;
typedef long double LD;
typedef unsigned long long ull;
typedef pair<int, int> pii;
const LD EPS = 1e-9;
const LD PI = acos(-1.0);
const int MX = 6e5 + 5;
ll mod = 1e9 + 7;

int main() {
  ll s;
  cin >> s;
  if (s <= 1000000000LL) {
    cout << "0 0 " << s << " 0 0 1\n";

  } else {

    ll x3 = ceil(sqrt(s));
    ll y2 = x3 ? (s / x3 + (s % x3 != 0)) : 0;
    ll y3 = x3 * y2 - s, x2;
    if (y3 == 0) {
      x2 = y3 = 0;
    } else {
      x2 = 1;
    }

    cout << "0 0 " << x2 << " " << y2 << " " << x3 << " " << y3 << endl;
  }
  return 0;
}

/**
                                                Md. Tariqul Islam
                                                        IIT,JU
                                                  fb/tariqiitju
                                          tarik.amtoly@gmail.com
*/
Problem p02963 (C++)

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

const int64_t lot = 1000000000;

signed main() {
  int64_t s;
  cin >> s;
  for (int64_t a = 1; a * a <= s; ++a) {
    if (s % a == 0) {
      int64_t b = s / a;
      if (a <= lot && b <= lot) {
        cout << 0 << ' ' << 0 << ' ' << a << ' ' << 0 << ' ' << 0 << ' ' << b
             << '\n';
        return 0;
      }
    }
  }
}


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

const int64_t lot = 1000000000;

signed main() {
  int64_t s;
  cin >> s;
  int64_t x = (lot - (s % lot)) % lot, y = (s + x) / lot;
  cout << 0 << ' ' << 0 << ' ' << lot << ' ' << 1 << ' ' << x << ' ' << y
       << '\n';
}
Problem p02963 (C++)

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

ll s;

int main() {
  cin >> s;
  ll memo;
  for (ll i = 1; i * i <= s; i++) {
    if (s % i == 0 && s / i <= 1e9) {
      memo = i;
      break;
    }
  }
  cout << 0 << ' ' << 0 << ' ' << 0 << ' ' << memo << ' ' << s / memo << ' '
       << 0 << endl;
  return 0;
}


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

ll s;

int main() {
  cin >> s;
  ll memo = 1e9;
  ll y = (s + memo - 1) / memo;
  ll x = y * memo - s;
  cout << 0 << ' ' << 0 << ' ' << memo << ' ' << 1 << ' ' << x << ' ' << y
       << endl;
  return 0;
}
Problem p02963 (C++)

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

using namespace std;

int main() {
  long long s;
  cin >> s;
  long long a, b;
  for (a = s - 1;; a--) {
    if (s % a == 0)
      break;
  }
  b = s / a;
  cout << 0 << " " << 0 << " " << 0 << " " << a << " " << b << " " << 0 << endl;
  getchar();
  getchar();
  return 0;
}

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

using namespace std;

int main() {
  long long s;
  cin >> s;
  long long x1, y1, x2, y2, x3, y3;
  x1 = 0, y1 = 0;
  x2 = 1000000000, y2 = 1;
  x3 = (1000000000 - s % 1000000000) % 1000000000, y3 = (s + x3) / 1000000000;
  cout << x1 << " " << y1 << " " << x2 << " " << y2 << " " << x3 << " " << y3;
  getchar();
  getchar();
  return 0;
}
Problem p02963 (Python)

Buggy submission (status: Time Limit Exceeded):
import sys
import math  # noqa
import bisect  # noqa
import queue  # noqa


def input():
    return sys.stdin.readline().rstrip()


if __name__ == "__main__":
    S = int(input())

    if len(str(S)) == 19:
        print(0, 0, 1000000000, 0, 0, 1000000000)
        exit(0)

    search = min(1000000000, math.ceil(math.sqrt(S)))
    for i in range(search, 0, -1):
        if S % i == 0:
            print(0, 0, i, 0, 0, S // i)
            exit(0)


Fixed submission:
import sys
import math  # noqa
import bisect  # noqa
import queue  # noqa


def input():
    return sys.stdin.readline().rstrip()


if __name__ == "__main__":
    S = int(input())

    x1, y1 = 0, 0
    x2, y2 = 1000000000, 1
    x3 = (x2 - S % x2) % x2
    y3 = (S + x3) // x2
    print("{} {} {} {} {} {}".format(x1, y1, x2, y2, x3, y3))
Problem p02963 (Python)

Buggy submission (status: Time Limit Exceeded):
def solve(s):
    k = 10**9
    if s <= k:
        return 0, 0, 1, 0, 0, s
    X = k
    while True:
        Y = (s - 1) // X + 1
        while Y <= k:
            xy = X * Y - s
            lim = min(Y, int(xy**0.5))
            for y in range(1, lim + 1):
                x, m = divmod(xy, y)
                if x <= X and m == 0:
                    return 0, 0, X, y, x, Y
            Y += 1
        X -= 1


s = int(input())
print(*solve(s))


Fixed submission:
def solve(s):
    k = 10**9
    if s <= k:
        return 0, 0, 1, 0, 0, s
    X = k
    while True:
        Y = (s - 1) // X + 1
        while Y <= k:
            xy = X * Y - s
            if xy == 0:
                return 0, 0, X, 0, 0, Y
            lim = min(Y, int(xy**0.5))
            for y in range(1, lim + 1):
                x, m = divmod(xy, y)
                if x <= X and m == 0:
                    return 0, 0, X, y, x, Y
            Y += 1
        X -= 1


s = int(input())
print(*solve(s))
Problem p02963 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h> // Tomasz Nowak
using namespace std;     // XIII LO Szczecin
using LL = long long;    // Poland
#define FOR(i, l, r) for (int i = (l); i <= (r); ++i)
#define REP(i, n) FOR(i, 0, (n)-1)
template <class T> int size(T &&x) { return int(x.size()); }
template <class A, class B>
ostream &operator<<(ostream &out, const pair<A, B> &p) {
  return out << '(' << p.first << ", " << p.second << ')';
}
template <class T>
auto operator<<(ostream &out, T &&x) -> decltype(x.begin(), out) {
  out << '{';
  for (auto it = x.begin(); it != x.end(); ++it)
    out << *it << (it == prev(x.end()) ? "" : ", ");
  return out << '}';
}
void dump() {}
template <class T, class... Args> void dump(T &&x, Args... args) {
  cerr << x << ";  ";
  dump(args...);
}
#ifdef DEBUG
struct Nl {
  ~Nl() { cerr << '\n'; }
};
#define debug(x...)                                                            \
  cerr << (strcmp(#x, "") ? #x ":  " : ""), dump(x), Nl(), cerr << ""
#else
#define debug(...) 0 && cerr
#endif
mt19937_64 rng(0);
int rd(int l, int r) { return uniform_int_distribution<int>(l, r)(rng); }
// end of templates

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

  LL s;
  cin >> s;
  LL added = 0;
  while (LL(sqrt(s + added)) * LL(sqrt(s + added)) != s + added)
    ++added;
  cout << "0 0 " << LL(sqrt(s + added)) << ' ' << (added ? 1 : 0) << ' '
       << added << ' ' << LL(sqrt(s + added));
}


Fixed submission:
#include <bits/stdc++.h> // Tomasz Nowak
using namespace std;     // XIII LO Szczecin
using LL = long long;    // Poland
#define FOR(i, l, r) for (int i = (l); i <= (r); ++i)
#define REP(i, n) FOR(i, 0, (n)-1)
template <class T> int size(T &&x) { return int(x.size()); }
template <class A, class B>
ostream &operator<<(ostream &out, const pair<A, B> &p) {
  return out << '(' << p.first << ", " << p.second << ')';
}
template <class T>
auto operator<<(ostream &out, T &&x) -> decltype(x.begin(), out) {
  out << '{';
  for (auto it = x.begin(); it != x.end(); ++it)
    out << *it << (it == prev(x.end()) ? "" : ", ");
  return out << '}';
}
void dump() {}
template <class T, class... Args> void dump(T &&x, Args... args) {
  cerr << x << ";  ";
  dump(args...);
}
#ifdef DEBUG
struct Nl {
  ~Nl() { cerr << '\n'; }
};
#define debug(x...)                                                            \
  cerr << (strcmp(#x, "") ? #x ":  " : ""), dump(x), Nl(), cerr << ""
#else
#define debug(...) 0 && cerr
#endif
mt19937_64 rng(0);
int rd(int l, int r) { return uniform_int_distribution<int>(l, r)(rng); }
// end of templates

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

  LL s;
  cin >> s;
  LL sq = LL(sqrt(s));
  if (sq * sq != s)
    ++sq;
  LL added = sq * sq - s;
  while (LL(sqrt(s + added)) * LL(sqrt(s + added)) != s + added)
    ++added;
  cout << "0 0 " << LL(sqrt(s + added)) << ' ' << (added ? 1 : 0) << ' '
       << added << ' ' << LL(sqrt(s + added));
}
Problem p02963 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define MP make_pair
#define PB push_back
#define inf 1000000007
#define mod 1000000007
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

int main() {
  ll s;
  cin >> s;
  ll a = 1;
  for (int i = 0; i < 10; i++) {
    if (a >= s) {
      break;
    } else {
      a *= 10;
    }
  }
  a /= 10;
  ll b = (s + a - 1) / a;
  ll p = a * b - s;
  ll q = 1;
  cout << 0 << " " << 0 << " " << a << " " << p << " " << q << " " << b << endl;
  // cerr << a*b-p*q << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define MP make_pair
#define PB push_back
#define inf 1000000007
#define mod 1000000007
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

int main() {
  ll s;
  cin >> s;
  ll a = 1;
  if (s == 1) {
    cout << 0 << " " << 0 << " " << 1 << " " << 0 << " " << 0 << " " << 1
         << endl;
    return 0;
  }
  for (int i = 0; i < 10; i++) {
    if (a >= s) {
      break;
    } else {
      a *= 10;
    }
  }
  a /= 10;
  ll b = (s + a - 1) / a;
  ll p = a * b - s;
  ll q = 1;
  cout << 0 << " " << 0 << " " << a << " " << p << " " << q << " " << b << endl;
  // cerr << a*b-p*q << endl;
  return 0;
}
Problem p02963 (C++)

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

int main() {
  long long S;
  cin >> S; // s=ad-bc(0,0,a,b,c,d)
  long long a = 1000000000;
  long long b = 1;
  long long c = (S + 999999999) / 1000000000;
  long long d = (S + b * c) / a;
  cout << "0 0 " + a + ' ' + b + ' ' + c + ' ' + d << endl;
}


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

int main() {
  long long S;
  cin >> S; // s=ad-bc(0,0,a,b,c,d)
  int a = 1000000000;
  int b = 1;
  int d = (S + 999999999) / 1000000000;
  int c = (-S + a * d) / b;
  char e = ' ';
  cout << "0 0 " << a << e << b << e << c << e << d << endl;
}
Problem p02963 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <bits/stdc++.h>
#include <cmath>   // abs() for float, and fabs()
#include <cstdlib> // abs() for integer 絶対値求めやつ
#include <iomanip> //浮動小数点数を出力する制度の指定
#include <string>
#include <vector>
// 使い方　数値をnumとして　cout<<setprecision(n)<<num ;nは桁数
#define rep(i, n) for (int i = 0; i < (n); i++)
#define SORT(a) sort((a).begin(), (a).end())
#define REV(a) reverse((a).begin(), (a).end())
using namespace std;
using ll = long long;
#define INF 2000000000
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
#define che(a, string) cout << "//" << string << "==" << (a) << "//" << endl;
bool IsInt(double a) {
  int b = a / 1;
  if (a == b) {
    return true;
  } else {
    return false;
  }
}
/*覚えてないことメaモ
数値型から文字列に変換　to_string(number);これは簡単
文字列から数値型に変換　stoi(number)
文字列からllに変換　stoll(number)*/

// ここから書き始める

int main() {
  ll S;
  cin >> S;
  // まず、面積がSとなる四角形の辺の長さを考えればよい
  ll Y = 1;
  ll i = 2;
  ll meow = pow(10, 9);
  while (S > meow) {
    while (1) {
      if (S % i == 0) {
        break;
      } else {
        if (i != 2) {
          i += 2;
        }
      }
    }
    S /= i;
    Y *= i;
  }
  cout << 0 << " " << 0 << " " << 0 << " " << Y << " " << S << " " << 0 << endl;
}


Fixed submission:
#include <algorithm>
#include <bits/stdc++.h>
#include <cmath>   // abs() for float, and fabs()
#include <cstdlib> // abs() for integer 絶対値求めやつ
#include <iomanip> //浮動小数点数を出力する制度の指定
#include <string>
#include <vector>
// 使い方　数値をnumとして　cout<<setprecision(n)<<num ;nは桁数
#define rep(i, n) for (int i = 0; i < (n); i++)
#define SORT(a) sort((a).begin(), (a).end())
#define REV(a) reverse((a).begin(), (a).end())
using namespace std;
using ll = long long;
#define INF 2000000000
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
#define che(a, string) cout << "//" << string << "==" << (a) << "//" << endl;
bool IsInt(double a) {
  int b = a / 1;
  if (a == b) {
    return true;
  } else {
    return false;
  }
}
/*覚えてないことメaモ
数値型から文字列に変換　to_string(number);これは簡単
文字列から数値型に変換　stoi(number)
文字列からllに変換　stoll(number)*/

// ここから書き始める

int main() {
  ll S;
  cin >> S;
  ll x = ceil(sqrt(S));
  ll a = x;
  ll d = x;
  ll b = 1;
  ll c = x * x - S;
  cout << 0 << " " << 0 << " " << a << " " << b << " " << c << " " << d << endl;
}
Problem p02963 (C++)

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

int k, x1, x2, x3, y1, y2, y3;
long long s;

int main() {
  scanf("%lld", &s);
  for (x2 = 1, y3 = 1, k = 1; 1LL * x2 * y3 < s; k = k ^ 1)
    if (k)
      x2++;
    else
      y3++;
  y2 = 1, x3 = 1LL * x2 * y3 - s;
  printf("%d %d %d %d %d %d\n", x1, y1, x2, y2, x3, y3);
  return 0;
}

Fixed submission:
#include <cstdio>

int k, x1, x2, x3, y1, y2, y3;
long long s;

int main() {
  scanf("%lld", &s);
  for (x2 = 1, y3 = 1; 1LL * (x2 + 10000) * (y3 + 10000) < s;
       x2 = x2 + 10000, y3 = y3 + 10000)
    ;
  for (k = 1; 1LL * x2 * y3 < s; k = k ^ 1)
    if (k)
      x2++;
    else
      y3++;
  y2 = 1, x3 = 1LL * x2 * y3 - s;
  printf("%d %d %d %d %d %d\n", x1, y1, x2, y2, x3, y3);
  return 0;
}
Problem p02963 (C++)

Buggy submission (status: Runtime Error):
#include <stdio.h>
int main() {
  long s;
  scanf("%d", s);
  printf("0 ");
  printf("0 ");
  printf("2 ");
  printf("0 ");
  printf("0 ");
  printf("%ld", s);
}

Fixed submission:
#include <stdio.h>
int main() {
  long long s, t, u;
  scanf("%lld", &s);
  t = s / 1000000000 + 1;
  u = 1000000000 - s % 1000000000;
  if (s % 1000000000 == 0) {
    t--;
    u = 0;
  }
  printf("0 0 %lld 1000000000 %lld 1", u, t);
}
Problem p02963 (C++)

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

#define int long long
#define pb push_back
#define pii pair<int, int>
#define vi vector<int>
#define vii vector<pii>
#define mi map<int, int>
#define mii map<pii, int>
#define all(a) (a).begin(), (a).end()
#define x first
#define y second
#define sz(x) (int)x.size()
#define endl '\n'
#define hell 1000000007
#define rep(i, a, b) for (int i = a; i < b; i++)
using namespace std;

void solve() {
  int s;
  cin >> s;
  int a = sqrt(s);
  int d = a;
  while ((a + 1) * d <= s)
    a++;
  int b = (s - a * d);
  int c = -1;
  assert(a + 1 <= hell - 7);
  assert(c + 1 <= hell - 7);
  assert(b <= hell - 7);
  assert(d <= hell - 7);
  assert(abs(d * a - b * c) == s);
  cout << 1 << " " << 0 << " " << a + 1 << " " << b << " " << c + 1 << " " << d
       << endl;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  // cin>>t;
  while (t--) {
    solve();
  }
  return 0;
}

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

#define int long long
#define pb push_back
#define pii pair<int, int>
#define vi vector<int>
#define vii vector<pii>
#define mi map<int, int>
#define mii map<pii, int>
#define all(a) (a).begin(), (a).end()
#define x first
#define y second
#define sz(x) (int)x.size()
#define endl '\n'
#define hell 1000000007
#define rep(i, a, b) for (int i = a; i < b; i++)
using namespace std;

void solve() {
  int s;
  cin >> s;
  int a = sqrt(s);
  int d = a;
  while (a + 1 > hell - 7)
    a--;
  while (d + 1 <= hell - 7 and (d + 1) * a <= s)
    d++;
  while (d > hell - 7)
    d--;
  int b = (s - a * d);
  int c = -1;
  assert(a + 1 <= hell - 7);
  assert(c + 1 <= hell - 7);
  assert(b <= hell - 7);
  assert(d <= hell - 7);
  assert(abs(d * a - b * c) == s);
  cout << 1 << " " << 0 << " " << a + 1 << " " << b << " " << c + 1 << " " << d
       << endl;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  // cin>>t;
  while (t--) {
    solve();
  }
  return 0;
}
Problem p02963 (C++)

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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, n) for (int i = 1; i <= (n); i++)
#define mp make_pair
#define pb push_back
#define fst first
#define snd second
typedef long long ll;
typedef pair<int, int> pii;

int main() {
  ll s, x, z, r;
  cin >> s;
  for (ll y = ll(sqrt(s)); y >= 1; y--) {
    if (s / y >= s % y) {
      x = 1;
      z = s % y;
      r = s / y - z;
      if (x > ll(1e9) || z + r > ll(1e9) || x + y > ll(1e9) || r > ll(1e9))
        continue;
      cout << 0 << " " << 0 << " " << x << " " << z + r << " " << x + y << " "
           << r << endl;
      return 0;
    }
  }
  return 0;
}

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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, n) for (int i = 1; i <= (n); i++)
#define mp make_pair
#define pb push_back
#define fst first
#define snd second
typedef long long ll;
typedef pair<int, int> pii;

int main() {
  ll s, x, z, r;
  cin >> s;
  if (s == ll(1e18)) {
    cout << 0 << " " << 0 << " " << ll(1e9) << " " << 0 << " " << 0 << " "
         << ll(1e9) << endl;
    return 0;
  }
  if (s == ll(1e18) - 1) {
    ll y = ll(1e9) - 1, z = ll(1e9) - 1, x = 1, r = ll(1e9) - z;
    cout << 0 << " " << 0 << " " << x << " " << z + r << " " << x + y << " "
         << r << endl;
    return 0;
  }
  for (ll y = ll(sqrt(s)); y >= 1; y--) {
    if (s / y >= s % y) {
      x = 1;
      z = s % y;
      r = s / y - z;
      if (x > ll(1e9) || z + r > ll(1e9) || x + y > ll(1e9) || r > ll(1e9))
        continue;
      cout << 0 << " " << 0 << " " << x << " " << z + r << " " << x + y << " "
           << r << endl;
      return 0;
    }
  }
  return 0;
}
Problem p02963 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define N 100000
typedef long long ll;
int main() {
  int n;
  cin >> n;
  vector<int> f(3, 0);
  cin >> f.at(0) >> f.at(1) >> f.at(2);
  vector<int> ln(n, 0);
  rep(i, n) { cin >> ln.at(i); }
  // sort(ln.begin(),ln.end());
  vector<int> s(n, 0);

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define N 100000
typedef long long ll;
int main() {
  ll s;
  cin >> s;
  ll x1, y1, x2, y2;
  x1 = 1e9;
  x2 = 1;
  y2 = s / x1;
  y1 = (ll)(x1 * y2 - s);
  if (y1 < 0) {
    y2++;
    y1 = (ll)(x1 * y2 - s);
  }
  printf("0 0 %d %d %d %d", x1, y1, x2, y2);
  return 0;
}
Problem p02963 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;

int main() {
  ll S;
  cin >> S;
  ll x1, y1 = 10e9, x2 = 1, y2;
  x1 = (y1 - S % y1) % y1;
  y2 = (S + x1) / x1;
  cout << 0 << " " << 0 << " " << y1 << " " << x2 << " " << x1 << " " << y2
       << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;

int main() {
  ll S;
  cin >> S;
  ll x1, y1, x2 = 1000000000, y2 = 1;
  x1 = (x2 - S % x2) % x2;
  y1 = (S + x1) / x2;
  printf("0 0 1000000000 1 %lld %lld\n", x1, y1);
  return 0;
}
Problem p02964 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define pb push_back
#define all(x) x.begin(), x.end()
using namespace std;
using ll = long long;
using vi = vector<ll>;
using vvi = vector<vi>;
using pi = pair<ll, ll>;
using vpi = vector<pi>;
const ll mod = 7 * 17 * (1 << 23) + 1;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int n, jumpid[200200], st[200200];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  set<int> pos[100];
  vi a;
  ll k = 0;
  cin >> n >> k;
  a.resize(n);
  for (int i = 0; i < n; i++)
    cin >> a[i], pos[a[i]].insert(i);
  int i = 0, j = 1;
  jumpid[0] = 1;
  st[1] = 0;
  int fcyc = -1, cl = 0, nw;
  while (true) {
    nw = 0;
    auto it = pos[a[i]].upper_bound(i);
    if (it != pos[a[i]].end())
      i = (1 + *it);
    else {
      i = (1 + *pos[a[i]].begin());
      st[++j] = i;
      nw = 1;
    }
    if (i == n)
      i = 0, st[++j] = 0, nw = 1;
    if (jumpid[i]) {
      fcyc = jumpid[i];
      cl = j - jumpid[i];
      break;
    }
    if (nw)
      jumpid[i] = j;
  }
  if (k < fcyc) {
    k = st[k];
  } else {
    k = st[fcyc + (k - fcyc) % cl];
  }
  set<int> z;
  vi ans;
  for (int i = k; i < n; i++) {
    if (z.count(a[i])) {
      while (z.count(a[i])) {
        z.erase(ans.back());
        ans.pop_back();
      }
    } else
      ans.pb(a[i]), z.insert(a[i]);
  }
  for (auto i : ans)
    cout << i << " ";
  cout << "\n";
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define pb push_back
#define all(x) x.begin(), x.end()
using namespace std;
using ll = long long;
using vi = vector<ll>;
using vvi = vector<vi>;
using pi = pair<ll, ll>;
using vpi = vector<pi>;
const ll mod = 7 * 17 * (1 << 23) + 1;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int n, jumpid[200200], st[200200];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  set<int> pos[200200];
  vi a;
  ll k = 0;
  cin >> n >> k;
  a.resize(n);
  for (int i = 0; i < n; i++)
    cin >> a[i], pos[a[i]].insert(i);
  int i = 0, j = 1;
  jumpid[0] = 1;
  st[1] = 0;
  int fcyc = -1, cl = 0, nw;
  while (true) {
    nw = 0;
    auto it = pos[a[i]].upper_bound(i);
    if (it != pos[a[i]].end())
      i = (1 + *it);
    else {
      i = (1 + *pos[a[i]].begin());
      st[++j] = i;
      nw = 1;
    }
    if (i == n)
      i = 0, st[++j] = 0, nw = 1;
    if (jumpid[i]) {
      fcyc = jumpid[i];
      cl = j - jumpid[i];
      break;
    }
    if (nw)
      jumpid[i] = j;
  }
  if (k < fcyc) {
    k = st[k];
  } else {
    k = st[fcyc + (k - fcyc) % cl];
  }
  set<int> z;
  vi ans;
  for (int i = k; i < n; i++) {
    if (z.count(a[i])) {
      while (z.count(a[i])) {
        z.erase(ans.back());
        ans.pop_back();
      }
    } else
      ans.pb(a[i]), z.insert(a[i]);
  }
  for (auto i : ans)
    cout << i << " ";
  cout << "\n";
  return 0;
}
Problem p02964 (C++)

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

#define MIN_INT -2147483648
#define MAX_INT 2147483647
#define MIN_LONG -9223372036854775808L
#define MAX_LONG 9223372036854775807L

#define long long long int

using namespace std;

// @author: pashka

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

  int n;
  long k;
  cin >> n >> k;
  vector<int> a(n * 2);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    a[i + n] = a[i];
  }
  int MAX = 100000;
  vector<int> last(MAX + 1);
  vector<int> next(n * 2);
  for (int i = a.size() - 1; i >= 0; i--) {
    next[i] = last[a[i]];
    last[a[i]] = i;
  }
  int x = 0;
  vector<long> pk(n, -1);
  while (true) {
    if (k <= 2) {
      vector<int> s;
      vector<bool> z(MAX + 1);
      for (int i = x; i < k * n; i++) {
        if (z[a[i % n]]) {
          while (z[a[i % n]]) {
            int t = s.back();
            s.pop_back();
            z[t] = false;
          }
        } else {
          z[a[i % n]] = true;
          s.push_back(a[i % n]);
        }
      }
      for (int x : s) {
        cout << x << " ";
      }
      break;
    }
    x = next[x] + 1;
    while (x >= n) {
      k--;
      x -= n;
    }
    if (pk[x] != -1) {
      long d = pk[x] - k;
      k %= d;
    }
    //        cout << x << " " << k << "\n";
    pk[x] = k;
  }

  return 0;
}

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

#define MIN_INT -2147483648
#define MAX_INT 2147483647
#define MIN_LONG -9223372036854775808L
#define MAX_LONG 9223372036854775807L

#define long long long int

using namespace std;

// @author: pashka

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

  int n;
  long k;
  cin >> n >> k;
  vector<int> a(n * 2);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    a[i + n] = a[i];
  }
  int MAX = 1000000;
  vector<int> last(MAX + 1);
  vector<int> next(n * 2);
  for (int i = a.size() - 1; i >= 0; i--) {
    next[i] = last[a[i]];
    last[a[i]] = i;
  }
  int x = 0;
  vector<long> pk(n, -1);
  while (true) {
    if (k <= 2) {
      vector<int> s;
      vector<bool> z(MAX + 1);
      for (int i = x; i < k * n; i++) {
        if (z[a[i % n]]) {
          while (z[a[i % n]]) {
            int t = s.back();
            s.pop_back();
            z[t] = false;
          }
        } else {
          z[a[i % n]] = true;
          s.push_back(a[i % n]);
        }
      }
      for (int x : s) {
        cout << x << " ";
      }
      break;
    }
    x = next[x] + 1;
    while (x >= n) {
      k--;
      x -= n;
    }
    if (pk[x] != -1) {
      long d = pk[x] - k;
      k %= d;
    }
    //        cout << x << " " << k << "\n";
    pk[x] = k;
  }

  return 0;
}
Problem p02964 (C++)

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

int N, A[200009], nx[200009], c[200009], P[200009];
long long K, L, fi[200009], a, b;

void putans(int x) {
  vector<int> S;
  vector<bool> chk(200009, 0);
  for (int i = x; i < N; i++) {
    if (chk[A[i]]) {
      while (chk[A[i]]) {
        chk[S.back()] = 0;
        S.pop_back();
      }
    } else {
      chk[A[i]] = 1;
      S.push_back(A[i]);
    }
  }
  for (auto &it : S)
    printf("%d ", it);
  exit(0);
}

void go(int i, long long d) {
  if (fi[i] != -1) {
    a = fi[i];
    b = d - fi[i];
    return;
  }
  fi[i] = d;
  go(nx[i], d + c[i]);
}

void Do(int i, long long d) {
  if (d + c[i] <= L)
    Do(nx[i], d + c[i]);
  else
    putans(i);
}

int main() {
  scanf("%d%lld", &N, &K);
  L = K * N;
  for (int i = 0; i < N; i++) {
    scanf("%d", &A[i]);
    A[i + N] = A[i];
    fi[i] = -1;
  }
  for (int i = 2 * N - 1; i >= 0; i--) {
    if (i < N)
      nx[i] = (P[A[i]] + 1) % N, c[i] = P[A[i]] - i + 1;
    P[A[i]] = i;
  }
  go(0, 0);
  if (L <= a)
    Do(0, 0);
  else {
    L -= a;
    L %= b;
    if (L == 0)
      return 0;
    Do(0, 0);
  }
  return 0;
}

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

int N, A[400009], nx[200009], c[200009], P[200009];
long long K, L, fi[200009], a, b;

void putans(int x) {
  vector<int> S;
  vector<bool> chk(200009, 0);
  for (int i = x; i < N; i++) {
    if (chk[A[i]]) {
      while (chk[A[i]]) {
        chk[S.back()] = 0;
        S.pop_back();
      }
    } else {
      chk[A[i]] = 1;
      S.push_back(A[i]);
    }
  }
  for (auto &it : S)
    printf("%d ", it);
  exit(0);
}

void go(int i, long long d) {
  if (fi[i] != -1) {
    a = fi[i];
    b = d - fi[i];
    return;
  }
  fi[i] = d;
  go(nx[i], d + c[i]);
}

void Do(int i, long long d) {
  if (d + c[i] <= L)
    Do(nx[i], d + c[i]);
  else
    putans(i);
}

int main() {
  scanf("%d%lld", &N, &K);
  L = K * N;
  for (int i = 0; i < N; i++) {
    scanf("%d", &A[i]);
    A[i + N] = A[i];
    fi[i] = -1;
  }
  for (int i = 2 * N - 1; i >= 0; i--) {
    if (i < N)
      nx[i] = (P[A[i]] + 1) % N, c[i] = P[A[i]] - i + 1;
    P[A[i]] = i;
  }
  go(0, 0);
  if (L <= a)
    Do(0, 0);
  else {
    L -= a;
    L %= b;
    if (L == 0)
      return 0;
    Do(0, 0);
  }
  return 0;
}
Problem p02964 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 2e5 + 10;
int a[maxn * 2];
int pre[maxn];
int net[maxn];
vector<int> s;
int vis[maxn];
ll stute[maxn];
int main() {
  int n;
  ll k;
  cin >> n >> k;
  for (int i = 1; i <= n; i++)
    cin >> a[i], a[i + n] = a[i];
  for (int i = 2 * n; i >= 1; i--) {
    net[i] = pre[a[i]];
    pre[a[i]] = i;
  }
  int now = 1;
  memset(stute, -1, sizeof stute);
  while (1) {
    if (k <= 2) {

      for (int i = now; i <= k * n; i++) {
        if (i > n)
          i = i - n, k--;
        int temp = a[i];
        if (vis[a[i]] == 1) {

          while (s.back() != temp) {
            vis[s.back()] = 0;
            s.pop_back();
          }
          s.pop_back();
          vis[a[i]] = 0;
        } else {
          s.push_back(a[i]);
          vis[a[i]] = 1;
        }
      }
      break;
    }
    now = net[now] + 1;
    while (now > n) {
      now -= n;
      k--;
    }
    if (stute[now] != -1) {
      k = k % (stute[now] - k);
    }
    stute[now] = k;
  }
  for (int i = 0; i < s.size(); i++)
    cout << s[i] << ' ';
  cout << endl;

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 4e5 + 10;
int a[maxn];
int pre[maxn];
int net[maxn];
vector<int> s;
int vis[maxn];
ll stute[maxn];
int main() {
  int n;
  ll k;
  cin >> n >> k;
  for (int i = 1; i <= n; i++)
    cin >> a[i], a[i + n] = a[i];
  for (int i = 2 * n; i >= 1; i--) {
    net[i] = pre[a[i]];
    pre[a[i]] = i;
  }
  int now = 1;
  memset(stute, -1, sizeof stute);
  while (1) {
    if (k <= 2) {

      for (int i = now; i <= k * n; i++) {
        if (i > n)
          i = i - n, k--;
        int temp = a[i];
        if (vis[a[i]] == 1) {

          while (s.back() != temp) {
            vis[s.back()] = 0;
            s.pop_back();
          }
          s.pop_back();
          vis[a[i]] = 0;
        } else {
          s.push_back(a[i]);
          vis[a[i]] = 1;
        }
      }
      break;
    }
    now = net[now] + 1;
    while (now > n) {
      now -= n;
      k--;
    }
    if (stute[now] != -1) {
      k = k % (stute[now] - k);
    }
    stute[now] = k;
  }
  for (int i = 0; i < s.size(); i++)
    cout << s[i] << ' ';
  cout << endl;

  return 0;
}
Problem p02964 (C++)

Buggy submission (status: Runtime Error):
#include <cstdio>
#include <fstream>
#include <iostream>
using namespace std;
int a[500005], g[200005], ans[200005];
long long f[200005][70];
int main() {
  int n = 0;
  long long k = 0;
  scanf("%d%lld", &n, &k);
  for (int i = 1; i <= n; i++)
    scanf("%d", &a[i]), a[n + i] = a[i];
  for (int i = 1; i <= n + n; i++) {
    if (0 < g[a[i]] && g[a[i]] <= n)
      f[g[a[i]]][0] = i - g[a[i]] + 1;
    g[a[i]] = i;
  }
  for (int j = 1; j <= 65; j++)
    for (int i = 1; i <= n; i++) {
      int s = ((i + f[i][j - 1]) % n == 0) ? n : (i + f[i][j - 1]) % n;
      if (f[i][j - 1] == -1 || f[s][j - 1] == -1)
        f[i][j] = -1;
      else
        f[i][j] = f[i][j - 1] + f[s][j - 1];
      if (f[i][j] < 0)
        f[i][j] = -1;
    }
  long long c = 1;
  for (int i = 65; i >= 0; i--) {
    int s = (c % n == 0) ? n : c % n;
    long long h = c + f[s][i];
    if (h < 0 || h > n * k)
      h = -1;
    if (f[s][i] != -1 && h != -1)
      c += f[s][i];
  }
  int cnt = 0;
  c = n * k - c + 1;
  if (c > n)
    c = 0;
  for (int i = 1; i <= n; i++)
    g[i] = 0;
  for (int i = n - c + 1; i <= n; i++)
    if (g[a[i]])
      while (g[a[i]])
        g[ans[cnt--]] = 0;
    else
      g[a[i]] = 1, ans[++cnt] = a[i];
  for (int i = 1; i <= cnt; i++)
    printf("%d ", ans[i]);
  return 0;
}

Fixed submission:
#include <cstdio>
#include <fstream>
#include <iostream>
using namespace std;
int a[500005], g[200005], ans[200005];
long long f[200005][70];
int main() {
  int n = 0;
  long long k = 0;
  scanf("%d%lld", &n, &k);
  for (int i = 1; i <= n; i++)
    scanf("%d", &a[i]), a[n + i] = a[i];
  for (int i = 1; i <= n + n; i++) {
    if (0 < g[a[i]] && g[a[i]] <= n)
      f[g[a[i]]][0] = i - g[a[i]] + 1;
    g[a[i]] = i;
  }
  for (int j = 1; j <= 65; j++)
    for (int i = 1; i <= n; i++) {
      int s = ((i + f[i][j - 1]) % n == 0) ? n : (i + f[i][j - 1]) % n;
      if (f[i][j - 1] == -1 || f[s][j - 1] == -1)
        f[i][j] = -1;
      else
        f[i][j] = f[i][j - 1] + f[s][j - 1];
      if (f[i][j] < 0)
        f[i][j] = -1;
    }
  long long c = 1;
  for (int i = 65; i >= 0; i--) {
    int s = (c % n == 0) ? n : c % n;
    long long h = c + f[s][i];
    if (h < 0 || h > n * k)
      h = -1;
    if (f[s][i] != -1 && h != -1)
      c += f[s][i];
  }
  int cnt = 0;
  c = n * k - c + 1;
  if (c > n)
    c = 0;
  for (int i = 1; i <= n; i++)
    g[a[i]] = 0;
  for (int i = n - c + 1; i <= n; i++)
    if (g[a[i]])
      while (g[a[i]])
        g[ans[cnt--]] = 0;
    else
      g[a[i]] = 1, ans[++cnt] = a[i];
  for (int i = 1; i <= cnt; i++)
    printf("%d ", ans[i]);
  return 0;
}
Problem p02964 (C++)

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

using namespace std;

typedef long long ll;

int f[200005][60];
ll g[200005][60];

int num[400005], last[200005];

void pre(int n) {
  for (int i = 0; i < n; i++)
    num[n + i] = num[i];
  for (int i = 2 * n - 1; i >= 0; i--) {
    if (i < n) {
      f[i][0] = (last[num[i]] + 1) % n;
      g[i][0] = last[num[i]] - i + 1;
    }
    last[num[i]] = i;
  }
  for (int i = 1; i < 60; i++)
    for (int j = 0; j < n; j++) {
      f[j][i] = f[f[j][i - 1]][i - 1];
      g[j][i] = g[j][i - 1] + g[f[j][i - 1]][i - 1];
    }
}

int query(ll k) {
  int x = 0;
  for (int i = 59; i >= 0; i--)
    if (g[x][i] <= k) {
      k -= g[x][i];
      x = f[x][i];
    }
  return k;
}

int st[200005];
bool vis[200005];

int main() {
  int n;
  ll k;
  scanf("%d%lld", &n, &k);
  for (int i = 0; i < n; i++)
    scanf("%d", &num[i]);
  pre(n);
  int d = query(n * k), top = 0;
  for (int i = n - d; i < n; i++) {
    int x = num[i];
    if (vis[x]) {
      while (vis[x]) {
        vis[st[top]] = 0;
        top--;
      }
    } else {
      vis[x] = 1;
      st[++top] = x;
    }
  }
  for (int i = 1; i <= top; i++)
    printf("%d ", st[i]);
  printf("\n");
  return 0;
}

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

using namespace std;

typedef long long ll;

int f[200005][60];
ll g[200005][60];

int num[400005], last[200005];

void pre(int n) {
  for (int i = 0; i < n; i++)
    num[n + i] = num[i];
  for (int i = 2 * n - 1; i >= 0; i--) {
    if (i < n) {
      f[i][0] = (last[num[i]] + 1) % n;
      g[i][0] = last[num[i]] - i + 1;
    }
    last[num[i]] = i;
  }
  for (int i = 1; i < 60; i++)
    for (int j = 0; j < n; j++) {
      f[j][i] = f[f[j][i - 1]][i - 1];
      g[j][i] = min(g[j][i - 1] + g[f[j][i - 1]][i - 1], (ll)1e18);
    }
}

int query(ll k) {
  int x = 0;
  for (int i = 59; i >= 0; i--)
    if (g[x][i] <= k) {
      k -= g[x][i];
      x = f[x][i];
    }
  return k;
}

int st[200005];
bool vis[200005];

int main() {
  int n;
  ll k;
  scanf("%d%lld", &n, &k);
  for (int i = 0; i < n; i++)
    scanf("%d", &num[i]);
  pre(n);
  int d = query(n * k), top = 0;
  for (int i = n - d; i < n; i++) {
    int x = num[i];
    if (vis[x]) {
      while (vis[x]) {
        vis[st[top]] = 0;
        top--;
      }
    } else {
      vis[x] = 1;
      st[++top] = x;
    }
  }
  for (int i = 1; i <= top; i++)
    printf("%d ", st[i]);
  printf("\n");
  return 0;
}
Problem p02964 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll, ll> P;
#define Mod 1000000007
using VP = vector<P>;
using VVP = vector<VP>;
using VI = vector<ll>;
using VVI = vector<VI>;
using VVVI = vector<VVI>;
#define INF 1ll << 59

#pragma GCC optimize("Ofast")

int main() {
  ll i, j;
  ll n, k;
  cin >> n >> k;
  ll a[2 * n + 1];
  for (i = 1; i <= n; i++) {
    cin >> a[i];
    a[i + n] = a[i];
  }

  vector<ll> m(202020, 0);
  vector<ll> v(n + 1);

  for (i = 1; i <= 2 * n; i++) {
    if (m[a[i]] == 0)
      m[a[i]] = i;
    else if (m[a[i]] <= n) {
      v[m[a[i]]] = i - m[a[i]] + 1;
      m[a[i]] = i;
    }
  }

  ll po = 1 + v[1];

  while (po % n != 1) {
    if (po % n == 0)
      po = po + v[n];
    else
      po = po + v[po % n];
  }

  ll loop = (po - 1) / n;
  k %= loop;

  po = 1;
  ll prev;

  while (po <= k * n) {
    prev = po;
    if (po % n == 0)
      po = po + v[n];
    else
      po = po + v[po % n];
  }

  if (po == k * n + 1) {
    return 0;
  }

  if (prev % n == 0)
    prev = n;
  else
    prev = prev % n;

  vector<ll> ans;

  while (prev <= n) {
    if (prev + v[prev] <= n + 1) {
      prev = prev + v[prev];
    } else {
      ans.pb(a[prev]);
      prev++;
    }
  }

  if (ans.size() == 0)
    return 0;
  printf("%d", ans[0]);
  for (i = 1; i < ans.size(); i++)
    printf(" %d", ans[i]);
  cout << endl;

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll, ll> P;
#define Mod 1000000007
using VP = vector<P>;
using VVP = vector<VP>;
using VI = vector<ll>;
using VVI = vector<VI>;
using VVVI = vector<VVI>;
#define INF 1ll << 59

#pragma GCC optimize("Ofast")

int main() {
  ll i, j;
  ll n, k;
  cin >> n >> k;
  if (n == 1) {
    ll x;
    cin >> x;
    if (k % 2 == 0)
      return 0;
    else {
      cout << x << endl;
      return 0;
    }
  }
  ll a[2 * n + 1];
  for (i = 1; i <= n; i++) {
    cin >> a[i];
    a[i + n] = a[i];
  }

  vector<ll> m(202020, 0);
  vector<ll> v(n + 1);

  for (i = 1; i <= 2 * n; i++) {
    if (m[a[i]] == 0)
      m[a[i]] = i;
    else if (m[a[i]] <= n) {
      v[m[a[i]]] = i - m[a[i]] + 1;
      m[a[i]] = i;
    }
  }

  ll po = 1 + v[1];

  while (po % n != 1) {
    if (po % n == 0)
      po = po + v[n];
    else
      po = po + v[po % n];
  }

  ll loop = (po - 1) / n;
  k %= loop;

  po = 1;
  ll prev;

  while (po <= k * n) {
    prev = po;
    if (po % n == 0)
      po = po + v[n];
    else
      po = po + v[po % n];
  }

  if (po == k * n + 1) {
    return 0;
  }

  if (prev % n == 0)
    prev = n;
  else
    prev = prev % n;

  vector<ll> ans;

  while (prev <= n) {
    if (prev + v[prev] <= n + 1) {
      prev = prev + v[prev];
    } else {
      ans.pb(a[prev]);
      prev++;
    }
  }

  if (ans.size() == 0)
    return 0;
  printf("%d", ans[0]);
  for (i = 1; i < ans.size(); i++)
    printf(" %d", ans[i]);
  cout << endl;

  return 0;
}
Problem p02964 (C++)

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

// 1ブロックごとに必ず1回は全部消すことになる→全部消した後の始点の推移を書く？

vector<int> v[20001]; // v[n]には A_k = n となるkが入ってる,
                      // ソート済みなので二分探索で値がlog n

// v[i] の k = j の index を二分探索で取得
int biSearch(int i, int j) {
  int lb = 0, ub = v[i].size() - 1;
  while (v[i][ub] != j) {
    int mid = (lb + ub) / 2;
    if (v[i][mid] >= j) {
      ub = mid;
    } else {
      lb = mid;
    }
  }
  return ub;
}

int main() {
  int N;
  ll K;
  cin >> N >> K;
  vector<int> A(N);
  for (int i = 0; i < N; ++i) {
    cin >> A[i];
    v[A[i]].push_back(i);
  }

  vector<int> ans; // 最初に1周するまで各kの出力の始点を保存(線形で出力が求まる)
  int s = 0;       // 始点

  while (true) {
    int index = biSearch(A[s], s);
    if (index == v[A[s]].size() - 1) {
      ans.push_back(s);
      s = v[A[s]][0] + 1;

      // 単独で末尾の場合
      if (s == N) {
        ans.push_back(-1);
        break;
      }
    } else {
      if (v[A[s]][index + 1] + 1 == N) {
        ans.push_back(-1);
        break;
      } else {
        s = v[A[s]][index + 1] + 1;
      }
    }
  }
  K = (K - 1) % ans.size();
  int i = ans[K];
  if (i != -1) {
    while (i != N) {
      int index = biSearch(A[i], i);
      if (index != v[A[i]].size() - 1) {
        i = v[A[i]][index + 1] + 1;
      } else {
        cout << A[i] << " ";
        i++;
      }
    }
  }

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
using ll = long long;

// 1ブロックごとに必ず1回は全部消すことになる→全部消した後の始点の推移を書く？

vector<int> v[200001]; // v[n]には A_k = n となるkが入ってる,
                       // ソート済みなので二分探索で値がlog n

// v[i] の k = j の index を二分探索で取得
int biSearch(int i, int j) {
  int lb = 0, ub = v[i].size() - 1;
  while (v[i][ub] != j) {
    int mid = (lb + ub) / 2;
    if (v[i][mid] >= j) {
      ub = mid;
    } else {
      lb = mid;
    }
  }
  return ub;
}

int main() {
  int N;
  ll K;
  cin >> N >> K;
  vector<int> A(N);
  for (int i = 0; i < N; ++i) {
    cin >> A[i];
    v[A[i]].push_back(i);
  }

  vector<int> ans; // 最初に1周するまで各kの出力の始点を保存(線形で出力が求まる)
  int s = 0;       // 始点

  while (true) {
    int index = biSearch(A[s], s);
    if (index == v[A[s]].size() - 1) {
      ans.push_back(s);
      s = v[A[s]][0] + 1;

      // 単独で末尾の場合
      if (s == N) {
        ans.push_back(-1);
        break;
      }
    } else {
      if (v[A[s]][index + 1] + 1 == N) {
        ans.push_back(-1);
        break;
      } else {
        s = v[A[s]][index + 1] + 1;
      }
    }
  }
  K = (K - 1) % ans.size();
  int i = ans[K];
  if (i != -1) {
    while (i != N) {
      int index = biSearch(A[i], i);
      if (index != v[A[i]].size() - 1) {
        i = v[A[i]][index + 1] + 1;
      } else {
        cout << A[i] << " ";
        i++;
      }
    }
  }

  return 0;
}
Problem p02964 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define ff(i, x, y) for (int i = x; i <= y; i++)
#define fs(i, x, y) for (int i = x; i >= y; i--)
using namespace std;
typedef long long ll;
int n, vis[300010], a[200010], ans[400010];
ll dp[400010][60], sum, d;
int main() {
  scanf("%d%lld", &n, &sum);
  d = n * sum;
  memset(vis, -1, sizeof(vis));
  ff(i, 0, n - 1) {
    scanf("%d", &a[i]);
    a[i + n] = a[i];
  }
  ff(i, 0, 2 * n - 1) {
    if (vis[a[i]] == -1) {
      vis[a[i]] = i;
      dp[i][0] = n;
    } else {
      dp[vis[a[i]]][0] = i - vis[a[i]];
      vis[a[i]] = i;
      dp[i][0] = n;
    }
  }
  ff(i, 1, 59) {
    ff(j, 0, n - 1) {
      if (dp[j][i - 1] == -1 ||
          dp[(j + dp[j][i - 1] + 1) % (ll)n][i - 1] == -1) {
        dp[j][i] = -1;
      } else
        dp[j][i] = dp[j][i - 1] + dp[(j + dp[j][i - 1] + 1) % (ll)n][i - 1] + 1;
      if (dp[j][i] >= d)
        dp[j][i] = -1;
    }
  }
  int now = 0;
  ll up = d;
  fs(i, 59, 0) {
    if (dp[now][i] != -1) {
      if (dp[now][i] + 1 <= up) {
        up -= (dp[now][i] + 1);
        now = (dp[now][i] + now + 1) % n;
      }
    }
  }
  int s = 0;
  memset(vis, -1, sizeof(vis));
  ff(i, n - up, n - 1) {
    if (vis[a[i]] == -1) {
      vis[a[i]] = i;
      s++;
      ans[s] = a[i];

    } else {
      while (ans[s] != a[i]) {
        vis[ans[s]] = -1;
        s--;
      }
      vis[ans[s]] = -1;
      s--;
    }
  }
  ff(i, 1, s) { printf("%d ", ans[i]); }
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define ff(i, x, y) for (int i = x; i <= y; i++)
#define fs(i, x, y) for (int i = x; i >= y; i--)
using namespace std;
typedef long long ll;
int n, vis[300010], a[400010], ans[200010];
ll dp[400010][60], sum, d;
int main() {
  scanf("%d%lld", &n, &sum);
  d = n * sum;
  memset(vis, -1, sizeof(vis));
  ff(i, 0, n - 1) {
    scanf("%d", &a[i]);
    a[i + n] = a[i];
  }
  ff(i, 0, 2 * n - 1) {
    if (vis[a[i]] == -1) {
      vis[a[i]] = i;
      dp[i][0] = n;
    } else {
      dp[vis[a[i]]][0] = i - vis[a[i]];
      vis[a[i]] = i;
      dp[i][0] = n;
    }
  }
  ff(i, 1, 59) {
    ff(j, 0, n - 1) {
      if (dp[j][i - 1] == -1 ||
          dp[(j + dp[j][i - 1] + 1) % (ll)n][i - 1] == -1) {
        dp[j][i] = -1;
      } else
        dp[j][i] = dp[j][i - 1] + dp[(j + dp[j][i - 1] + 1) % (ll)n][i - 1] + 1;
      if (dp[j][i] >= d)
        dp[j][i] = -1;
    }
  }
  int now = 0;
  ll up = d;
  fs(i, 59, 0) {
    if (dp[now][i] != -1) {
      if (dp[now][i] + 1 <= up) {
        up -= (dp[now][i] + 1);
        now = (dp[now][i] + now + 1) % n;
      }
    }
  }
  int s = 0;
  memset(vis, -1, sizeof(vis));
  ff(i, n - up, n - 1) {
    if (vis[a[i]] == -1) {
      vis[a[i]] = i;
      s++;
      ans[s] = a[i];

    } else {
      while (ans[s] != a[i]) {
        vis[ans[s]] = -1;
        s--;
      }
      vis[ans[s]] = -1;
      s--;
    }
  }
  ff(i, 1, s) { printf("%d ", ans[i]); }
  return 0;
}