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

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <typeinfo>
#include <unordered_map>
#include <vector>

using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define REP(i, n) for (ll i = 0; i < n; i++)

int main() {
  ll n, x;
  cin >> n >> x;
  if (x == 1 || x == 2 * n - 1) {
    cout << "No" << endl;
    return 0;
  }
  if (x == 2) {
    vector<ll> ans(2 * n - 1);
    ans[n - 1] = x;
    ans[n] = x - 1;
    ans[n - 2] = x + 1;
    ans[n + 1] = x + 2;
    int c = 5;
    for (int i = 0; i < n - 2; i++) {
      ans[i] = c++;
    }
    for (int i = n + 2; i < 2 * n - 1; i++) {
      ans[i] = c++;
    }
    cout << "Yes" << endl;
    REP(i, 2 * n - 1) { cout << ans[i] << endl; }
    return 0;
  }
  vector<ll> ans(2 * n - 1);
  ans[n - 1] = x;
  ans[n] = x + 1;
  ans[n - 2] = x - 1;
  ans[n + 1] = x - 2;
  int c = 1;
  for (int i = 0; i < n - 2; i++) {
    if (c == x - 2) {
      c += 4;
    }
    ans[i] = c++;
  }
  for (int i = n + 2; i < 2 * n - 1; i++) {
    if (c == x - 2) {
      c += 4;
    }
    ans[i] = c++;
  }
  cout << "Yes" << endl;
  REP(i, 2 * n - 1) { cout << ans[i] << endl; }
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <typeinfo>
#include <unordered_map>
#include <vector>

using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define REP(i, n) for (ll i = 0; i < n; i++)

int main() {
  ll n, x;
  cin >> n >> x;
  if (x == 1 || x == 2 * n - 1) {
    cout << "No" << endl;
    return 0;
  }
  if (n == 2) {
    cout << "Yes" << endl << 1 << endl << 2 << endl << 3 << endl;
    return 0;
  }
  if (x == 2) {
    vector<ll> ans(2 * n - 1);
    ans[n - 1] = x;
    ans[n] = x - 1;
    ans[n - 2] = x + 1;
    ans[n + 1] = x + 2;
    int c = 5;
    for (int i = 0; i < n - 2; i++) {
      ans[i] = c++;
    }
    for (int i = n + 2; i < 2 * n - 1; i++) {
      ans[i] = c++;
    }
    cout << "Yes" << endl;
    REP(i, 2 * n - 1) { cout << ans[i] << endl; }
    return 0;
  }
  vector<ll> ans(2 * n - 1);
  ans[n - 1] = x;
  ans[n] = x + 1;
  ans[n - 2] = x - 1;
  ans[n + 1] = x - 2;
  int c = 1;
  for (int i = 0; i < n - 2; i++) {
    if (c == x - 2) {
      c += 4;
    }
    ans[i] = c++;
  }
  for (int i = n + 2; i < 2 * n - 1; i++) {
    if (c == x - 2) {
      c += 4;
    }
    ans[i] = c++;
  }
  cout << "Yes" << endl;
  REP(i, 2 * n - 1) { cout << ans[i] << endl; }
}
Problem p03952 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
const int maxn = 1e5;
int n, x;
int a[maxn + 8];

int read() {
  int x = 0, f = 1;
  char ch = getchar();
  for (; ch < '0' || ch > '9'; ch = getchar())
    if (ch == '-')
      f = -1;
  for (; ch >= '0' && ch <= '9'; ch = getchar())
    x = x * 10 + ch - '0';
  return x * f;
}

int main() {
  n = read(), x = read();
  if (x == 1 || x == 2 * n - 1) {
    puts("No");
    return 0;
  }
  if (n == 2) {
    puts("Yes");
    puts("1 2 3");
    return 0;
  }
  a[n] = x;
  if (x == 2) {
    a[n - 1] = x + 1, a[n + 1] = x - 1, a[n + 2] = x + 2;
    int now = 1;
    for (int i = 1; i < n - 1; i++) {
      if (now == x - 1)
        now = x + 3;
      a[i] = now++;
    }
    for (int i = n + 3; i < 2 * n; i++) {
      if (now == x - 1)
        now = x + 3;
      a[i] = now++;
    }
  } else {
    a[n - 1] = x - 1, a[n + 1] = x + 1, a[n + 2] = x - 2;
    int now = 1;
    for (int i = 1; i < n - 1; i++) {
      if (now == x - 2)
        now = x + 2;
      a[i] = now++;
    }
    for (int i = n + 3; i < 2 * n; i++) {
      if (now == x - 2)
        now = x + 2;
      a[i] = now++;
    }
  }
  puts("Yes");
  for (int i = 1; i < 2 * n; i++)
    printf("%d ", a[i]);
  puts("");
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
const int maxn = 1e5;
int n, x;
int a[maxn * 2 + 8];

int read() {
  int x = 0, f = 1;
  char ch = getchar();
  for (; ch < '0' || ch > '9'; ch = getchar())
    if (ch == '-')
      f = -1;
  for (; ch >= '0' && ch <= '9'; ch = getchar())
    x = x * 10 + ch - '0';
  return x * f;
}

int main() {
  n = read(), x = read();
  if (x == 1 || x == 2 * n - 1) {
    puts("No");
    return 0;
  }
  if (n == 2) {
    puts("Yes");
    puts("1 2 3");
    return 0;
  }
  a[n] = x;
  if (x == 2) {
    a[n - 1] = x + 1, a[n + 1] = x - 1, a[n + 2] = x + 2;
    int now = 1;
    for (int i = 1; i < n - 1; i++) {
      if (now == x - 1)
        now = x + 3;
      a[i] = now++;
    }
    for (int i = n + 3; i < 2 * n; i++) {
      if (now == x - 1)
        now = x + 3;
      a[i] = now++;
    }
  } else {
    a[n - 1] = x - 1, a[n + 1] = x + 1, a[n + 2] = x - 2;
    int now = 1;
    for (int i = 1; i < n - 1; i++) {
      if (now == x - 2)
        now = x + 2;
      a[i] = now++;
    }
    for (int i = n + 3; i < 2 * n; i++) {
      if (now == x - 2)
        now = x + 2;
      a[i] = now++;
    }
  }
  puts("Yes");
  for (int i = 1; i < 2 * n; i++)
    printf("%d ", a[i]);
  puts("");
  return 0;
}
Problem p03952 (C++)

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

using namespace std;

int main() {
  ios_base::sync_with_stdio(0);
  int n, x;
  cin >> n >> x;
  n = 2 * n - 1;
  --x;
  if (x == 0 || x == n - 1) {
    cout << "No";
    return 0;
  }
  cout << "Yes" << endl;
  vector<int> odp(n, -1);
  vector<bool> bylo(n, false);
  int s = n / 2;
  if (x == 1) {
    odp[s - 1] = 0;
    odp[s] = 1;
    odp[s + 1] = 2;
    odp[s - 2] = 3;
    bylo[0] = bylo[1] = bylo[2] = bylo[3] = true;
  }
  if (x == n - 2) {
    odp[s + 1] = n - 1;
    odp[s] = n - 2;
    odp[s - 1] = n - 3;
    odp[s + 2] = n - 4;
    bylo[n - 1] = bylo[n - 2] = bylo[n - 3] = bylo[n - 4] = true;
  }
  if (x != 1 && x != n - 2) {
    odp[s] = x;
    odp[s - 1] = x - 1;
    odp[s - 2] = x + 2;
    odp[s + 1] = x + 1;
    bylo[x] = bylo[x - 1] = bylo[x + 2] = bylo[x + 1] = true;
  }
  for (int i = 0, j = 0; i < n; ++i) {
    if (odp[i] == -1) {
      while (bylo[j])
        ++j;
      odp[i] = j;
      bylo[j] = true;
    }
  }
  for (int i = 0; i < n; ++i)
    cout << odp[i] + 1 << endl;
  return 0;
}


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

using namespace std;

int main() {
  ios_base::sync_with_stdio(0);
  int n, x;
  cin >> n >> x;
  n = 2 * n - 1;
  --x;
  if (x == 0 || x == n - 1) {
    cout << "No";
    return 0;
  }
  cout << "Yes" << endl;
  if (n == 3 && x == 1) {
    cout << "1\n2\n3";
    return 0;
  }
  vector<int> odp(n, -1);
  vector<bool> bylo(n, false);
  int s = n / 2;
  if (x == 1) {
    odp[s - 1] = 0;
    odp[s] = 1;
    odp[s + 1] = 2;
    odp[s - 2] = 3;
    bylo[0] = bylo[1] = bylo[2] = bylo[3] = true;
  }
  if (x == n - 2) {
    odp[s + 1] = n - 1;
    odp[s] = n - 2;
    odp[s - 1] = n - 3;
    odp[s + 2] = n - 4;
    bylo[n - 1] = bylo[n - 2] = bylo[n - 3] = bylo[n - 4] = true;
  }
  if (x != 1 && x != n - 2) {
    odp[s] = x;
    odp[s - 1] = x - 1;
    odp[s - 2] = x + 2;
    odp[s + 1] = x + 1;
    bylo[x] = bylo[x - 1] = bylo[x + 2] = bylo[x + 1] = true;
  }
  for (int i = 0, j = 0; i < n; ++i) {
    if (odp[i] == -1) {
      while (bylo[j])
        ++j;
      odp[i] = j;
      bylo[j] = true;
    }
  }
  for (int i = 0; i < n; ++i)
    cout << odp[i] + 1 << endl;
  return 0;
}
Problem p03952 (C++)

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

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

using namespace std;

typedef pair<int, int> P;

const int INF = 1e15;
const int MOD = 1e9 + 7;

signed main() {
  int n, x;
  cin >> n >> x;

  if (x == 1 || x == 2 * n - 1) {
    cout << "No" << endl;
    return 0;
  }

  vector<int> a(2 * n - 1);
  if (x == 2) {
    int m = (2 * n - 1) / 2;
    a[m - 1] = 2 * n - 1;
    a[m] = 1;
    a[m + 1] = 2;
    a[m + 2] = 2 * n - 2;

    int y = 3;
    for (int i = 0; i < 2 * n - 1; i++) {
      if (m - 1 <= i && i <= m + 2) {
        continue;
      }
      a[i] = y++;
    }
  } else {
    int m = (2 * n - 1) / 2;
    a[m - 1] = 1;
    a[m] = x;
    a[m + 1] = x + 1;
    a[m + 2] = 2;

    int y = 3;
    for (int i = 0; i < 2 * n - 1; i++) {
      if (m - 1 <= i && i <= m + 2) {
        continue;
      }
      if (y == x) {
        y += 2;
      }
      a[i] = y++;
    }
  }

  cout << "Yes" << endl;

  rep(i, 2 * n - 1) { cout << a[i] << endl; }
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <utility>
#include <vector>

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

using namespace std;

typedef pair<int, int> P;

const int INF = 1e15;
const int MOD = 1e9 + 7;

signed main() {
  int n, x;
  cin >> n >> x;

  if (n == 2 && x == 2) {
    cout << "Yes\n1\n2\n3" << endl;
    return 0;
  }

  if (x == 1 || x == 2 * n - 1) {
    cout << "No" << endl;
    return 0;
  }

  vector<int> a(2 * n - 1);
  if (x == 2) {
    int m = (2 * n - 1) / 2;
    a[m - 1] = 2 * n - 1;
    a[m] = 1;
    a[m + 1] = 2;
    a[m + 2] = 2 * n - 2;

    int y = 3;
    for (int i = 0; i < 2 * n - 1; i++) {
      if (m - 1 <= i && i <= m + 2) {
        continue;
      }
      a[i] = y++;
    }
  } else {
    int m = (2 * n - 1) / 2;
    a[m - 1] = 1;
    a[m] = x;
    a[m + 1] = x + 1;
    a[m + 2] = 2;

    int y = 3;
    for (int i = 0; i < 2 * n - 1; i++) {
      if (m - 1 <= i && i <= m + 2) {
        continue;
      }
      if (y == x) {
        y += 2;
      }
      a[i] = y++;
    }
  }

  cout << "Yes" << endl;

  rep(i, 2 * n - 1) { cout << a[i] << endl; }
  return 0;
}
Problem p03952 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using Map = map<ll, ll>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
ll INF = 1LL << 60;
ll MOD = 1000000007;

int main() {
  ll N;
  cin >> N;
  ll X;
  cin >> X;
  if (X == 1 || X == 2 * N - 1) {
    cout << "No" << endl;
    return 0;
  }
  if (N == 3) {
    cout << "Yes" << endl;
    cout << 1 << endl << 2 << endl << 3 << endl;
    return 0;
  }
  cout << "Yes" << endl;
  vector<ll> ans(2 * N, 0);
  if (X != 2 * N - 2) {
    ans[N - 1] = X + 2;
    ans[N] = X;
    ans[N + 1] = X - 1;
    ans[N + 2] = X + 1;

    ll mark = 1;
    ll in = 1;
    while (mark <= 2 * N - 1) {
      if (mark == N - 1) {
        mark += 4;
        continue;
      }
      if (in == X - 1) {
        in += 4;
      }
      ans[mark] = in;
      mark++;
      in++;
    }
  } else if (X == 2 * N - 2) {
    ans[N - 1] = X - 2;
    ans[N] = X;
    ans[N + 1] = X + 1;
    ans[N + 2] = X - 1;

    ll mark = 1;
    ll in = 1;
    while (mark <= 2 * N - 1) {
      if (mark == N - 1) {
        mark += 4;
      }
      if (in == X - 2) {
        in += 4;
      }
      ans[mark] = in;
      mark++;
      in++;
    }
  }
  for (ll i = 1; i < 2 * N; i++) {
    cout << ans[i] << endl;
    ;
  }

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using Map = map<ll, ll>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
ll INF = 1LL << 60;
ll MOD = 1000000007;

int main() {
  ll N;
  cin >> N;
  ll X;
  cin >> X;
  if (X == 1 || X == 2 * N - 1) {
    cout << "No" << endl;
    return 0;
  }
  if (N == 2) {
    cout << "Yes" << endl;
    cout << 1 << endl << 2 << endl << 3 << endl;
    return 0;
  }
  cout << "Yes" << endl;
  vector<ll> ans(2 * N, 0);
  if (X != 2 * N - 2) {
    ans[N - 1] = X + 2;
    ans[N] = X;
    ans[N + 1] = X - 1;
    ans[N + 2] = X + 1;

    ll mark = 1;
    ll in = 1;
    while (mark <= 2 * N - 1) {
      if (mark == N - 1) {
        mark += 4;
        continue;
      }
      if (in == X - 1) {
        in += 4;
      }
      ans[mark] = in;
      mark++;
      in++;
    }
  } else if (X == 2 * N - 2) {
    ans[N - 1] = X - 2;
    ans[N] = X;
    ans[N + 1] = X + 1;
    ans[N + 2] = X - 1;

    ll mark = 1;
    ll in = 1;
    while (mark <= 2 * N - 1) {
      if (mark == N - 1) {
        mark += 4;
      }
      if (in == X - 2) {
        in += 4;
      }
      ans[mark] = in;
      mark++;
      in++;
    }
  }
  for (ll i = 1; i < 2 * N; i++) {
    cout << ans[i] << endl;
    ;
  }

  return 0;
}
Problem p03952 (C++)

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

using namespace std;

int main(void) {
  int n, x, N;
  cin >> n >> x;
  N = n;

  if (x == 1 || 2 * n - 1 == x) {
    cout << "No" << endl;
    return 0;
  }
  if (n == 2 && x != 2) {
    cout << "No" << endl;
    return 0;
  } else if (n == 2 && x == 2) {
    cout << "Yes" << endl;
    cout << 1 << endl;
    cout << 2 << endl;
    cout << 3 << endl;
    return 0;
  }
  cout << "Yes" << endl;
  if (x < 2 * n - 2) {
    vector<int> is_used(2 * N, 0);
    vector<int> ans(2 * N - 1, -1);
    ans[N - 1] = x;
    ans[N - 2] = x + 2;
    ans[N] = x - 1;
    ans[N + 1] = x + 1;
    is_used[x] = 1;
    is_used[x + 2] = 1;
    is_used[x - 1] = 1;
    is_used[x + 1] = 1;
    int cnt = 0;
    for (int i = 1; i <= 2 * N - 1; i++) {
      if (is_used[i] == 0) {
        while (ans[cnt] != -1)
          cnt++;
        ans[cnt] = i;
        cnt++;
      }
    }
    for (auto a : ans)
      cout << a << endl;
  } else {
    vector<int> is_used(2 * N, 0);
    vector<int> ans(2 * N - 1, -1);
    ans[N - 1] = x;
    ans[N - 2] = x - 2;
    ans[N] = x + 1;
    ans[N + 1] = x - 1;
    is_used[x] = 1;
    is_used[x - 2] = 1;
    is_used[x + 1] = 1;
    is_used[x - 1] = 1;
    int cnt = 0;
    for (int i = 1; i <= 2 * N - 1; i++) {
      if (is_used[i]) {
        while (ans[cnt] != -1)
          cnt++;
        ans[cnt] = i;
        cnt++;
      }
    }
    for (auto a : ans)
      cout << a << endl;
  }
}


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

using namespace std;

int main(void) {
  int n, x, N;
  cin >> n >> x;
  N = n;

  if (x == 1 || 2 * n - 1 == x) {
    cout << "No" << endl;
    return 0;
  }
  if (n == 2 && x != 2) {
    cout << "No" << endl;
    return 0;
  } else if (n == 2 && x == 2) {
    cout << "Yes" << endl;
    cout << 1 << endl;
    cout << 2 << endl;
    cout << 3 << endl;
    return 0;
  }
  cout << "Yes" << endl;
  if (x < 2 * n - 2) {
    vector<int> is_used(2 * N, 0);
    vector<int> ans(2 * N - 1, -1);
    ans[N - 1] = x;
    ans[N - 2] = x + 2;
    ans[N] = x - 1;
    ans[N + 1] = x + 1;
    is_used[x] = 1;
    is_used[x + 2] = 1;
    is_used[x - 1] = 1;
    is_used[x + 1] = 1;
    int cnt = 0;
    for (int i = 1; i <= 2 * N - 1; i++) {
      if (is_used[i] == 0) {
        while (ans[cnt] != -1)
          cnt++;
        ans[cnt] = i;
        cnt++;
      }
    }
    for (auto a : ans)
      cout << a << endl;
  } else {
    vector<int> is_used(2 * N, 0);
    vector<int> ans(2 * N - 1, -1);
    ans[N - 1] = x;
    ans[N - 2] = x - 2;
    ans[N] = x + 1;
    ans[N + 1] = x - 1;
    is_used[x] = 1;
    is_used[x - 2] = 1;
    is_used[x + 1] = 1;
    is_used[x - 1] = 1;
    int cnt = 0;
    for (int i = 1; i <= 2 * N - 1; i++) {
      if (is_used[i] == 0) {
        while (ans[cnt] != -1)
          cnt++;
        ans[cnt] = i;
        cnt++;
      }
    }
    for (auto a : ans)
      cout << a << endl;
  }
}
Problem p03952 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <queue>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>
#define m 1000000007
using namespace std;

int a, b, c, n, i, d, o[130300], l[100010], e,
    dx[10] = {0, -1, 1, 0, 0, -1, -1, 1, 1},
    dy[10] = {0, 0, 0, -1, 1, -1, 1, -1, 1};
long long x, y, z, k;
stack<int> s;
queue<int> qx, qy, qn;
string r1, r2;
vector<pair<int, int>> v[200010];
// char r1[1010],r2[1010],r3[1010];

int main() {
  scanf("%d %d", &a, &b);
  if (b == 1 || b == 2 * a - 1)
    printf("No");
  else {
    for (int t = a - 1, w = 2 * a - 1; t >= 1; w--)
      if (w != b) {
        o[t] = w;
        t--;
      }
    o[a] = b;
    for (int t = a + 1, w = 1; t <= 2 * a - 1; w++)
      if (w != b) {
        o[t] = w;
        t++;
      }
    puts("Yes");
    for (int t = 1; t <= a * 2 - 1; t++)
      printf("%d\n", o[t]);
  }

  return 0;
}

Fixed submission:
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <queue>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>
#define m 1000000007
using namespace std;

int a, b, c, n, i, d, o[230300], l[100010], e,
    dx[10] = {0, -1, 1, 0, 0, -1, -1, 1, 1},
    dy[10] = {0, 0, 0, -1, 1, -1, 1, -1, 1};
long long x, y, z, k;
stack<int> s;
queue<int> qx, qy, qn;
string r1, r2;
vector<pair<int, int>> v[200010];
// char r1[1010],r2[1010],r3[1010];

int main() {
  scanf("%d %d", &a, &b);
  if (b == 1 || b == 2 * a - 1)
    printf("No");
  else {
    for (int t = a - 1, w = 2 * a - 1; t >= 1; w--)
      if (w != b) {
        o[t] = w;
        t--;
      }
    o[a] = b;
    for (int t = a + 1, w = 1; t <= 2 * a - 1; w++)
      if (w != b) {
        o[t] = w;
        t++;
      }
    puts("Yes");
    for (int t = 1; t <= a * 2 - 1; t++)
      printf("%d\n", o[t]);
  }

  return 0;
}
Problem p03952 (C++)

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

  int n, x;
  cin >> n >> x;
  if (x == 1 || x == 2 * n - 1) {
    cout << "No\n";
    return 0;
  }

  cout << "Yes\n";

  vector<int> v(2 * n - 1);
  int c = x;
  for (int i = (2 * n - 1) / 2; i < 2 * n - 1 && c <= 2 * n - 1; ++i) {
    v[i] = c;
    c++;
  }
  c = x - 1;
  for (int i = (2 * n - 1) / 2 - 1; c > 0; i--) {
    v[i] = c;
    c--;
  }
  c = 1;
  for (int i = 2 * n - 2; v[i] == 0; i--) {
    v[i] = c;
    c++;
  }
  c = v[2 * n - 2] + 1;
  for (int i = 0; v[i] == 0; ++i) {
    v[i] = c;
    c++;
  }
  for (int i = 0; i < 2 * n - 1; ++i) {
    cout << v[i] << '\n';
  }
}
/*
5
6 6
7 6 2
1  2 2
2 3 3
3 4
4
*/


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

  int n, x;
  cin >> n >> x;
  if (x == 1 || x == 2 * n - 1) {
    cout << "No\n";
    return 0;
  }

  cout << "Yes\n";

  vector<int> v(2 * n - 1);
  int c = x;
  for (int i = (2 * n - 1) / 2; i < 2 * n - 1 && c <= 2 * n - 1; ++i) {
    v[i] = c;
    c++;
  }
  c = x - 1;
  for (int i = (2 * n - 1) / 2 - 1; c > 0 && i >= 0; i--) {
    v[i] = c;
    c--;
  }
  c = 1;
  for (int i = 2 * n - 2; v[i] == 0; i--) {
    v[i] = c;
    c++;
  }
  c = v[2 * n - 2] + 1;
  for (int i = 0; v[i] == 0; ++i) {
    v[i] = c;
    c++;
  }
  for (int i = 0; i < 2 * n - 1; ++i) {
    cout << v[i] << '\n';
  }
}
/*
5
6 6
7 6 2
1  2 2
2 3 3
3 4
4
*/
Problem p03952 (C++)

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

using namespace std;

int N, x;
int a[123456];

int main() {

  cin >> N >> x;

  if (x == 1 || x == 2 * N - 1)
    puts("No");
  else if (N == 2) {
    puts("Yes");
    printf("1\n");
    printf("2\n");
    printf("3\n");
  } else {
    if (x <= N) {
      a[N] = x + 2;
      a[N - 1] = 1;
      a[N - 2] = x;
      a[N - 3] = x + 1;
      int j = 1;
      for (int i = 0; i < 2 * N - 1; i++) {
        if (a[i] == 0) {
          while ((j == x + 2 || j == 1) || (j == x || j == x + 1)) {
            j++;
          }
          a[i] = j++;
        }
      }
    } else {
      a[N] = x - 2;
      a[N - 1] = 2 * N - 1;
      a[N - 2] = x;
      a[N - 3] = x - 1;
      int j = 1;
      for (int i = 0; i < 2 * N - 1; i++) {
        if (a[i] == 0) {
          while ((j == x - 2 || j == 2 * N - 1) || (j == x || j == x - 1)) {
            j++;
          }
          a[i] = j++;
        }
      }
    }
    puts("Yes");
    for (int i = 0; i < 2 * N - 1; i++) {
      printf("%d\n", a[i]);
    }
  }

  return 0;
}

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

using namespace std;

int N, x;
int a[234567];

int main() {

  cin >> N >> x;

  if (x == 1 || x == 2 * N - 1)
    puts("No");
  else if (N == 2) {
    puts("Yes");
    printf("1\n");
    printf("2\n");
    printf("3\n");
  } else {
    if (x <= N) {
      a[N] = x + 2;
      a[N - 1] = 1;
      a[N - 2] = x;
      a[N - 3] = x + 1;
      int j = 1;
      for (int i = 0; i < 2 * N - 1; i++) {
        if (a[i] == 0) {
          while ((j == x + 2 || j == 1) || (j == x || j == x + 1)) {
            j++;
          }
          a[i] = j++;
        }
      }
    } else {
      a[N] = x - 2;
      a[N - 1] = 2 * N - 1;
      a[N - 2] = x;
      a[N - 3] = x - 1;
      int j = 1;
      for (int i = 0; i < 2 * N - 1; i++) {
        if (a[i] == 0) {
          while ((j == x - 2 || j == 2 * N - 1) || (j == x || j == x - 1)) {
            j++;
          }
          a[i] = j++;
        }
      }
    }
    puts("Yes");
    for (int i = 0; i < 2 * N - 1; i++) {
      printf("%d\n", a[i]);
    }
  }

  return 0;
}
Problem p03952 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;
typedef long long ll;
const int maxn = 100005;

int a[maxn];
bool vis[maxn];

int main() {
  // freopen("in.cpp","r",stdin);
  int n, m;
  cin >> n >> m;
  int l = 2, r = n + n - 2;
  if (m >= l && m <= r) {
    cout << "Yes" << endl;
    a[n - 1] = m;
    vis[m] = 1;
    a[n - 2] = 1;
    vis[1] = 1;
    a[n] = n + n - 1;
    vis[n + n - 1] = 1;
    if (m != n + n - 2) {
      a[n + 1] = n + n - 2;
      vis[n + n - 2] = 1;
    } else {
      a[n - 3] = 2;
      vis[2] = 1;
    }
    int pos = 0;
    for (int i = 1; i <= n + n - 1; i++) {
      if (vis[i])
        continue;
      while (a[pos])
        pos++;
      a[pos] = i;
    }
    for (int i = 0; i < n + n - 1; i++)
      cout << a[i] << endl;
  } else
    cout << "No" << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;
typedef long long ll;
const int maxn = 200005;

int a[maxn];
bool vis[maxn];

int main() {
  // freopen("in.cpp","r",stdin);
  int n, m;
  cin >> n >> m;
  int l = 2, r = n + n - 2;
  if (m >= l && m <= r) {
    cout << "Yes" << endl;
    a[n - 1] = m;
    vis[m] = 1;
    a[n - 2] = 1;
    vis[1] = 1;
    a[n] = n + n - 1;
    vis[n + n - 1] = 1;
    if (m != n + n - 2) {
      a[n + 1] = n + n - 2;
      vis[n + n - 2] = 1;
    } else {
      a[n - 3] = 2;
      vis[2] = 1;
    }
    int pos = 0;
    for (int i = 1; i <= n + n - 1; i++) {
      if (vis[i])
        continue;
      while (a[pos])
        pos++;
      a[pos] = i;
    }
    for (int i = 0; i < n + n - 1; i++)
      cout << a[i] << endl;
  } else
    cout << "No" << endl;
  return 0;
}
Problem p03952 (C++)

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

using namespace std;

int main(void) {
  int N, x;
  cin >> N >> x;
  if (x == 1 || x == 2 * N - 1)
    cout << "No" << endl;
  else {
    vector<int> p(2 * N, 0), c(2 * N, 0);
    if (min((2 * N - 1) - x + 1, x) == x) {
      for (int i = 1; i <= 2 * x - 1; i++) {
        p[N - (x - i)] = i;
        c[i] = 1;
      }
    } else {
      for (int i = 2 * N - 1; i >= 2 * x - (2 * N - 1); i++) {
        p[N - (x - i)] = i;
        c[i] = 1;
      }
    }
    auto itrc = c.begin() + 1;
    while (*itrc != 0)
      itrc++;
    for (auto itr = p.begin() + 1; itr != p.end(); itr++) {
      if (*itr != 0)
        continue;
      else {
        *itr = distance(c.begin(), itrc);
        *itrc = 1;
        while (*itrc != 0)
          itrc++;
      }
    }
    cout << "Yes" << endl;
    for (auto itr = p.begin() + 1; itr != p.end(); itr++) {
      cout << *itr << endl;
    }
  }

  return 0;
}

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

using namespace std;

int main(void) {
  int N, x;
  cin >> N >> x;
  if (x == 1 || x == 2 * N - 1)
    cout << "No" << endl;
  else {
    vector<int> p(2 * N, 0), c(2 * N, 0);
    if (min((2 * N - 1) - x + 1, x) == x) {
      for (int i = 1; i <= 2 * x - 1; i++) {
        p[N - (x - i)] = i;
        c[i] = 1;
      }
    } else {
      for (int i = 2 * N - 1; i >= 2 * x - (2 * N - 1); i--) {
        p[N - (x - i)] = i;
        c[i] = 1;
      }
    }
    auto itrc = c.begin() + 1;
    while (*itrc != 0)
      itrc++;
    for (auto itr = p.begin() + 1; itr != p.end(); itr++) {
      if (*itr != 0)
        continue;
      else {
        *itr = distance(c.begin(), itrc);
        *itrc = 1;
        while (*itrc != 0)
          itrc++;
      }
    }
    cout << "Yes" << endl;
    for (auto itr = p.begin() + 1; itr != p.end(); itr++) {
      cout << *itr << endl;
    }
  }

  return 0;
}
Problem p03953 (C++)

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

using ll = long long;
array<int, 200000> buf;
void merge(vector<int> &lhs, vector<int> rhs) {
  int n = lhs.size();
  for (int i = 0; i < n; i++) {
    buf[i] = lhs[rhs[i]];
  }
  for (int i = 0; i < n; i++)
    lhs[i] = buf[i];
}
int main() {
  int n;
  cin >> n;
  vector<ll> x(n);
  for (int i = 0; i < n; i++)
    cin >> x[i];
  int m;
  ll k;
  cin >> m >> k;
  vector<int> a(n);
  for (int i = 0; i < m; i++)
    cin >> a[i], a[i]--;

  // cerr<<"#PERM PHASE"<<endl;
  vector<int> perm(n - 1);
  iota(perm.begin(), perm.end(), 0);
  for (int i = 0; i < m; i++) {
    // assert(0<=a[i]-1 && a[i]<n-1);
    swap(perm[a[i] - 1], perm[a[i]]);
  }
  vector<int> diff(n - 1);
  for (int i = 0; i + 1 < n; i++)
    diff[i] = x[i + 1] - x[i];

  // cerr<<"#POW PHASE"<<endl;
  while (k) {
    if (k & 1)
      merge(diff, perm);
    k >>= 1;
    merge(perm, perm);
  }

  // cerr<<"#RESTORE PHASE"<<endl;
  vector<ll> res(n);
  res[0] = x[0];
  for (int i = 1; i < n; i++) {
    res[i] = res[i - 1] + diff[i - 1];
  }
  for (int i = 0; i < n; i++) {
    cout << res[i] << endl;
  }
  return 0;
}

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

using ll = long long;
array<int, 200000> buf;
void merge(vector<int> &lhs, vector<int> rhs) {
  int n = lhs.size();
  for (int i = 0; i < n; i++) {
    buf[i] = lhs[rhs[i]];
  }
  for (int i = 0; i < n; i++)
    lhs[i] = buf[i];
}
int main() {
  int n;
  cin >> n;
  vector<ll> x(n);
  for (int i = 0; i < n; i++)
    cin >> x[i];
  int m;
  ll k;
  cin >> m >> k;
  vector<int> a(m);
  for (int i = 0; i < m; i++)
    cin >> a[i], a[i]--;

  // cerr<<"#PERM PHASE"<<endl;
  vector<int> perm(n - 1);
  iota(perm.begin(), perm.end(), 0);
  for (int i = 0; i < m; i++) {
    // assert(0<=a[i]-1 && a[i]<n-1);
    swap(perm[a[i] - 1], perm[a[i]]);
  }
  vector<int> diff(n - 1);
  for (int i = 0; i + 1 < n; i++)
    diff[i] = x[i + 1] - x[i];

  // cerr<<"#POW PHASE"<<endl;
  while (k) {
    if (k & 1)
      merge(diff, perm);
    k >>= 1;
    merge(perm, perm);
  }

  // cerr<<"#RESTORE PHASE"<<endl;
  vector<ll> res(n);
  res[0] = x[0];
  for (int i = 1; i < n; i++) {
    res[i] = res[i - 1] + diff[i - 1];
  }
  for (int i = 0; i < n; i++) {
    cout << res[i] << endl;
  }
  return 0;
}
Problem p03953 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cstdio>
using namespace std;
typedef long long ll;
const int N = 100100;
int i, j, k, n, m, ch, ff;
ll K;
int x[N], a[N], p[N], ans[N], tmp[N];
ll Ans[N];
void R(int &x) {
  ff = x = 0;
  ch = getchar();
  while (ch < '0' || '9' < ch) {
    if (ch == '-')
      ff = 1;
    ch = getchar();
  }
  while ('0' <= ch && ch <= '9')
    x = x * 10 + ch - '0', ch = getchar();
  if (ff)
    x = -x;
}
void R(ll &x) {
  ff = x = 0;
  ch = getchar();
  while (ch < '0' || '9' < ch) {
    if (ch == '-')
      ff = 1;
    ch = getchar();
  }
  while ('0' <= ch && ch <= '9')
    x = x * 10 + ch - '0', ch = getchar();
  if (ff)
    x = -x;
}
void W(ll x) {
  if (x < 0)
    putchar('-'), x = -x;
  if (x >= 10)
    W(x / 10);
  putchar(x % 10 + '0');
}
void work(int *A, int *B, int *C) {
  int i;
  for (i = 1; i < n; i++)
    tmp[i] = A[B[i]];
  for (i = 1; i < n; i++)
    C[i] = tmp[i];
}
int main() {
  freopen("1_04.txt", "r", stdin);
  R(n);
  for (i = 1; i <= n; i++)
    R(x[i]);
  R(m);
  R(K);
  for (i = 1; i < n; i++)
    ans[i] = p[i] = i;
  for (i = 1; i <= m; i++) {
    R(a[i]);
    swap(p[a[i] - 1], p[a[i]]);
  }
  for (; K; K >>= 1, work(p, p, p))
    if (K & 1)
      work(ans, p, ans);
  for (i = 1; i < n; i++)
    Ans[i] = x[ans[i] + 1] - x[ans[i]];
  Ans[0] = x[1];
  for (i = 1; i < n; i++)
    Ans[i] += Ans[i - 1];
  for (i = 0; i < n; i++)
    W(Ans[i]), puts("");
}

Fixed submission:
#include <algorithm>
#include <cstdio>
using namespace std;
typedef long long ll;
const int N = 100100;
int i, j, k, n, m, ch, ff;
ll K;
int x[N], a[N], p[N], ans[N], tmp[N];
ll Ans[N];
void R(int &x) {
  ff = x = 0;
  ch = getchar();
  while (ch < '0' || '9' < ch) {
    if (ch == '-')
      ff = 1;
    ch = getchar();
  }
  while ('0' <= ch && ch <= '9')
    x = x * 10 + ch - '0', ch = getchar();
  if (ff)
    x = -x;
}
void R(ll &x) {
  ff = x = 0;
  ch = getchar();
  while (ch < '0' || '9' < ch) {
    if (ch == '-')
      ff = 1;
    ch = getchar();
  }
  while ('0' <= ch && ch <= '9')
    x = x * 10 + ch - '0', ch = getchar();
  if (ff)
    x = -x;
}
void W(ll x) {
  if (x < 0)
    putchar('-'), x = -x;
  if (x >= 10)
    W(x / 10);
  putchar(x % 10 + '0');
}
void work(int *A, int *B, int *C) {
  int i;
  for (i = 1; i < n; i++)
    tmp[i] = A[B[i]];
  for (i = 1; i < n; i++)
    C[i] = tmp[i];
}
int main() {
  R(n);
  for (i = 1; i <= n; i++)
    R(x[i]);
  R(m);
  R(K);
  for (i = 1; i < n; i++)
    ans[i] = p[i] = i;
  for (i = 1; i <= m; i++) {
    R(a[i]);
    swap(p[a[i] - 1], p[a[i]]);
  }
  for (; K; K >>= 1, work(p, p, p))
    if (K & 1)
      work(ans, p, ans);
  for (i = 1; i < n; i++)
    Ans[i] = x[ans[i] + 1] - x[ans[i]];
  Ans[0] = x[1];
  for (i = 1; i < n; i++)
    Ans[i] += Ans[i - 1];
  for (i = 0; i < n; i++)
    W(Ans[i]), puts("");
}
Problem p03953 (C++)

Buggy submission (status: Runtime Error):
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const double PI = 3.141592653589793238;
const double EPS = 1e-10;
ll x[100000];
int perm[100000];
bool used[100000];
ll d[100000];
int main() {
  int N;
  cin >> N;
  for (int i = 0; i < N; i++)
    cin >> x[i];
  for (int i = 0; i + 1 < N; i++)
    perm[i] = i;
  int M, K;
  cin >> M >> K;
  for (int i = 0; i < M; i++) {
    int a;
    cin >> a;
    a--;
    swap(perm[a], perm[a - 1]);
  }
  for (int i = 0; i + 1 < N; i++) {
    if (used[i])
      continue;
    vector<int> v;
    while (!used[i]) {
      v.push_back(i);
      used[i] = 1;
      i = perm[i];
    }
    for (int j = 0; j < v.size(); j++) {
      int k = v[(j + K) % v.size()];
      d[v[j]] = x[k + 1] - x[k];
    }
  }
  cout << x[0] << endl;
  ll now = x[0];
  for (int i = 0; i + 1 < N; i++) {
    now += d[i];
    cout << now << endl;
  }
}


Fixed submission:
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const double PI = 3.141592653589793238;
const double EPS = 1e-10;
ll x[100000];
int perm[100000];
bool used[100000];
ll d[100000];
int main() {
  int N;
  cin >> N;
  for (int i = 0; i < N; i++)
    cin >> x[i];
  for (int i = 0; i + 1 < N; i++)
    perm[i] = i;
  int M;
  ll K;
  cin >> M >> K;
  for (int i = 0; i < M; i++) {
    int a;
    cin >> a;
    a--;
    swap(perm[a], perm[a - 1]);
  }
  for (int i = 0; i + 1 < N; i++) {
    if (used[i])
      continue;
    vector<int> v;
    while (!used[i]) {
      v.push_back(i);
      used[i] = 1;
      i = perm[i];
    }
    for (int j = 0; j < v.size(); j++) {
      int k = v[(j + K) % v.size()];
      d[v[j]] = x[k + 1] - x[k];
    }
  }
  cout << x[0] << endl;
  ll now = x[0];
  for (int i = 0; i + 1 < N; i++) {
    now += d[i];
    cout << now << endl;
  }
}
Problem p03953 (C++)

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

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef pair<LL, LL> PLL;

#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(), (c).end())

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

#define FF first
#define SS second
template <class S, class T> istream &operator>>(istream &is, pair<S, T> &p) {
  return is >> p.FF >> p.SS;
}

const double EPS = 1e-10;
const double PI = acos(-1.0);
const LL MOD = 1e9 + 7;

VI pow(VI p, LL k, int n) {
  VI ans(n);
  REP(i, n) ans[i] = i;
  while (k > 0) {
    VI tmp(n);
    if (k & 1) {
      REP(i, n)
      tmp[i] = ans[p[i]];
      ans = tmp;
    }
    REP(i, n)
    tmp[i] = p[p[i]];
    p = tmp;
    k /= 2;
  }
  return ans;
}

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

  int N;
  cin >> N;
  vector<LL> xs(N);
  REP(i, N) cin >> xs[i];
  vector<LL> ds(N - 1);
  REP(i, N - 1) ds[i] = xs[i + 1] - xs[i];

  LL M, K;
  cin >> M >> K;
  VI as(M);
  VI pm(N - 1);
  REP(i, N) pm[i] = i;
  REP(i, M) {
    cin >> as[i];
    --as[i];
    swap(pm[as[i]], pm[as[i] - 1]);
  }
  pm = pow(pm, K, N - 1);

  LL x = xs[0];
  cout << x << endl;
  REP(i, N - 1) {
    x += ds[pm[i]];
    cout << x << endl;
  }

  return 0;
}


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

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef pair<LL, LL> PLL;

#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(), (c).end())

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

#define FF first
#define SS second
template <class S, class T> istream &operator>>(istream &is, pair<S, T> &p) {
  return is >> p.FF >> p.SS;
}

const double EPS = 1e-10;
const double PI = acos(-1.0);
const LL MOD = 1e9 + 7;

VI pow(VI p, LL k, int n) {
  VI ans(n);
  REP(i, n) ans[i] = i;
  while (k > 0) {
    VI tmp(n);
    if (k & 1) {
      REP(i, n)
      tmp[i] = ans[p[i]];
      ans = tmp;
    }
    REP(i, n)
    tmp[i] = p[p[i]];
    p = tmp;
    k /= 2;
  }
  return ans;
}

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

  int N;
  cin >> N;
  vector<LL> xs(N);
  REP(i, N) cin >> xs[i];
  vector<LL> ds(N - 1);
  REP(i, N - 1) ds[i] = xs[i + 1] - xs[i];

  LL M, K;
  cin >> M >> K;
  VI as(M);
  VI pm(N - 1);
  REP(i, N - 1) pm[i] = i;
  REP(i, M) {
    cin >> as[i];
    --as[i];
    swap(pm[as[i]], pm[as[i] - 1]);
  }
  pm = pow(pm, K, N - 1);

  LL x = xs[0];
  cout << x << endl;
  REP(i, N - 1) {
    x += ds[pm[i]];
    cout << x << endl;
  }

  return 0;
}
Problem p03953 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <cstring>
#define repu(i, x, y) for (int i = x; i <= y; ++i)
#define repd(i, x, y) for (int i = x; i >= y; --i)
using namespace std;

typedef long long LL;
int n, m, d[100100], p[100100], a[100100], ans[100100];
LL k;
bool flag[100100];

int getint() {
  char ch;
  while (!isdigit(ch = getchar()) && ch != '-')
    ;
  bool flag = ch == '-';
  if (flag)
    ch = getchar();
  int x = ch - '0';
  for (; isdigit(ch = getchar()); x = x * 10 + ch - '0')
    ;
  return flag ? -x : x;
}

int main() {
  n = getint() - 1;
  repu(i, 0, n) d[i] = getint();
  repd(i, n, 1) d[i] -= d[i - 1];
  repu(i, 1, n) p[i] = i;
  for (scanf("%d%lld", &m, &k); m--;) {
    int x = getint();
    swap(p[x], p[x - 1]);
  }
  repu(i, 1, n) if (!flag[i]) {
    a[0] = i, m = 1;
    for (int j = p[i]; j != i; a[m++] = j, j = p[j])
      ;
    repu(j, 0, m - 1) ans[a[j]] = a[(j + k) % m];
  }
  LL sum = d[0];
  printf("%lld\n", sum);
  repu(i, 1, n) printf("%lld\n", sum += d[ans[i]]);
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <cstring>
#define repu(i, x, y) for (int i = x; i <= y; ++i)
#define repd(i, x, y) for (int i = x; i >= y; --i)
using namespace std;

typedef long long LL;
int n, m, d[100100], p[100100], a[100100], ans[100100];
LL k;
bool flag[100100];

int getint() {
  char ch;
  while (!isdigit(ch = getchar()) && ch != '-')
    ;
  bool flag = ch == '-';
  if (flag)
    ch = getchar();
  int x = ch - '0';
  for (; isdigit(ch = getchar()); x = x * 10 + ch - '0')
    ;
  return flag ? -x : x;
}

int main() {
  n = getint() - 1;
  repu(i, 0, n) d[i] = getint();
  repd(i, n, 1) d[i] -= d[i - 1];
  repu(i, 1, n) p[i] = i;
  for (scanf("%d%lld", &m, &k); m--;) {
    int x = getint();
    swap(p[x], p[x - 1]);
  }
  repu(i, 1, n) if (!flag[i]) {
    flag[a[0] = i] = 1, m = 1;
    for (int j = p[i]; j != i; flag[a[m++] = j] = 1, j = p[j])
      ;
    repu(j, 0, m - 1) ans[a[j]] = a[(j + k) % m];
  }
  LL sum = d[0];
  printf("%lld\n", sum);
  repu(i, 1, n) printf("%lld\n", sum += d[ans[i]]);
  return 0;
}
Problem p03953 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define reg register
#define ll long long
#define maxn 21
using namespace std;
inline ll read() {
  reg ll s = 0, t = 0;
  reg char ch = getchar();
  while (ch > '9' || ch < '0')
    t |= ch == '-', ch = getchar();
  while (ch >= '0' && ch <= '9')
    s = (s << 1) + (s << 3) + (ch ^ 48), ch = getchar();
  return t ? -s : s;
}
ll n, x[maxn], m, k, d[maxn], cha[maxn], sum[maxn], belong[maxn];
ll nxt[maxn], w[maxn], a[maxn], vis[maxn], f[maxn], cnt;
vector<ll> Q[maxn];
int main() {
  n = read();
  for (int i = 1; i <= n; i++)
    x[i] = read(), cha[i] = x[i] - x[i - 1];
  m = read();
  k = read();
  for (int i = 1; i <= m; i++)
    a[i] = read();
  for (int j = 1; j <= n; j++)
    d[j] = j;
  for (int i = 1; i <= m; i++)
    swap(d[a[i]], d[a[i] + 1]);
  for (int i = 1; i <= n; i++)
    nxt[d[i]] = i;
  for (int i = 1; i <= n; i++) {
    if (vis[i] == 0) {
      int p = i;
      cnt++;
      while (!vis[p]) {
        Q[cnt].push_back(p);
        vis[p] = 1;
        sum[cnt]++;
        belong[p] = cnt;
        f[p] = sum[cnt] - 1;
        p = nxt[p];
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    int p = k % sum[belong[i]];
    nxt[i] = Q[belong[i]][(f[i] + p) % sum[belong[i]]];
    w[nxt[i]] = i;
  }
  for (int i = 1; i <= n; i++)
    a[i] = cha[w[i]];
  for (int i = 1; i <= n; i++)
    a[i] += a[i - 1], printf("%lld\n", a[i]);
}


Fixed submission:
#include <bits/stdc++.h>
#define reg register
#define ll long long
#define maxn 200001
using namespace std;
inline ll read() {
  reg ll s = 0, t = 0;
  reg char ch = getchar();
  while (ch > '9' || ch < '0')
    t |= ch == '-', ch = getchar();
  while (ch >= '0' && ch <= '9')
    s = (s << 1) + (s << 3) + (ch ^ 48), ch = getchar();
  return t ? -s : s;
}
ll n, x[maxn], m, k, d[maxn], cha[maxn], sum[maxn], belong[maxn];
ll nxt[maxn], w[maxn], a[maxn], vis[maxn], f[maxn], cnt;
vector<ll> Q[maxn];
int main() {
  n = read();
  for (int i = 1; i <= n; i++)
    x[i] = read(), cha[i] = x[i] - x[i - 1];
  m = read();
  k = read();
  for (int i = 1; i <= m; i++)
    a[i] = read();
  for (int j = 1; j <= n; j++)
    d[j] = j;
  for (int i = 1; i <= m; i++)
    swap(d[a[i]], d[a[i] + 1]);
  for (int i = 1; i <= n; i++)
    nxt[d[i]] = i;
  for (int i = 1; i <= n; i++) {
    if (vis[i] == 0) {
      int p = i;
      cnt++;
      while (!vis[p]) {
        Q[cnt].push_back(p);
        vis[p] = 1;
        sum[cnt]++;
        belong[p] = cnt;
        f[p] = sum[cnt] - 1;
        p = nxt[p];
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    int p = k % sum[belong[i]];
    nxt[i] = Q[belong[i]][(f[i] + p) % sum[belong[i]]];
    w[nxt[i]] = i;
  }
  for (int i = 1; i <= n; i++)
    a[i] = cha[w[i]];
  for (int i = 1; i <= n; i++)
    a[i] += a[i - 1], printf("%lld\n", a[i]);
}
Problem p03953 (C++)

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

const int MAX_N = 1e5;
int N, M, K;

typedef vector<int> vec;

vec mul(vec a, vec b) {
  vec ret(N - 1);
  REP(i, N - 1) { ret[i] = a[b[i]]; }
  return ret;
}

vec pw(vec n, ll m) {
  vec ret(N - 1);
  REP(i, N - 1) { ret[i] = i; }
  if (!m) {
    return ret;
  }
  ret = pw(n, m / 2);
  ret = mul(ret, ret);
  if (m & 1) {
    ret = mul(ret, n);
  }
  return ret;
}

int main() {
  ll x0, x1, x;
  cin >> N >> x0;
  x = x0;
  vec dif(N - 1);
  REP(i, N - 1) {
    cin >> x1;
    dif[i] = x1 - x0;
    swap(x0, x1);
  }
  cin >> M >> K;
  vec p(N - 1);
  REP(i, N - 1) { p[i] = i; }
  REP(i, M) {
    int a;
    cin >> a;
    swap(p[a - 2], p[a - 1]);
  }
  p = pw(p, K);
  dif = mul(dif, p);
  cout << x << endl;
  x1 = x;
  REP(i, N - 1) {
    x1 += dif[i];
    cout << x1 << endl;
  }
  return 0;
}

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

const int MAX_N = 1e5;
int N, M;
ll K;

typedef vector<int> vec;

vec mul(vec a, vec b) {
  vec ret(N - 1);
  REP(i, N - 1) { ret[i] = a[b[i]]; }
  return ret;
}

vec pw(vec n, ll m) {
  vec ret(N - 1);
  REP(i, N - 1) { ret[i] = i; }
  if (!m) {
    return ret;
  }
  ret = pw(n, m / 2);
  ret = mul(ret, ret);
  if (m & 1) {
    ret = mul(ret, n);
  }
  return ret;
}

int main() {
  ll x0, x1, x;
  cin >> N >> x0;
  x = x0;
  vec dif(N - 1);
  REP(i, N - 1) {
    cin >> x1;
    dif[i] = x1 - x0;
    swap(x0, x1);
  }
  cin >> M >> K;
  vec p(N - 1);
  REP(i, N - 1) { p[i] = i; }
  REP(i, M) {
    int a;
    cin >> a;
    swap(p[a - 2], p[a - 1]);
  }
  p = pw(p, K);
  dif = mul(dif, p);
  cout << x << endl;
  x1 = x;
  REP(i, N - 1) {
    x1 += dif[i];
    cout << x1 << endl;
  }
  return 0;
}
Problem p03953 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <vector>
#define SIZE 100005

using namespace std;
typedef long long int ll;

int A[SIZE];
int X[SIZE], T[SIZE];
bool use[SIZE];
int nd[SIZE];

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++)
    scanf("%d", &A[i]);
  for (int i = 0; i < n - 1; i++)
    X[i] = i;
  int m;
  ll K;
  scanf("%d %lld", &m, &K);
  for (int i = 0; i < m; i++) {
    int a;
    scanf("%d", &a);
    a--;
    swap(X[a - 1], X[a]);
  }
  for (int i = 0; i < n - 1; i++) {
    if (!use[i]) {
      int now = i;
      int len = 0;
      do {
        nd[len++] = now;
        now = X[now];
      } while (now != i);
      for (int j = 0; j < len; j++) {
        int to = (int)(K % len);
        to = nd[(j + to) % len];
        T[nd[j]] = to;
      }
    }
  }
  ll sum = A[0];
  for (int i = 0; i < n; i++) {
    printf("%lld\n", sum);
    int pos = T[i];
    sum += A[pos + 1] - A[pos];
  }
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <vector>
#define SIZE 100005

using namespace std;
typedef long long int ll;

int A[SIZE];
int X[SIZE], T[SIZE];
bool use[SIZE];
int nd[SIZE];

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++)
    scanf("%d", &A[i]);
  for (int i = 0; i < n - 1; i++)
    X[i] = i;
  int m;
  ll K;
  scanf("%d %lld", &m, &K);
  for (int i = 0; i < m; i++) {
    int a;
    scanf("%d", &a);
    a--;
    swap(X[a - 1], X[a]);
  }
  for (int i = 0; i < n - 1; i++) {
    if (!use[i]) {
      int now = i;
      int len = 0;
      do {
        use[now] = true;
        nd[len++] = now;
        now = X[now];
      } while (now != i);
      for (int j = 0; j < len; j++) {
        int to = (int)(K % len);
        to = nd[(j + to) % len];
        T[nd[j]] = to;
      }
    }
  }
  ll sum = A[0];
  for (int i = 0; i < n; i++) {
    printf("%lld\n", sum);
    int pos = T[i];
    sum += A[pos + 1] - A[pos];
  }
  return 0;
}
Problem p03953 (C++)

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

typedef long long i64;

vector<int> mul(const vector<int> &a, const vector<int> &b) {
  int n = SZ(a);
  vector<int> c(n);
  for (int i = 0; i < n; ++i) {
    c[i] = b[a[i]];
  }
  return c;
}

vector<int> Pow(vector<int> x, int64_t y) {
  int n = SZ(x);
  vector<int> ret(n);
  for (int i = 0; i < n; ++i) {
    ret[i] = i;
  }
  for (; y > 0; y /= 2) {
    if (y & 1) {
      ret = mul(ret, x);
    }
    x = mul(x, x);
  }
  return ret;
}

int main() {
#ifdef LOCAL_RUN
  freopen("task.in", "r", stdin);
  freopen("task.out", "w", stdout);
// freopen("task.err", "w", stderr);
#endif // ONLINE_JUDGE
  ios::sync_with_stdio(false);
  cin.tie(0);

  int n;
  cin >> n;

  vector<int> A(n);
  for (int i = 0; i < n; ++i) {
    cin >> A[i];
  }
  vector<int> dists(n - 1);
  for (int i = 0; i < n; ++i) {
    dists[i] = A[i + 1] - A[i];
  }

  vector<int> perm(n - 1);
  for (int i = 0; i < n - 1; ++i) {
    perm[i] = i;
  }

  int m;
  int64_t k;
  cin >> m >> k;

  while (m-- > 0) {
    int x;
    cin >> x;
    swap(perm[x - 2], perm[x - 1]);
  }
  perm = Pow(perm, k);

  vector<int> fdist(n - 1);
  for (int i = 0; i < n - 1; ++i) {
    fdist[i] = dists[perm[i]];
  }

  vector<int64_t> fans(n);
  fans[0] = A[0];
  for (int i = 1; i < n; ++i) {
    fans[i] = fans[i - 1] + fdist[i - 1];
  }

  for (int i = 0; i < n; ++i) {
    cout << fans[i] << '\n';
  }
}

Fixed submission:
#include <bits/stdc++.h>
#define SZ(x) ((int)(x).size())
using namespace std;

typedef long long i64;

vector<int> mul(const vector<int> &a, const vector<int> &b) {
  int n = SZ(a);
  vector<int> c(n);
  for (int i = 0; i < n; ++i) {
    c[i] = b[a[i]];
  }
  return c;
}

vector<int> Pow(vector<int> x, int64_t y) {
  int n = SZ(x);
  vector<int> ret(n);
  for (int i = 0; i < n; ++i) {
    ret[i] = i;
  }
  for (; y > 0; y /= 2) {
    if (y & 1) {
      ret = mul(ret, x);
    }
    x = mul(x, x);
  }
  return ret;
}

int main() {
#ifdef LOCAL_RUN
  freopen("task.in", "r", stdin);
  freopen("task.out", "w", stdout);
// freopen("task.err", "w", stderr);
#endif // ONLINE_JUDGE
  ios::sync_with_stdio(false);
  cin.tie(0);

  int n;
  cin >> n;

  vector<int> A(n);
  for (int i = 0; i < n; ++i) {
    cin >> A[i];
  }
  vector<int> dists(n - 1);
  for (int i = 0; i < n - 1; ++i) {
    dists[i] = A[i + 1] - A[i];
  }

  vector<int> perm(n - 1);
  for (int i = 0; i < n - 1; ++i) {
    perm[i] = i;
  }

  int m;
  int64_t k;
  cin >> m >> k;

  while (m-- > 0) {
    int x;
    cin >> x;
    swap(perm[x - 2], perm[x - 1]);
  }
  perm = Pow(perm, k);

  vector<int> fdist(n - 1);
  for (int i = 0; i < n - 1; ++i) {
    fdist[i] = dists[perm[i]];
  }

  vector<int64_t> fans(n);
  fans[0] = A[0];
  for (int i = 1; i < n; ++i) {
    fans[i] = fans[i - 1] + fdist[i - 1];
  }

  for (int i = 0; i < n; ++i) {
    cout << fans[i] << '\n';
  }
}