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

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define N 100005
using namespace std;
int n, m, x, y, q[N], b[N];
struct T {
  int x, y;
} a[N];
bool cmp(T a, T b) { return a.y > b.y; }
int to[N * 2], nxt[N * 2], fst[N], l;
void link(int x, int y) {
  to[++l] = y;
  nxt[l] = fst[x];
  fst[x] = l;
  to[++l] = x;
  nxt[l] = fst[y];
  fst[y] = l;
}
void biu() {
  puts("No");
  exit(0);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    scanf("%d%d", &x, &y);
    link(x, y);
  }
  for (int i = 1; i <= n; i++)
    b[i] = 233333333;
  scanf("%d", &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &x, &y);
    a[i] = (T){x, y};
  }
  sort(a + 1, a + m + 1, cmp);
  int l = 0, r = 1, f = 1;
  q[1] = a[1].x;
  b[a[1].x] = a[1].y;
  while (l < r) {
    l++;
    // cout<<q[l]<<endl;
    while (f < m && a[f + 1].y == b[q[l]]) {
      f++;
      q[++r] = a[f].x;
      if (b[a[f].x] != 233333333 && b[a[f].x] != a[f].y)
        biu();
      b[a[f].x] = a[f].y;
    }
    for (int i = fst[q[l]]; i; i = nxt[i])
      if (b[to[i]] == 233333333) {
        q[++r] = to[i];
        b[to[i]] = b[q[l]] - 1;
      }
  }
  for (int i = 1; i <= m; i++)
    if (b[a[i].x] != a[i].y)
      biu();
  for (int i = 1; i <= n; i++)
    for (int j = fst[i]; j; j = nxt[j])
      if (abs(b[i] - b[to[j]]) != 1)
        biu();
  puts("Yes");
  for (int i = 1; i <= n; i++)
    printf("%d\n", b[i]);
}

Fixed submission:
#include <bits/stdc++.h>
#define N 400005
using namespace std;
int n, m, x, y, q[N], b[N];
struct T {
  int x, y;
} a[N];
bool cmp(T a, T b) { return a.y > b.y; }
int to[N * 2], nxt[N * 2], fst[N], l;
void link(int x, int y) {
  to[++l] = y;
  nxt[l] = fst[x];
  fst[x] = l;
  to[++l] = x;
  nxt[l] = fst[y];
  fst[y] = l;
}
void biu() {
  puts("No");
  exit(0);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    scanf("%d%d", &x, &y);
    link(x, y);
  }
  for (int i = 1; i <= n; i++)
    b[i] = 233333333;
  scanf("%d", &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &x, &y);
    a[i] = (T){x, y};
  }
  sort(a + 1, a + m + 1, cmp);
  int l = 0, r = 1, f = 1;
  q[1] = a[1].x;
  b[a[1].x] = a[1].y;
  while (l < r) {
    l++;
    // cout<<q[l]<<endl;
    while (f < m && a[f + 1].y == b[q[l]]) {
      f++;
      q[++r] = a[f].x;
      if (b[a[f].x] != 233333333 && b[a[f].x] != a[f].y)
        biu();
      b[a[f].x] = a[f].y;
    }
    for (int i = fst[q[l]]; i; i = nxt[i])
      if (b[to[i]] == 233333333) {
        q[++r] = to[i];
        b[to[i]] = b[q[l]] - 1;
      }
  }
  for (int i = 1; i <= m; i++)
    if (b[a[i].x] != a[i].y)
      biu();
  for (int i = 1; i <= n; i++)
    for (int j = fst[i]; j; j = nxt[j])
      if (abs(b[i] - b[to[j]]) != 1)
        biu();
  puts("Yes");
  for (int i = 1; i <= n; i++)
    printf("%d\n", b[i]);
}
Problem p03949 (C++)

Buggy submission (status: Runtime Error):
#include <cmath>
#include <iostream>
#include <vector>
using namespace std;
typedef long long lli;
lli n;
vector<vector<lli>> g;
lli k;
vector<pair<lli, lli>> r;
vector<bool> vs;
void marge(pair<lli, lli> &a, pair<lli, lli> b) {
  a.first = max(a.first, b.first);
  a.second = min(a.second, b.second);
}
pair<lli, lli> dfs(lli x, pair<lli, lli> p, bool isOdd) {
  marge(r[x], p);
  vs[x] = true;
  // cout << x << ">" << endl;
  for (lli i = 0; i < g[x].size(); i++) {
    if (vs[g[x][i]])
      continue;
    marge(r[x], dfs(g[x][i], make_pair(r[x].first - 1, r[x].second + 1),
                    (isOdd + 1) % 2));
  }
  // cout << x << "<" << r[x].first << " " << r[x].second << endl;
  if (abs(r[x].first) % 2 != isOdd || r[x].first > r[x].second) {
    cout << "No" << endl;
    exit(1);
  }
  return make_pair(r[x].first - 1, r[x].second + 1);
}
int main(int argc, char const *argv[]) {
  cin >> n;
  g = vector<vector<lli>>(n + 1);
  for (lli i = 1; i < n; i++) {
    lli a, b;
    cin >> a >> b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  cin >> k;
  r = vector<pair<lli, lli>>(n + 1, make_pair((lli)-10000000, (lli)10000000));
  lli x;
  lli y;
  for (lli i = 0; i < k; i++) {
    lli v, p;
    cin >> v >> p;
    r[v] = make_pair(p, p);
    x = v, y = p;
  }
  vs = vector<bool>(n + 1);
  dfs(x, make_pair((lli)-10000000, (lli)10000000), y % 2);
  vs = vector<bool>(n + 1);
  dfs(x, make_pair((lli)-10000000, (lli)10000000), y % 2);
  cout << "Yes" << endl;
  for (lli i = 1; i <= n; i++)
    cout << r[i].second << endl;
  return 0;
}


Fixed submission:
#include <cmath>
#include <iostream>
#include <vector>
using namespace std;
typedef long long lli;
lli n;
vector<vector<lli>> g;
lli k;
vector<pair<lli, lli>> r;
vector<bool> vs;
void marge(pair<lli, lli> &a, pair<lli, lli> b) {
  a.first = max(a.first, b.first);
  a.second = min(a.second, b.second);
}
pair<lli, lli> dfs(lli x, pair<lli, lli> p, bool isOdd) {
  marge(r[x], p);
  vs[x] = true;
  // cout << x << ">" << endl;
  for (lli i = 0; i < g[x].size(); i++) {
    if (vs[g[x][i]])
      continue;
    marge(r[x], dfs(g[x][i], make_pair(r[x].first - 1, r[x].second + 1),
                    (isOdd + 1) % 2));
  }
  // cout << x << "<" << r[x].first << " " << r[x].second << endl;
  if (abs(r[x].first) % 2 != isOdd || r[x].first > r[x].second) {
    cout << "No" << endl;
    exit(0);
  }
  return make_pair(r[x].first - 1, r[x].second + 1);
}
int main(int argc, char const *argv[]) {
  cin >> n;
  g = vector<vector<lli>>(n + 1);
  for (lli i = 1; i < n; i++) {
    lli a, b;
    cin >> a >> b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  cin >> k;
  r = vector<pair<lli, lli>>(n + 1, make_pair((lli)-10000000, (lli)10000000));
  lli x;
  lli y;
  for (lli i = 0; i < k; i++) {
    lli v, p;
    cin >> v >> p;
    r[v] = make_pair(p, p);
    x = v, y = p;
  }
  vs = vector<bool>(n + 1);
  dfs(x, make_pair((lli)-10000000, (lli)10000000), y % 2);
  vs = vector<bool>(n + 1);
  dfs(x, make_pair((lli)-10000000, (lli)10000000), y % 2);
  cout << "Yes" << endl;
  for (lli i = 1; i <= n; i++)
    cout << r[i].second << endl;
  return 0;
}
Problem p03949 (Python)

Buggy submission (status: Runtime Error):
import sys


def dfs(v, parent, odd):
    hi = INF
    lo = -INF
    if fixed[v] != INF:
        if odd_even[v] != odd:
            print("No")
            exit()
        hi = lo = fixed[v]
    for u in links[v]:
        if u == parent:
            continue
        chi, clo = dfs(u, v, odd ^ 1)
        if hi < clo or chi < lo:
            print("No")
            exit()
        hi = min(hi, chi)
        lo = max(lo, clo)
    upper[v] = hi
    lower[v] = lo
    return hi + 1, lo - 1


def fill(v, parent, pp):
    if pp + 1 > upper[v]:
        assert pp - 1 >= lower[v]
        vp = fixed[v] = pp - 1
    else:
        vp = fixed[v] = pp + 1
    for u in links[v]:
        if u == parent:
            continue
        fill(u, v, vp)


inp = list(map(int, sys.stdin.buffer.read().split()))
n = inp[0]
links = [set() for _ in range(n)]
for a, b in zip(inp[1 : 2 * n - 1 : 2], inp[2 : 2 * n - 1 : 2]):
    a -= 1
    b -= 1
    links[a].add(b)
    links[b].add(a)
INF = 10**9
k = inp[2 * n - 1]
fixed = [INF] * n
odd_even = {}
fixed_v = 0
for v, p in zip(inp[2 * n :: 2], inp[2 * n + 1 :: 2]):
    v -= 1
    fixed[v] = p
    odd_even[v] = p % 2
    fixed_v = v

lower = [-INF] * n
upper = [INF] * n
dfs(fixed_v, -1, odd_even[fixed_v])
fill(fixed_v, -1, fixed[fixed_v] + 1)
print("Yes")
print("\n".join(map(str, fixed)))


Fixed submission:
import sys

sys.setrecursionlimit(10**7)


def dfs(v, parent, odd):
    hi = INF
    lo = -INF
    if fixed[v] != INF:
        if odd_even[v] != odd:
            print("No")
            exit()
        hi = lo = fixed[v]
    for u in links[v]:
        if u == parent:
            continue
        chi, clo = dfs(u, v, odd ^ 1)
        if hi < clo or chi < lo:
            print("No")
            exit()
        hi = min(hi, chi)
        lo = max(lo, clo)
    upper[v] = hi
    lower[v] = lo
    return hi + 1, lo - 1


def fill(v, parent, pp):
    if pp + 1 > upper[v]:
        assert pp - 1 >= lower[v]
        vp = fixed[v] = pp - 1
    else:
        vp = fixed[v] = pp + 1
    for u in links[v]:
        if u == parent:
            continue
        fill(u, v, vp)


inp = list(map(int, sys.stdin.buffer.read().split()))
n = inp[0]
links = [set() for _ in range(n)]
for a, b in zip(inp[1 : 2 * n - 1 : 2], inp[2 : 2 * n - 1 : 2]):
    a -= 1
    b -= 1
    links[a].add(b)
    links[b].add(a)
INF = 10**9
k = inp[2 * n - 1]
fixed = [INF] * n
odd_even = {}
fixed_v = 0
for v, p in zip(inp[2 * n :: 2], inp[2 * n + 1 :: 2]):
    v -= 1
    fixed[v] = p
    odd_even[v] = p % 2
    fixed_v = v

lower = [-INF] * n
upper = [INF] * n
dfs(fixed_v, -1, odd_even[fixed_v])
fill(fixed_v, -1, fixed[fixed_v] + 1)
print("Yes")
print("\n".join(map(str, fixed)))
Problem p03951 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define FLASH                                                                  \
  cin.tie(0);                                                                  \
  cout.tie(0);                                                                 \
  ios_base::sync_with_stdio(false);
#define pb push_back
#define int long long
#define fr(i, a, b) for (int i = a; i < b; i++)
#define mod 1000000007
#define FILEIO                                                                 \
  freopen("/home/aman/Desktop/Kachda/input.txt", "r", stdin);                  \
  freopen("/home/aman/Desktop/Kachda/output.txt", "w", stdout);

using namespace std;

signed main() {
#ifndef ONLINE_JUDGE
  FILEIO
#endif
  FLASH

  int n;
  string s, t;
  cin >> n >> s >> t;

  int ind = n - 1;

  fr(i, 0, n) {
    bool ok = 1;
    fr(j, 0, n - i) {
      if (s[i + j] != t[j])
        ok = 0;
    }
    if (ok == 1) {
      ind = i - 1;
      break;
    }
  }

  cout << n + ind + 1;
}

Fixed submission:
#include <bits/stdc++.h>
#define FLASH                                                                  \
  cin.tie(0);                                                                  \
  cout.tie(0);                                                                 \
  ios_base::sync_with_stdio(false);
#define pb push_back
#define int long long
#define fr(i, a, b) for (int i = a; i < b; i++)
#define mod 1000000007
#define FILEIO                                                                 \
  freopen("/home/aman/Desktop/Kachda/input.txt", "r", stdin);                  \
  freopen("/home/aman/Desktop/Kachda/output.txt", "w", stdout);

using namespace std;

signed main() {

  FLASH

  int n;
  string s, t;
  cin >> n >> s >> t;

  int ind = n - 1;

  fr(i, 0, n) {
    bool ok = 1;
    fr(j, 0, n - i) {
      if (s[i + j] != t[j])
        ok = 0;
    }
    if (ok == 1) {
      ind = i - 1;
      break;
    }
  }

  cout << n + ind + 1;
}
Problem p03951 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  string s, t;
  cin >> n >> s >> t;
  for (int i = n; i > 0; i++) {
    if (t.substr(0, i) == s.substr(n - i - 1, i)) {
      cout << n * 2 - i;
      return 0;
    }
  }
  cout << n * 2;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  string s, t;
  cin >> n >> s >> t;
  for (int i = n; i > 0; i--) {
    if (t.substr(0, i) == s.substr(n - i, i)) {
      cout << n * 2 - i;
      return 0;
    }
  }
  cout << n * 2;
}
Problem p03951 (Python)

Buggy submission (status: Runtime Error):
# -*- coding: utf-8 -*-

n = int(input())
s = list(input())
t = list(input())

for i in range(n):
    match = True
    for j in range(n):
        if i + j < n:
            if s[i + j] != t[j]:
                match = False
    if match:
        if i == 0:
            print(n)
        else:
            print(n + i)
        break
else:
    print(len(n * 2))


Fixed submission:
# -*- coding: utf-8 -*-

n = int(input())
s = list(input())
t = list(input())

for i in range(n):
    match = True
    for j in range(n):
        if i + j < n:
            if s[i + j] != t[j]:
                match = False
    if match:
        if i == 0:
            print(n)
        else:
            print(n + i)
        break
else:
    print(n * 2)
Problem p03951 (C++)

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

using namespace std;

int N;
int ans = 0;
bool is;
int main() {
  string s, t;
  cin >> N >> s >> t;
  int k = 0;
  for (int i = 0; i < s.length(); i++) {
    if (s[i] == t[k]) {
      ans++;
      k++;
    } else {
      ans = 0;
      k = 0;
      i--;
    }
  }
  cout << N * 2 - ans << endl;
}


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

using namespace std;

int N;
int ans = 0;
bool is;
int main() {
  string s, t;
  cin >> N >> s >> t;
  int k = 0;
  for (int i = 0; i < s.length(); i++) {
    if (s[i] == t[k]) {
      ans++;
      k++;
    } else if (ans > 0) {
      ans = 0;
      k = 0;
      i--;
    }
  }
  cout << N * 2 - ans << endl;
}
Problem p03951 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <climits>
#include <cmath>
#include <complex>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

class question {
public:
  int N;
  string s, t;
  void ans() {
    cin >> N >> s >> t;
    int i = 0;
    while (i < N) {
      while (i < N && s[i] != t[0])
        i++;
      int j = 1;
      while (i + j < N && s[i + j] == t[j])
        j++;
      if (i + j == N) {
        cout << 2 * N - j << "\n";
        return;
      }
    }
    cout << 2 * N << "\n";
  }
};

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

  question q;
  q.ans();

  return 0;
}

Fixed submission:
#include <algorithm>
#include <climits>
#include <cmath>
#include <complex>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

class question {
public:
  int N;
  string s, t;
  void ans() {
    cin >> N >> s >> t;
    REP(i, N) {
      if (s.substr(i) == t.substr(0, N - i)) {
        cout << N + i << "\n";
        return;
      }
    }
    cout << 2 * N << "\n";
  }
};

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

  question q;
  q.ans();

  return 0;
}
Problem p03951 (C++)

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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> pll;
typedef vector<bool> vb;
const ll oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORD(i, a, b) for (ll i = (b)-1; i >= (a); i--)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define has(c, i) ((c).find(i) != end(c))
#define DBGDO(X)                                                               \
  ({                                                                           \
    if (1)                                                                     \
      cerr << "DBGDO: " << (#X) << " = " << (X) << endl;                       \
  })

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

  ll n;
  string s, t;
  cin >> n >> s >> t;
  FOR(m, n, 2 * n + 1) {
    bool ok = true;
    string r(m, ' ');
    FOR(i, 0, n) r[i] = s[i];
    FOR(i, 0, n) if (r[i + m - n] != ' ' && r[i + m - n] != t[i]) ok = false;
    if (ok) {
      cout << m << endl;
      break;
    }
  }
  exit(1);
}


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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> pll;
typedef vector<bool> vb;
const ll oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORD(i, a, b) for (ll i = (b)-1; i >= (a); i--)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define has(c, i) ((c).find(i) != end(c))
#define DBGDO(X)                                                               \
  ({                                                                           \
    if (1)                                                                     \
      cerr << "DBGDO: " << (#X) << " = " << (X) << endl;                       \
  })

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

  ll n;
  string s, t;
  cin >> n >> s >> t;
  FOR(m, n, 2 * n + 1) {
    bool ok = true;
    string r(m, ' ');
    FOR(i, 0, n) r[i] = s[i];
    FOR(i, 0, n) if (r[i + m - n] != ' ' && r[i + m - n] != t[i]) ok = false;
    if (ok) {
      cout << m << endl;
      return 0;
    }
  }
  exit(1);
}
Problem p03951 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(), (obj).end()
const int INF = 99999;

bool check(string s, string t) {
  for (int i = 0; i < s.size(); i++) {
    if (s.at(i) != t.at(i))
      return false;
  }
  return true;
}
int main() {
  string s, t;
  int n, mn = 200;
  cin >> n;
  cin >> s >> t;
  for (int i = 0; i <= n; i++) {
    int sz = s.size();
    if (check(s, t)) {
      mn = min(mn, n * 2 - sz);
    }
    s.erase(s.begin());
  }
  if (mn == 200)
    mn = 2 * n;
  cout << mn << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(), (obj).end()
const int INF = 99999;

bool check(string s, string t) {
  for (int i = 0; i < s.size(); i++) {
    if (s.at(i) != t.at(i))
      return false;
  }
  return true;
}
int main() {
  string s, t;
  int n, mn = 200;
  cin >> n;
  cin >> s >> t;
  for (int i = 0; i < n; i++) {
    int sz = s.size();
    if (check(s, t)) {
      mn = min(mn, n * 2 - sz);
    }
    s.erase(s.begin());
  }
  if (mn == 200)
    mn = 2 * n;
  cout << mn << endl;
  return 0;
}
Problem p03951 (C++)

Buggy submission (status: Runtime Error):
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define REP(i, a, b) for (int i = a; i < (b); ++i)
#define all(x) (x).begin(), (x).end()
const int INF = 1000000007;
typedef long long ll;
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a, b); }
ll fac(ll a) { return a > 1 ? fac(a - 1) * a : 1; }
int solve() {
  int n, i;
  string s, t;
  scanf("%d%s%s", &n, &s, &t);
  for (i = n; i > 0; i--) {
    if (s.substr(n - i, i) == t.substr(0, i))
      break;
  }
  cout << 2 * n - i << endl;
  return 0;
}
int main() {
  // ios::sync_with_stdio(false);cin.tie(nullptr);
  // cout << fixed;cout << setprecision(16) << endl;
  solve();
  return 0;
}

Fixed submission:
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define REP(i, a, b) for (int i = a; i < (b); ++i)
#define all(x) (x).begin(), (x).end()
const int INF = 1000000007;
typedef long long ll;
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a, b); }
ll fac(ll a) { return a > 1 ? fac(a - 1) * a : 1; }
int solve() {
  int n, i;
  string s, t;
  cin >> n >> s >> t;
  for (i = n; i > 0; i--) {
    if (s.substr(n - i, i) == t.substr(0, i))
      break;
  }
  cout << 2 * n - i << endl;
  return 0;
}
int main() {
  // ios::sync_with_stdio(false);cin.tie(nullptr);
  // cout << fixed;cout << setprecision(16) << endl;
  solve();
  return 0;
}
Problem p03951 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
const int maxn = 200;
int n;
char s[maxn], t[maxn];
int f[maxn];
void getf() {
  for (int i = 1; i <= n; ++i) {
    int j = f[i - 1];
    while (j && t[j + 1] != t[i])
      j = f[j];
    if (t[j + 1] == t[i])
      ++j;
    f[i] = j;
  }
}
int match() {
  int j = 0;
  for (int i = 1; i <= n; ++i) {
    while (j && t[j + 1] != s[i])
      j = f[j];
    if (t[j + 1] == s[i])
      ++j;
  }
  return j;
}
int main() {
  scanf("%d%s%s", &n, s + 1, t + 1);
  getf();
  int ret = match();
  printf("%d\n", 2 * n - ret);
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
const int maxn = 200;
int n;
char s[maxn], t[maxn];
int f[maxn];
void getf() {
  for (int i = 2; i <= n; ++i) {
    int j = f[i - 1];
    while (j && t[j + 1] != t[i])
      j = f[j];
    if (t[j + 1] == t[i])
      ++j;
    f[i] = j;
  }
}
int match() {
  int j = 0;
  for (int i = 1; i <= n; ++i) {
    while (j && t[j + 1] != s[i])
      j = f[j];
    if (t[j + 1] == s[i])
      ++j;
  }
  return j;
}
int main() {
  scanf("%d%s%s", &n, s + 1, t + 1);
  getf();
  int ret = match();
  printf("%d\n", 2 * n - ret);
  return 0;
}
Problem p03951 (C++)

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

using namespace std;

#define foru(i, l, r) for (register int i = l; i <= r; i++)
#define ford(i, r, l) for (register int i = r; i >= l; i--)

int N;
char S[100002];
char T[100002];

int main() {
  scanf("%d%s%s", &N, S + 1, T + 1);
  for (int len = N; len >= 1; len--) {
    bool flag = true;
    for (int i = N - len + 1, j = 1; i <= N && flag; i++, j++)
      if (S[i] != T[j])
        flag = false;
    if (flag)
      return printf("%d\n", (N << 1) - len);
  }
  printf("%d\n", N << 1);
  return 0;
}


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

using namespace std;

#define foru(i, l, r) for (register int i = l; i <= r; i++)
#define ford(i, r, l) for (register int i = r; i >= l; i--)

int N;
char S[100002];
char T[100002];

int main() {
  scanf("%d%s%s", &N, S + 1, T + 1);
  for (int len = N; len >= 1; len--) {
    bool flag = true;
    for (int i = N - len + 1, j = 1; i <= N && flag; i++, j++)
      if (S[i] != T[j])
        flag = false;
    if (flag)
      return printf("%d\n", (N << 1) - len), 0;
  }
  printf("%d\n", N << 1);
  return 0;
}
Problem p03951 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
const long long mod = pow(10, 9) + 7;
const long long mod2 = 998244353;
const long long INF = 1LL << 60;
const int inf = pow(10, 9) + 7;
const string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const string abc = "abcdefghijklmnopqrstuvwxyz";
template <class T> bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int divCeil(int A, int B) { return (A + (B - 1)) / B; }
long long divCeil(long long A, int B) { return (A + (B - 1)) / B; }
long long divCeil(int A, long long B) { return (A + (B - 1)) / B; }
long long divCeil(long long A, long long B) { return (A + (B - 1)) / B; }

int main() {
  int N;
  string s, t;
  cin >> N >> s >> t;

  int ans = 2 * N;
  for (int i = 1; i <= N; i++) {
    if (s.substr(N - 1 - i, i) == t.substr(0, i)) {
      ans = 2 * N - i - 1;
    }
  }

  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
const long long mod = pow(10, 9) + 7;
const long long mod2 = 998244353;
const long long INF = 1LL << 60;
const int inf = pow(10, 9) + 7;
const string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const string abc = "abcdefghijklmnopqrstuvwxyz";
template <class T> bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int divCeil(int A, int B) { return (A + (B - 1)) / B; }
long long divCeil(long long A, int B) { return (A + (B - 1)) / B; }
long long divCeil(int A, long long B) { return (A + (B - 1)) / B; }
long long divCeil(long long A, long long B) { return (A + (B - 1)) / B; }

int main() {
  int N;
  string s, t;
  cin >> N >> s >> t;

  int ans = 2 * N;
  for (int i = 1; i <= N; i++) {
    if (s.substr(N - i, i) == t.substr(0, i)) {
      ans = 2 * N - i;
    }
  }

  cout << ans << endl;
}
Problem p03952 (C++)

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

using namespace std;

#define int long long
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<double, int> pdi;
typedef pair<ll, ll> pll;

#define S second
#define F first
#define kill(x) return (cout << x << endl, 0)
#define debug(x) cerr << #x << " : " << x << endl
#define ddebug(x, y)                                                           \
  cerr << #x << " : " << x << ", " << #y << " : " << y << endl
#define sz(s) (int)s.size()
#define sq(x) (x) * (x)
#define PB(x) push_back(x)
#define smax(x, y) (x) = max((x), (y))
#define smin(x, y) (x) = min((x), (y))
#define all(x) x.begin(), x.end()
#define SP fixed << setprecision(10)
#define UB upper_bound

const int MAXN = 100 * 1000 + 10;
int ans[MAXN];

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

  int n, x;
  cin >> n >> x;
  if (x == 1 || x == 2 * n - 1)
    kill("No");
  cout << "Yes" << endl;
  ans[n - 1] = x;
  ans[n] = 1;
  ans[n - 2] = 2 * n - 1;

  int a = 2;
  for (int i = 0; i < 2 * n - 1; i++) {
    if (a == x)
      a++;
    if (i <= n && i >= n - 2)
      continue;
    ans[i] = a;
    a++;
  }
  for (int i = 0; i < 2 * n - 1; i++)
    cout << ans[i] << "\n";

  return 0;
}


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

using namespace std;

#define int long long
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<double, int> pdi;
typedef pair<ll, ll> pll;

#define S second
#define F first
#define kill(x) return (cout << x << endl, 0)
#define debug(x) cerr << #x << " : " << x << endl
#define ddebug(x, y)                                                           \
  cerr << #x << " : " << x << ", " << #y << " : " << y << endl
#define sz(s) (int)s.size()
#define sq(x) (x) * (x)
#define PB(x) push_back(x)
#define smax(x, y) (x) = max((x), (y))
#define smin(x, y) (x) = min((x), (y))
#define all(x) x.begin(), x.end()
#define SP fixed << setprecision(10)
#define UB upper_bound

const int MAXN = 200 * 1000 + 10;
int ans[MAXN];

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

  int n, x;
  cin >> n >> x;
  if (x == 1 || x == 2 * n - 1)
    kill("No");
  cout << "Yes" << endl;
  ans[n - 1] = x;
  ans[n] = 1;
  ans[n - 2] = 2 * n - 1;

  int a = 2;
  for (int i = 0; i < 2 * n - 1; i++) {
    if (a == x)
      a++;
    if (i <= n && i >= n - 2)
      continue;
    ans[i] = a;
    a++;
  }
  for (int i = 0; i < 2 * n - 1; i++)
    cout << ans[i] << "\n";

  return 0;
}
Problem p03952 (C++)

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

int N, X;
int ans[100010] = {0};
bool used[100010] = {0};

int main() {
  scanf("%d%d", &N, &X);
  if (N == 2) {
    if (X == 2) {
      printf("Yes\n");
      printf("1\n2\n3\n");
    } else
      printf("No\n");
    return 0;
  }
  N = N * 2 - 1;
  if (X == 1 || X == N) {
    printf("No\n");
    return 0;
  }
  if (X == 2) {
    ans[N / 2] = X;
    ans[N / 2 - 1] = X + 1;
    ans[N / 2 + 1] = X - 1;
    ans[N / 2 + 2] = X + 2;
    used[X] = used[X - 1] = used[X + 1] = used[X + 2] = true;
  } else {
    ans[N / 2] = X;
    ans[N / 2 + 1] = X - 1;
    ans[N / 2 - 1] = X + 1;
    ans[N / 2 - 2] = X - 2;
    used[X] = used[X + 1] = used[X - 1] = used[X - 2] = true;
  }
  int cnt = 1;
  for (int i = 0; i < N; i++) {
    if (ans[i] == 0) {
      while (used[cnt])
        cnt++;
      ans[i] = cnt;
      used[cnt] = true;
    }
  }
  printf("Yes\n");
  for (int i = 0; i < N; i++)
    printf("%d\n", ans[i]);
  return 0;
}


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

int N, X;
int ans[200010] = {0};
bool used[200010] = {0};

int main() {
  scanf("%d%d", &N, &X);
  if (N == 2) {
    if (X == 2) {
      printf("Yes\n");
      printf("1\n2\n3\n");
    } else
      printf("No\n");
    return 0;
  }
  N = N * 2 - 1;
  if (X == 1 || X == N) {
    printf("No\n");
    return 0;
  }
  if (X == 2) {
    ans[N / 2] = X;
    ans[N / 2 - 1] = X + 1;
    ans[N / 2 + 1] = X - 1;
    ans[N / 2 + 2] = X + 2;
    used[X] = used[X - 1] = used[X + 1] = used[X + 2] = true;
  } else {
    ans[N / 2] = X;
    ans[N / 2 + 1] = X - 1;
    ans[N / 2 - 1] = X + 1;
    ans[N / 2 - 2] = X - 2;
    used[X] = used[X + 1] = used[X - 1] = used[X - 2] = true;
  }
  int cnt = 1;
  for (int i = 0; i < N; i++) {
    if (ans[i] == 0) {
      while (used[cnt])
        cnt++;
      ans[i] = cnt;
      used[cnt] = true;
    }
  }
  printf("Yes\n");
  for (int i = 0; i < N; i++)
    printf("%d\n", ans[i]);
  return 0;
}
Problem p03952 (C++)

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

using namespace std;

#define REP(i, n) for (ll i = 0; i < n; i++)
#define REPR(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define FORR(i, m, n) for (ll i = m; i >= n; i--)
#define REPO(i, n) for (ll i = 1; i <= n; i++)
#define ll long long
#define INF 1999999999
#define MINF -1999999999
#define INF64 1999999999999999999
#define ALL(n) n.begin(), n.end()
#define MOD 1000000007

ll n, x, s[110000];
bool used[110000];
queue<ll> q;
int main() {
  cin >> n >> x;
  if (n == 2) {
    if (x == 2) {
      cout << "Yes" << endl;
      REPO(i, 3) cout << i << endl;
    } else
      cout << "No" << endl;
  } else {
    if (x == 1 or x == 2 * n - 1)
      cout << "No" << endl;
    else {
      FOR(i, -2, 1) {
        s[n + i] = x + i + 1;
        used[x + i + 1] = true;
      }
      if (x != 2) {
        s[n + 1] = x - 2;
        used[x - 2] = true;
      } else {
        s[n - 3] = x + 2;
        used[x + 2] = true;
      }
      REPO(i, 2 * n - 1) {
        if (!used[i])
          q.push(i);
      }
      REP(i, 2 * n - 1) {
        if (s[i] == 0) {
          s[i] = q.front();
          q.pop();
        }
      }
      cout << "Yes" << endl;
      REP(i, n * 2 - 1) cout << s[i] << endl;
    }
  }
}


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

using namespace std;

#define REP(i, n) for (ll i = 0; i < n; i++)
#define REPR(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define FORR(i, m, n) for (ll i = m; i >= n; i--)
#define REPO(i, n) for (ll i = 1; i <= n; i++)
#define ll long long
#define INF 1999999999
#define MINF -1999999999
#define INF64 1999999999999999999
#define ALL(n) n.begin(), n.end()
#define MOD 1000000007

ll n, x, s[310000];
bool used[310000];
queue<ll> q;
int main() {
  cin >> n >> x;
  if (n == 2) {
    if (x == 2) {
      cout << "Yes" << endl;
      REPO(i, 3) cout << i << endl;
    } else
      cout << "No" << endl;
  } else {
    if (x == 1 or x == 2 * n - 1)
      cout << "No" << endl;
    else {
      FOR(i, -2, 1) {
        s[n + i] = x + i + 1;
        used[x + i + 1] = true;
      }
      if (x != 2) {
        s[n + 1] = x - 2;
        used[x - 2] = true;
      } else {
        s[n - 3] = x + 2;
        used[x + 2] = true;
      }
      REPO(i, 2 * n - 1) {
        if (!used[i])
          q.push(i);
      }
      REP(i, 2 * n - 1) {
        if (s[i] == 0) {
          s[i] = q.front();
          q.pop();
        }
      }
      cout << "Yes" << endl;
      REP(i, n * 2 - 1) cout << s[i] << endl;
    }
  }
}
Problem p03952 (C++)

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

using namespace std;
typedef long long ll;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}

int 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);
  for (int i = 0; i < (int)(2 * N - 1); ++i)
    a[i] = i + 1;
  if (N != 2) {
    swap(a[N - 2], a[x - 2]);
    swap(a[N - 1], a[x - 1]);
    swap(a[N], a[x]);
    swap(a[N + 1], a[x - 3]);
  }

  cout << "Yes" << endl;
  for (int i = 0; i < (int)(2 * N - 1); ++i)
    cout << a[i] << endl;
  return 0;
}


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

using namespace std;
typedef long long ll;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}

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

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

  if (N == 2) {
    cout << "Yes" << endl;
    cout << "1 2 3" << endl;
    return 0;
  }

  vector<int> a(2 * N - 1, 0);
  vector<bool> used(2 * N, false);

  used[x] = true;
  used[x - 1] = true;
  used[x + 1] = true;
  if (x == 2) {
    a[N - 2] = x + 1;
    a[N - 1] = x;
    a[N] = x - 1;
    a[N + 1] = x + 2;
    used[x + 2] = true;
  } else {
    a[N - 2] = x - 1;
    a[N - 1] = x;
    a[N] = x + 1;
    a[N + 1] = x - 2;
    used[x - 2] = true;
  }

  int j = 1;
  for (int i = 0; i < (int)(2 * N - 1); ++i) {
    if (a[i] != 0)
      continue;
    while (used[j])
      ++j;
    a[i] = j++;
  }

  cout << "Yes" << endl;
  for (int i = 0; i < (int)(2 * N - 1); ++i)
    cout << a[i] << endl;
  return 0;
}
Problem p03952 (C++)

Buggy submission (status: Runtime Error):
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template <typename T> bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T> bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
#define itn int
#define fi first
#define se second
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define rrep1(i, n) for (int i = (int)(n); i >= 1; i--)
#define all(vec) vec.begin(), vec.end()
#define sortt(vec) sort((vec).begin(), (vec).end())
#define rsort(vec) sort((vec).rbegin(), (vec).rend())
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef tuple<ll, ll, ll> tlll;
typedef tuple<int, int, int> tiii;
const ll mod = 1e9 + 7;
const int inf = 2e9;
const ll lnf = 9e18;

int main() {
  itn n, x;
  cin >> n >> x;
  x--;
  if (x == 0 || x == 2 * n - 2) {
    cout << "No" << endl;
    return 0;
  }
  vector<itn> ans(2 * n - 1);
  rep(i, 2 * n - 1) { ans[i] = i; }
  if (x == n - 1) {
    cout << "Yes" << endl;
    rep(i, ans.size()) cout << ans[i] + 1 << endl;
    return 0;
  } else if (x < n - 1) {
    swap(ans[0], ans[n - 1]);
    swap(ans[x], ans[n]);
  } else {
    swap(ans[2 * n - 1], ans[n - 1]);
    swap(ans[x], ans[n - 2]);
  }
  cout << "Yes" << endl;
  rep(i, ans.size()) cout << ans[i] + 1 << endl;
}

Fixed submission:
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template <typename T> bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T> bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
#define itn int
#define fi first
#define se second
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define rrep1(i, n) for (int i = (int)(n); i >= 1; i--)
#define all(vec) vec.begin(), vec.end()
#define sortt(vec) sort((vec).begin(), (vec).end())
#define rsort(vec) sort((vec).rbegin(), (vec).rend())
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef tuple<ll, ll, ll> tlll;
typedef tuple<int, int, int> tiii;
const ll mod = 1e9 + 7;
const int inf = 2e9;
const ll lnf = 9e18;

int main() {
  itn n, x;
  cin >> n >> x;
  x--;
  if (x == 0 || x == 2 * n - 2) {
    cout << "No" << endl;
    return 0;
  }
  vector<itn> ans(2 * n - 1);
  rep(i, 2 * n - 1) { ans[i] = i; }
  if (x == n - 1) {
    cout << "Yes" << endl;
    rep(i, ans.size()) cout << ans[i] + 1 << endl;
    return 0;
  } else if (x < n - 1) {
    swap(ans[0], ans[n - 1]);
    swap(ans[x], ans[n]);
  } else {
    swap(ans[2 * n - 2], ans[n - 1]);
    swap(ans[x], ans[n - 2]);
  }
  cout << "Yes" << endl;
  rep(i, ans.size()) cout << ans[i] + 1 << endl;
}
Problem p03952 (C++)

Buggy submission (status: Runtime Error):
/*
 * 16-10-29_AGC006_B.cpp
 *
 *  Created on: 2016/10/29
 *      Author: ryoma
 */

#include <algorithm>
#include <iostream>

using namespace std;

int main() {
  int N, x, a[20001];
  cin >> N >> x;
  if (x == 1 || x == 2 * N - 1) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
    if (N == 2) {
      for (int i = 1; i <= 2 * N - 1; i++)
        cout << i << endl;
    } else {
      a[N - 1] = x;
      int j = 1, NN = 2 * N - 1;
      if (x == 2)
        for (int i = 1; i <= N; i++) {
          a[(N - i + NN - 1) % NN] = (x + i * j + NN - 1) % NN + 1;
          a[(N + i - 1) % NN] = (x - i * j + NN - 1) % NN + 1;
          j *= -1;
        }
      else
        for (int i = 1; i <= N; i++) {
          a[(N - i + NN - 1) % NN] = (x - i * j + NN - 1) % NN + 1;
          a[(N + i - 1) % NN] = (x + i * j + NN - 1) % NN + 1;
          j *= -1;
        }
      for (int i = 0; i < 2 * N - 1; i++)
        cout << a[i] << endl;
    }
  }
  return 0;
}


Fixed submission:
/*
 * 16-10-29_AGC006_B.cpp
 *
 *  Created on: 2016/10/29
 *      Author: ryoma
 */

#include <algorithm>
#include <iostream>

using namespace std;

int main() {
  int N, x, a[200001];
  cin >> N >> x;
  if (x == 1 || x == 2 * N - 1) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
    if (N == 2) {
      for (int i = 1; i <= 2 * N - 1; i++)
        cout << i << endl;
    } else {
      a[N - 1] = x;
      int j = 1, NN = 2 * N - 1;
      if (x == 2)
        for (int i = 1; i <= N; i++) {
          a[(N - i + NN - 1) % NN] = (x + i * j + NN - 1) % NN + 1;
          a[(N + i - 1) % NN] = (x - i * j + NN - 1) % NN + 1;
          j *= -1;
        }
      else
        for (int i = 1; i <= N; i++) {
          a[(N - i + NN - 1) % NN] = (x - i * j + NN - 1) % NN + 1;
          a[(N + i - 1) % NN] = (x + i * j + NN - 1) % NN + 1;
          j *= -1;
        }
      for (int i = 0; i < 2 * N - 1; i++)
        cout << a[i] << endl;
    }
  }
  return 0;
}
Problem p03952 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;

int main() {
  int N, x;
  while (cin >> N >> x) {
    int M = 2 * N - 1;
    if (x == 1 || x == M) {
      cout << "No" << endl;
      continue;
    }
    --x;
    vector<int> ans(M);
    ans[N - 2] = x + 1;
    ans[N - 1] = x;
    ans[N] = x - 1;
    for (int i = 2; i <= N; i++) {
      ans[N - 1 - i] = (x - i + M) % M;
      ans[N - 1 + i] = (x + i) % M;
    }
    cout << "Yes" << endl;
    for (int x : ans) {
      cout << x + 1 << endl;
    }
  }
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;

int main() {
  int N, x;
  while (cin >> N >> x) {
    int M = 2 * N - 1;
    if (x == 1 || x == M) {
      cout << "No" << endl;
      continue;
    }
    --x;
    vector<int> ans(M);
    ans[N - 2] = x + 1;
    ans[N - 1] = x;
    ans[N] = x - 1;
    for (int i = 2; i < N; i++) {
      ans[N - 1 - i] = (x - i + M) % M;
      ans[N - 1 + i] = (x + i) % M;
    }
    cout << "Yes" << endl;
    for (int x : ans) {
      cout << x + 1 << endl;
    }
  }
  return 0;
}
Problem p03952 (C++)

Buggy submission (status: Runtime Error):
// 2017-11-4
// miaomiao
//
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>

using namespace std;

#define For(i, a, b) for (int i = (a); i <= (int)(b); ++i)
#define N (100000 + 5)

int a[N];
bool use[N];

int main() {
  int x, n;
  scanf("%d%d", &n, &x);

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

  puts("Yes");

  a[n - 1] = x;
  if (x == 2) {
    a[n] = x - 1;

    int p = 0;
    For(i, 1, n * 2 - 1) {
      if (i == n - 1 || i == n)
        continue;

      ++p;
      if (p == x - 1)
        p = x + 1;
      a[i] = p;
    }
  } else {
    a[n] = x + 1;
    a[n - 2] = x - 1;
    a[n + 1] = x - 2;
    use[x - 1] = use[x] = use[x + 1] = use[x - 2] = true;

    int p = 1;
    For(i, 1, n * 2 - 1) {
      if (i >= n - 2 && i <= n + 1)
        continue;

      while (use[p])
        ++p;
      use[p] = true;
      a[i] = p;
    }
  }

  For(i, 1, n * 2 - 1) printf("%d\n", a[i]);

  return 0;
}

Fixed submission:
// 2017-11-4
// miaomiao
//
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>

using namespace std;

#define For(i, a, b) for (int i = (a); i <= (int)(b); ++i)
#define N (200000 + 5)

int a[N];
bool use[N];

int main() {
  int x, n;
  scanf("%d%d", &n, &x);

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

  puts("Yes");

  a[n - 1] = x;
  if (x == 2) {
    a[n] = x - 1;

    int p = 0;
    For(i, 1, n * 2 - 1) {
      if (i == n - 1 || i == n)
        continue;

      ++p;
      if (p == x - 1)
        p = x + 1;
      a[i] = p;
    }
  } else {
    a[n] = x + 1;
    a[n - 2] = x - 1;
    a[n + 1] = x - 2;
    use[x - 1] = use[x] = use[x + 1] = use[x - 2] = true;

    int p = 1;
    For(i, 1, n * 2 - 1) {
      if (i >= n - 2 && i <= n + 1)
        continue;

      while (use[p])
        ++p;
      use[p] = true;
      a[i] = p;
    }
  }

  For(i, 1, n * 2 - 1) printf("%d\n", a[i]);

  return 0;
}
Problem p03952 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define int long long

#define rep(i, n) for (int i = 0; i < (n); i++)
#define itrep(i, a) for (auto i = (a).begin(); i != (a).end(); i++)
#define REP(i, a, n) for (int i = (a); i <= (n); i++)
#define all(a) (a).begin(), (a).end()

using namespace std;

bool inserted[100010];

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

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

  cout << "Yes" << endl;

  deque<int> deq;

  deq.push_back(x);
  deq.push_back(x - 1);
  deq.push_front(x + 1);

  inserted[x] = true;
  inserted[x - 1] = true;
  inserted[x + 1] = true;

  if (N > 2) {
    if (x == 2) {
      deq.push_back(4);
      inserted[4] = true;
    } else {
      deq.push_front(x - 2);
      inserted[x - 2] = true;
    }

    bool front = true;
    REP(i, 1, 2 * N - 1) {
      if (inserted[i])
        continue;
      if (front)
        deq.push_front(i);
      else
        deq.push_back(i);
      front = !front;
    }
  }

  for (int num : deq)
    cout << num << endl;

  return 0;
}


Fixed submission:
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define int long long

#define rep(i, n) for (int i = 0; i < (n); i++)
#define itrep(i, a) for (auto i = (a).begin(); i != (a).end(); i++)
#define REP(i, a, n) for (int i = (a); i <= (n); i++)
#define all(a) (a).begin(), (a).end()

using namespace std;

bool inserted[200010];

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

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

  cout << "Yes" << endl;

  deque<int> deq;

  deq.push_back(x);
  deq.push_back(x - 1);
  deq.push_front(x + 1);

  inserted[x] = true;
  inserted[x - 1] = true;
  inserted[x + 1] = true;

  if (N > 2) {
    if (x == 2) {
      deq.push_back(4);
      inserted[4] = true;
    } else {
      deq.push_front(x - 2);
      inserted[x - 2] = true;
    }

    bool front = true;
    REP(i, 1, 2 * N - 1) {
      if (inserted[i])
        continue;
      if (front)
        deq.push_front(i);
      else
        deq.push_back(i);
      front = !front;
    }
  }

  for (int num : deq)
    cout << num << endl;

  return 0;
}
Problem p03952 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define INF (1 << 30)
#define MOD 1000000007
#define l_ength size
using ll = long long;
using namespace std;

const int bound = 100100;
bool ok[bound];
bool flag = false;

int main() {
  int n, x;
  cin >> n >> x;
  if (n == 2) {
    if (x == 1 || x == 3) {
      cout << "No" << endl;
    } else {
      cout << "Yes" << endl << 1 << endl << 2 << endl << 3 << endl;
    }
    return 0;
  }
  if (1 < x && x < 2 * n - 1) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
    return 0;
  }
  fill_n(ok, bound, true);
  if (x == 2 * n - 2)
    flag = true;
  if (flag) {
    ok[x - 2] = ok[x] = ok[x + 1] = ok[x - 1] = false;
  } else {
    ok[x + 2] = ok[x] = ok[x - 1] = ok[x + 1] = false;
  }
  vector<int> a;
  for (int k = 1; k <= 2 * n - 1; ++k) {
    if (ok[k])
      a.push_back(k);
  }
  auto itr = a.begin();
  for (int k = 1; k <= 2 * n - 1; ++k) {
    if (k == n - 1) {
      cout << ((flag) ? x - 2 : x + 2) << endl;
    } else if (k == n) {
      cout << x << endl;
    } else if (k == n + 1) {
      cout << ((flag) ? x + 1 : x - 1) << endl;
    } else if (k == n + 2) {
      cout << ((flag) ? x - 1 : x + 1) << endl;
    } else {
      cout << (*itr) << endl;
      ++itr;
    }
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define INF (1 << 30)
#define MOD 1000000007
#define l_ength size
using ll = long long;
using namespace std;

const int bound = 314159;
bool ok[bound];
bool flag = false;

int main() {
  int n, x;
  cin >> n >> x;
  if (n == 2) {
    if (x == 1 || x == 3) {
      cout << "No" << endl;
    } else {
      cout << "Yes" << endl << 1 << endl << 2 << endl << 3 << endl;
    }
    return 0;
  }
  if (1 < x && x < 2 * n - 1) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
    return 0;
  }
  fill_n(ok, bound, true);
  if (x == 2 * n - 2)
    flag = true;
  if (flag) {
    ok[x - 2] = ok[x] = ok[x + 1] = ok[x - 1] = false;
  } else {
    ok[x + 2] = ok[x] = ok[x - 1] = ok[x + 1] = false;
  }
  vector<int> a;
  for (int k = 1; k <= 2 * n - 1; ++k) {
    if (ok[k])
      a.push_back(k);
  }
  auto itr = a.begin();
  for (int k = 1; k <= 2 * n - 1; ++k) {
    if (k == n - 1) {
      cout << ((flag) ? x - 2 : x + 2) << endl;
    } else if (k == n) {
      cout << x << endl;
    } else if (k == n + 1) {
      cout << ((flag) ? x + 1 : x - 1) << endl;
    } else if (k == n + 2) {
      cout << ((flag) ? x - 1 : x + 1) << endl;
    } else {
      cout << (*itr) << endl;
      ++itr;
    }
  }
  return 0;
}