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

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int a[N], b[N];
int n;
bool check(int x) {
  int L = 1, R = 2 * n - 1;
  for (int i = 1; i <= 2 * n - 1; i++)
    b[i] = (a[i] >= x);
  for (int i = 1; i < n; i++)
    if (b[i] == b[i + 1])
      L = i + 1;
  for (int i = 2 * n - 1; i > n; i--)
    if (b[i] == b[i - 1])
      R = i - 1;
  if (n - L < R - n)
    return (b[L] == 1);
  else
    return (b[R] == 1);
}
int main() {
  cin >> n;
  for (int i = 1; i <= 2 * n - 1; i++)
    cin >> a[i];
  int low = 1, high = 2 * n - 1, ans = 0;
  while (low <= high) {
    int mid = (low + high) / 2;
    if (check(mid)) {
      low = mid + 1;
      ans = mid;
    } else
      high = mid - 1;
  }
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
int a[N], b[N];
int n;
bool check(int x) {
  int L = 1, R = 2 * n - 1;
  for (int i = 1; i <= 2 * n - 1; i++)
    b[i] = (a[i] >= x);
  for (int i = 1; i < n; i++)
    if (b[i] == b[i + 1])
      L = i + 1;
  for (int i = 2 * n - 1; i > n; i--)
    if (b[i] == b[i - 1])
      R = i - 1;
  if (n - L < R - n)
    return (b[L] == 1);
  else
    return (b[R] == 1);
}
int main() {
  cin >> n;
  for (int i = 1; i <= 2 * n - 1; i++)
    cin >> a[i];
  int low = 1, high = 2 * n - 1, ans = 0;
  while (low <= high) {
    int mid = (low + high) / 2;
    if (check(mid)) {
      low = mid + 1;
      ans = mid;
    } else
      high = mid - 1;
  }
  cout << ans << endl;
  return 0;
}
Problem p03954 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <map>
#include <set>
#include <vector>

using namespace std;

#define mp make_pair
#define pb push_back
#define x first
#define y second

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

int a[100010], b[100010], c[100010][3];

int main() {
  int n;
  scanf("%d", &n);
  n = 2 * n - 1;
  for (int i = 1; i <= n; i++)
    scanf("%d", &a[i]);
  int l = 1, r = n;
  while (l <= r) {
    int mid = (l + r) >> 1;
    for (int i = 1; i <= n; i++)
      if (a[i] <= mid)
        b[i] = 1;
      else
        b[i] = 0;
    int l0 = 1, m = 0;
    for (int i = 2; i <= n + 1; i++)
      if (i == n + 1 || b[i] != b[i - 1]) {
        if (i - l0 > 1) {
          c[++m][0] = l0;
          c[m][1] = i - 1;
          c[m][2] = b[l0];
        }
        l0 = i;
      }
    int t;
    if (!m)
      t = b[(n + 1) / 2] ^ (n / 2 % 2);
    else {
      int ma = n, x = (n + 1) / 2;
      for (int i = 1; i <= m; i++) {
        if (abs(c[i][0] - x) < ma) {
          ma = abs(c[i][0] - x);
          t = c[i][2];
        }
        if (abs(c[i][1] - x) < ma) {
          ma = abs(c[i][1] - x);
          t = c[i][2];
        }
      }
    }
    if (t)
      r = mid - 1;
    else
      l = mid + 1;
  }
  printf("%d\n", l);
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <map>
#include <set>
#include <vector>

using namespace std;

#define mp make_pair
#define pb push_back
#define x first
#define y second

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

int a[200010], b[200010], c[200010][3];

int main() {
  int n;
  scanf("%d", &n);
  n = 2 * n - 1;
  for (int i = 1; i <= n; i++)
    scanf("%d", &a[i]);
  int l = 1, r = n;
  while (l <= r) {
    int mid = (l + r) >> 1;
    for (int i = 1; i <= n; i++)
      if (a[i] <= mid)
        b[i] = 1;
      else
        b[i] = 0;
    int l0 = 1, m = 0;
    for (int i = 2; i <= n + 1; i++)
      if (i == n + 1 || b[i] != b[i - 1]) {
        if (i - l0 > 1) {
          c[++m][0] = l0;
          c[m][1] = i - 1;
          c[m][2] = b[l0];
        }
        l0 = i;
      }
    int t;
    if (!m)
      t = b[(n + 1) / 2] ^ (n / 2 % 2);
    else {
      int ma = n, x = (n + 1) / 2;
      for (int i = 1; i <= m; i++) {
        if (abs(c[i][0] - x) < ma) {
          ma = abs(c[i][0] - x);
          t = c[i][2];
        }
        if (abs(c[i][1] - x) < ma) {
          ma = abs(c[i][1] - x);
          t = c[i][2];
        }
      }
    }
    if (t)
      r = mid - 1;
    else
      l = mid + 1;
  }
  printf("%d\n", l);
  return 0;
}
Problem p03954 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;
typedef long long int ll;
static const int MAX_N = 100000;
static const int MAX_A = 2 * MAX_N - 1;

int N, a[2 * MAX_N - 1];

bool def(bool b[]) {
  int s = 0, t = 0;
  while (N - s - 1 > 0 && b[N - s - 1] != b[N - s - 2])
    s++;
  while (t + N - 1 < 2 * N - 1 && b[N + t - 1] != b[N + t])
    t++;
  if (min(s, t) >= N - 1)
    return ((N % 2) ? b[N - 1] : !b[N - 1]);
  else if (t < s)
    return b[t + N - 1];
  else
    return b[N - s - 1];
}

int main() {
  cin >> N;
  for (int i = 0; i < 2 * N - 1; i++)
    cin >> a[i];

  int lb = -1, ub = MAX_A + 1;
  while (ub - lb > 1) {
    int mid = lb + (ub - lb) / 2;
    bool b[MAX_N];
    for (int i = 0; i < 2 * N - 1; i++) {
      if (a[i] >= mid)
        b[i] = true;
      else
        b[i] = false;
    }
    if (def(b))
      lb = mid;
    else
      ub = mid;
  }
  cout << lb << endl;
  return 0;
}

Fixed submission:
#include <iostream>
using namespace std;
typedef long long int ll;
static const int MAX_N = 100000;
static const int MAX_A = 2 * MAX_N - 1;

int N, a[2 * MAX_N - 1];

bool def(bool b[]) {
  int s = 0, t = 0;
  while (N - s - 1 > 0 && b[N - s - 1] != b[N - s - 2])
    s++;
  while (t + N - 1 < 2 * N - 1 && b[N + t - 1] != b[N + t])
    t++;
  if (min(s, t) >= N - 1)
    return ((N % 2) ? b[N - 1] : !b[N - 1]);
  else if (t < s)
    return b[t + N - 1];
  else
    return b[N - s - 1];
}

int main() {
  cin >> N;
  for (int i = 0; i < 2 * N - 1; i++)
    cin >> a[i];

  int lb = -1, ub = MAX_A + 1;
  while (ub - lb > 1) {
    int mid = lb + (ub - lb) / 2;
    bool b[2 * MAX_N - 1];
    for (int i = 0; i < 2 * N - 1; i++) {
      if (a[i] >= mid)
        b[i] = true;
      else
        b[i] = false;
    }
    if (def(b))
      lb = mid;
    else
      ub = mid;
  }
  cout << lb << endl;
  return 0;
}
Problem p03954 (C++)

Buggy submission (status: Runtime Error):
/*******************************
Author:galaxy yr
LANG:C++
Created Time:2019/07/23 09:40:42
*******************************/
#include <cstdio>
#include <iostream>
using namespace std;
const int maxn = 1e5 + 10;
int n, a[maxn], l, r, mid, ans;
bool small(int i, int j, int k) { return a[i] <= k and a[j] <= k; }
bool big(int i, int j, int k) { return a[i] > k and a[j] > k; }
int check(int k) {
  for (int i = 0; i < n - 1; i++) {
    if (big(n + i, n + i + 1, k) or big(n - i, n - i - 1, k))
      return 0;
    if (small(n + i, n + i + 1, k) or small(n - i, n - i - 1, k))
      return 1;
  }
  return small(1, 1, k);
}
int main() {
  // freopen("triangle.in","r",stdin);
  // freopen("triangle.out","w",stdout);
  cin >> n;
  for (int i = 1; i <= 2 * n - 1; i++)
    cin >> a[i];
  l = 1, r = 2 * n - 1;
  while (l <= r) {
    mid = (l + r) >> 1;
    if (check(mid))
      r = mid - 1, ans = mid;
    else
      l = mid + 1;
  }
  cout << ans << endl;
  return 0;
}


Fixed submission:
/*******************************
Author:galaxy yr
LANG:C++
Created Time:2019/07/23 09:40:42
*******************************/
#include <cstdio>
#include <iostream>
using namespace std;
const int maxn = 2e5 + 10;
int n, a[maxn], l, r, mid, ans;
bool small(int i, int j, int k) { return a[i] <= k and a[j] <= k; }
bool big(int i, int j, int k) { return a[i] > k and a[j] > k; }
int check(int k) {
  for (int i = 0; i < n - 1; i++) {
    if (big(n + i, n + i + 1, k) or big(n - i, n - i - 1, k))
      return 0;
    if (small(n + i, n + i + 1, k) or small(n - i, n - i - 1, k))
      return 1;
  }
  return small(1, 1, k);
}
int main() {
  // freopen("triangle.in","r",stdin);
  // freopen("triangle.out","w",stdout);
  cin >> n;
  for (int i = 1; i <= 2 * n - 1; i++)
    cin >> a[i];
  l = 1, r = 2 * n - 1;
  while (l <= r) {
    mid = (l + r) >> 1;
    if (check(mid))
      r = mid - 1, ans = mid;
    else
      l = mid + 1;
  }
  cout << ans << endl;
  return 0;
}
Problem p03954 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 1;
int n, a[N], l, r;
int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-')
      f = -f;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = x * 10 + ch - 48;
    ch = getchar();
  }
  return x * f;
}
int c1(int x, int y, int z) { return x > z && y > z; }
int c2(int x, int y, int z) { return x <= z && y <= z; }
int check(int k) {
  int p = n >> 1;
  ++p;
  for (int i = 0; i < (n >> 1); i++) {
    if (c1(a[p + i], a[p + i + 1], k) || c1(a[p - i], a[p - i - 1], k))
      return 0;
    if (c2(a[p + i], a[p + i + 1], k) || c2(a[p - i], a[p - i - 1], k))
      return 1;
  }
  return a[1] <= k;
}
int main() {
  n = read();
  n = n << 1;
  n--;
  for (int i = 1; i <= n; i++)
    a[i] = read(), r = max(r, a[i]);
  while (l < r) {
    int mid = l + r >> 1;
    if (check(mid))
      r = mid;
    else
      l = mid + 1;
  }
  printf("%d\n", r);
  return 0;
}
/*
  5
  1 9 2 3 6
*/


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 1;
int n, a[N], l, r;
int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-')
      f = -f;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = x * 10 + ch - 48;
    ch = getchar();
  }
  return x * f;
}
int c1(int x, int y, int z) { return x > z && y > z; }
int c2(int x, int y, int z) { return x <= z && y <= z; }
int check(int k) {
  int p = n >> 1;
  ++p;
  for (int i = 0; i < (n >> 1); i++) {
    if (c1(a[p + i], a[p + i + 1], k) || c1(a[p - i], a[p - i - 1], k))
      return 0;
    if (c2(a[p + i], a[p + i + 1], k) || c2(a[p - i], a[p - i - 1], k))
      return 1;
  }
  return a[1] <= k;
}
int main() {
  n = read();
  n = n << 1;
  n--;
  for (int i = 1; i <= n; i++)
    a[i] = read(), r = max(r, a[i]);
  while (l < r) {
    int mid = l + r >> 1;
    if (check(mid))
      r = mid;
    else
      l = mid + 1;
  }
  printf("%d\n", r);
  return 0;
}
/*
  5
  1 9 2 3 6
*/
Problem p03954 (C++)

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

typedef long long ll;
typedef unsigned long long ull;

int N;
int bottom[100000];

bool top(int x) {
  for (int i = 1; i < N; i++) {
    if ((bottom[N - 1 + i] >= x) == (bottom[N - 1 + i - 1] >= x))
      return bottom[N - 1 + i] >= x;
    if ((bottom[N - 1 - i] >= x) == (bottom[N - 1 - i + 1] >= x))
      return bottom[N - 1 - i] >= x;
  }
  return (bottom[0] >= x);
}

int main() {
  cin >> N;
  for (int i = 0; i < 2 * N - 1; i++) {
    cin >> bottom[i];
  }
  int l = 1, r = 2 * N;
  while (r - l > 1) {
    int m = (l + r) / 2;
    if (top(m))
      l = m;
    else
      r = m;
  }
  cout << l << endl;

  return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;

int N;
int bottom[200001];

bool top(int x) {
  for (int i = 1; i < N; i++) {
    if ((bottom[N - 1 + i] >= x) == (bottom[N - 1 + i - 1] >= x))
      return bottom[N - 1 + i] >= x;
    if ((bottom[N - 1 - i] >= x) == (bottom[N - 1 - i + 1] >= x))
      return bottom[N - 1 - i] >= x;
  }
  return (bottom[0] >= x);
}

int main() {
  cin >> N;
  for (int i = 0; i < 2 * N - 1; i++) {
    cin >> bottom[i];
  }
  int l = 1, r = 2 * N;
  while (r - l > 1) {
    int m = (l + r) / 2;
    if (top(m))
      l = m;
    else
      r = m;
  }
  cout << l << endl;

  return 0;
}
Problem p03954 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
typedef long long ll;
ll gi() {
  ll x = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch))
    f ^= ch == '-', ch = getchar();
  while (isdigit(ch))
    x = x * 10 + ch - '0', ch = getchar();
  return f ? x : -x;
}
int n, a[100010], b[100010];
bool check(int mid) {
  for (int i = 1; i < 2 * n; ++i)
    b[i] = a[i] <= mid;
  for (int i = 0; i + 1 < n; ++i) {
    if (b[n + i] == b[n + i + 1])
      return b[n + i];
    if (b[n - i] == b[n - i - 1])
      return b[n - i];
  }
  return b[1];
}
int main() {
#ifdef XZZSB
  freopen("in.in", "r", stdin);
  freopen("out.out", "w", stdout);
#endif
  n = gi();
  for (int i = 1; i < 2 * n; ++i)
    a[i] = gi();
  int l = 1, r = 2 * n - 1, mid;
  while (l < r) {
    mid = (l + r) >> 1;
    if (check(mid))
      r = mid;
    else
      l = mid + 1;
  }
  printf("%d\n", l);
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
typedef long long ll;
ll gi() {
  ll x = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch))
    f ^= ch == '-', ch = getchar();
  while (isdigit(ch))
    x = x * 10 + ch - '0', ch = getchar();
  return f ? x : -x;
}
int n, a[200010], b[200010];
bool check(int mid) {
  for (int i = 1; i < 2 * n; ++i)
    b[i] = a[i] <= mid;
  for (int i = 0; i + 1 < n; ++i) {
    if (b[n + i] == b[n + i + 1])
      return b[n + i];
    if (b[n - i] == b[n - i - 1])
      return b[n - i];
  }
  return b[1];
}
int main() {
#ifdef XZZSB
  freopen("in.in", "r", stdin);
  freopen("out.out", "w", stdout);
#endif
  n = gi();
  for (int i = 1; i < 2 * n; ++i)
    a[i] = gi();
  int l = 1, r = 2 * n - 1, mid;
  while (l < r) {
    mid = (l + r) >> 1;
    if (check(mid))
      r = mid;
    else
      l = mid + 1;
  }
  printf("%d\n", l);
  return 0;
}
Problem p03954 (C++)

Buggy submission (status: Runtime Error):
// ===================================
//   author: M_sea
//   website: http://m-sea-blog.com/
// ===================================
#include <bits/stdc++.h>
#define re register
using namespace std;

inline int read() {
  int X = 0, w = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-')
      w = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9')
    X = X * 10 + c - '0', c = getchar();
  return X * w;
}

const int N = 100000 + 10;

int n, a[N];

inline int check(int mid) {
  for (re int i = 0; i < n - 1; ++i) {
    if (a[n - i] < mid && a[n - i - 1] < mid)
      return 0;
    if (a[n + i] < mid && a[n + i + 1] < mid)
      return 0;
    if (a[n - i] >= mid && a[n - i - 1] >= mid)
      return 1;
    if (a[n + i] >= mid && a[n + i + 1] >= mid)
      return 1;
  }
  return a[1] < mid ? 0 : 1;
}

int main() {
  n = read();
  for (re int i = 1; i < n << 1; ++i)
    a[i] = read();
  int L = 1, R = (n << 1) - 1;
  while (L < R) {
    int mid = (L + R + 1) >> 1;
    if (check(mid))
      L = mid;
    else
      R = mid - 1;
  }
  printf("%d\n", L);
  return 0;
}


Fixed submission:
// ===================================
//   author: M_sea
//   website: http://m-sea-blog.com/
// ===================================
#include <bits/stdc++.h>
#define re register
using namespace std;

inline int read() {
  int X = 0, w = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-')
      w = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9')
    X = X * 10 + c - '0', c = getchar();
  return X * w;
}

const int N = 200000 + 10;

int n, a[N];

inline int check(int mid) {
  for (re int i = 0; i < n - 1; ++i) {
    if (a[n - i] < mid && a[n - i - 1] < mid)
      return 0;
    if (a[n + i] < mid && a[n + i + 1] < mid)
      return 0;
    if (a[n - i] >= mid && a[n - i - 1] >= mid)
      return 1;
    if (a[n + i] >= mid && a[n + i + 1] >= mid)
      return 1;
  }
  return a[1] < mid ? 0 : 1;
}

int main() {
  n = read();
  for (re int i = 1; i < n << 1; ++i)
    a[i] = read();
  int L = 1, R = (n << 1) - 1;
  while (L < R) {
    int mid = (L + R + 1) >> 1;
    if (check(mid))
      L = mid;
    else
      R = mid - 1;
  }
  printf("%d\n", L);
  return 0;
}
Problem p03954 (C++)

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

const int N = 100005;

int n, l, r, mid, m;
int a[N], b[N];

bool check(int w) {
  int i, l, r;
  for (i = 1; i <= m; i++)
    b[i] = (a[i] > w);
  l = r = n;
  while (l > 1 && b[l] != b[l - 1])
    l--;
  while (r < m && b[r] != b[r + 1])
    r++;
  if (m - r + 1 >= l)
    return b[r];
  return b[l];
}

int main() {
  int i;
  scanf("%d", &n);
  m = n + n - 1;
  for (i = 1; i <= m; i++)
    scanf("%d", &a[i]);
  l = 1;
  r = m;
  while (l < r) {
    mid = l + (r - l) / 2;
    if (check(mid))
      l = mid + 1;
    else
      r = mid;
  }
  printf("%d\n", r);
  return 0;
}

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

const int N = 200005;

int n, l, r, mid, m;
int a[N], b[N];

bool check(int w) {
  int i, l, r;
  for (i = 1; i <= m; i++)
    b[i] = (a[i] > w);
  l = r = n;
  while (l > 1 && b[l] != b[l - 1])
    l--;
  while (r < m && b[r] != b[r + 1])
    r++;
  if (m - r + 1 >= l)
    return b[r];
  return b[l];
}

int main() {
  int i;
  scanf("%d", &n);
  m = n + n - 1;
  for (i = 1; i <= m; i++)
    scanf("%d", &a[i]);
  l = 1;
  r = m;
  while (l < r) {
    mid = l + (r - l) / 2;
    if (check(mid))
      l = mid + 1;
    else
      r = mid;
  }
  printf("%d\n", r);
  return 0;
}
Problem p03954 (C++)

Buggy submission (status: Runtime Error):
#include <cstdio>
#include <iostream>
using namespace std;
int n, a[101010], b[101010];
bool check(int x) {
  for (int i = 1; i <= n * 2 + 1; i++)
    b[i] = (a[i] > x);
  b[0] = b[1];
  for (int i = n, j = n; i; i--, j++)
    if (b[i] == b[i - 1])
      return b[i];
    else if (b[j] == b[j + 1])
      return b[j];
}

int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n * 2 - 1; i++)
    scanf("%d", &a[i]);
  int l = 1, r = n * 2 - 1, mid;
  while (l < r) {
    mid = (l + r) / 2;
    if (!check(mid))
      r = mid;
    else
      l = mid + 1;
  }
  printf("%d\n", l);
  return 0;
}

Fixed submission:
#include <cstdio>
#include <iostream>
using namespace std;
int n, a[301010], b[301010];
bool check(int x) {
  for (int i = 1; i <= n * 2 + 1; i++)
    b[i] = (a[i] > x);
  b[0] = b[1];
  for (int i = n, j = n; i; i--, j++)
    if (b[i] == b[i - 1])
      return b[i];
    else if (b[j] == b[j + 1])
      return b[j];
}

int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n * 2 - 1; i++)
    scanf("%d", &a[i]);
  int l = 1, r = n * 2 - 1, mid;
  while (l < r) {
    mid = (l + r) / 2;
    if (!check(mid))
      r = mid;
    else
      l = mid + 1;
  }
  printf("%d\n", l);
  return 0;
}
Problem p03954 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
int n, a[200005];
inline int read() {
  int ret = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch))
    f = (ch == '-') ? -f : f, ch = getchar();
  while (isdigit(ch))
    ret = (ret << 1) + (ret << 3) + ch - 48, ch = getchar();
  return ret * f;
}

inline bool check(const int &k) {
  if (a[n] <= k && (a[n - 1] <= k || a[n + 1] <= k))
    return 1;
  if (a[n] > k && (a[n - 1] > k || a[n + 1] > k))
    return 0;
  for (int i = 1; i < n - 1; i++) {
    if ((a[n + i] <= k && a[n + i + 1] <= k) ||
        (a[n - i] <= k && a[n - i - 1] <= k))
      return 1;
    if ((a[n + i] > k && a[n + i + 1] > k) ||
        (a[n - i] > k && a[n - i - 1] > k))
      return 0;
  }
  return a[1] <= k;
}
int main() {
  freopen("pyramid.in", "r", stdin);
  freopen("pyramid.out", "w", stdout);
  n = read();
  for (int i = 1; i <= 2 * n - 1; i++)
    a[i] = read();
  int L = 0, R = (n << 1) - 1;
  while (L <= R) {
    int mid = (L + R) >> 1;
    if (check(mid))
      R = mid - 1;
    else
      L = mid + 1;
  }
  printf("%d\n", L);
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int n, a[200005];
inline int read() {
  int ret = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch))
    f = (ch == '-') ? -f : f, ch = getchar();
  while (isdigit(ch))
    ret = (ret << 1) + (ret << 3) + ch - 48, ch = getchar();
  return ret * f;
}

inline bool check(const int &k) {
  if (a[n] <= k && (a[n - 1] <= k || a[n + 1] <= k))
    return 1;
  if (a[n] > k && (a[n - 1] > k || a[n + 1] > k))
    return 0;
  for (int i = 1; i < n - 1; i++) {
    if ((a[n + i] <= k && a[n + i + 1] <= k) ||
        (a[n - i] <= k && a[n - i - 1] <= k))
      return 1;
    if ((a[n + i] > k && a[n + i + 1] > k) ||
        (a[n - i] > k && a[n - i - 1] > k))
      return 0;
  }
  return a[1] <= k;
}
int main() {
  n = read();
  for (int i = 1; i <= 2 * n - 1; i++)
    a[i] = read();
  int L = 0, R = (n << 1) - 1;
  while (L <= R) {
    int mid = (L + R) >> 1;
    if (check(mid))
      R = mid - 1;
    else
      L = mid + 1;
  }
  printf("%d\n", L);
  return 0;
}
Problem p03954 (C++)

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

#define fio()                                                                  \
  ios::sync_with_stdio(false);                                                 \
  cin.tie(0);                                                                  \
  cout.tie(0)
#define pb push_back
#define mp make_pair

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pi;
typedef pair<pi, ll> pii;

const ll mod = 1e9 + 7;
const ll maxn = 1e5 + 6;
const ll N = 1e2 + 2;
const ll inf = 1e12;
const ld eps = 1e-6;

ll n, k, arr[maxn], col[maxn];

// if ans > x

void print() {
  for (int i = 0; i < k; i++)
    cout << col[i] << " ";
  cout << endl;
}

bool solve(ll x) {
  for (int i = 0; i < k; i++) {
    if (arr[i] > x)
      col[i] = 1;
    else
      col[i] = 0;
  }
  //	print();
  for (int i = 1; i < n; i++) {
    if (col[n - i - 1] == col[n - i])
      return col[n - i];
    if (col[n + i - 1] == col[n + i - 2])
      return col[n + i - 1];
  }
  return col[0];
}

int main() {
  fio();
  cin >> n;
  k = 2 * n - 1;
  for (int i = 0; i < k; i++)
    cin >> arr[i];
  ll L = 0, R = k - 1, M;
  while (L < R) {
    // cout << L << " " << R << endl;
    M = (L + R) / 2;
    if (solve(M))
      L = M + 1;
    else
      R = M;
  }
  cout << L << endl;
  return 0;
}


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

#define fio()                                                                  \
  ios::sync_with_stdio(false);                                                 \
  cin.tie(0);                                                                  \
  cout.tie(0)
#define pb push_back
#define mp make_pair

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pi;
typedef pair<pi, ll> pii;

const ll mod = 1e9 + 7;
const ll maxn = 2e5 + 6;
const ll N = 1e2 + 2;
const ll inf = 1e12;
const ld eps = 1e-6;

ll n, k, arr[maxn], col[maxn];

// if ans > x

void print() {
  for (int i = 0; i < k; i++)
    cout << col[i] << " ";
  cout << endl;
}

bool solve(ll x) {
  for (int i = 0; i < k; i++) {
    if (arr[i] > x)
      col[i] = 1;
    else
      col[i] = 0;
  }
  //	print();
  for (int i = 1; i < n; i++) {
    if (col[n - i - 1] == col[n - i])
      return col[n - i];
    if (col[n + i - 1] == col[n + i - 2])
      return col[n + i - 1];
  }
  return col[0];
}

int main() {
  fio();
  cin >> n;
  k = 2 * n - 1;
  for (int i = 0; i < k; i++)
    cin >> arr[i];
  ll L = 0, R = k - 1, M;
  while (L < R) {
    // cout << L << " " << R << endl;
    M = (L + R) / 2;
    if (solve(M))
      L = M + 1;
    else
      R = M;
  }
  cout << L << endl;
  return 0;
}
Problem p03954 (C++)

Buggy submission (status: Runtime Error):

#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
using namespace std;

#define fir first
#define sec second

typedef long long LL;
typedef pair<int, int> PP;

namespace INPUT {
const int L = 1 << 15;
char _buf[L], *S, *T, c;
char _gc() {
  if (S == T) {
    T = (S = _buf) + fread(_buf, 1, L, stdin);
    if (S == T)
      return EOF;
  }
  return *S++;
}
void readi(int &X) {
  for (c = _gc(); c < '0' || c > '9'; c = _gc())
    ;
  X = c & 15;
  for (c = _gc(); c >= '0' && c <= '9'; X = X * 10 + (c & 15), c = _gc())
    ;
}
} // namespace INPUT
using INPUT ::readi;

const int Maxn = 1E5 + 5;

int N;
int a[Maxn];
bool b[Maxn];

bool Check(int X) {
  bool FLAG = true;
  for (int i = 1; i <= N; ++i)
    b[i] = (a[i] >= X);
  for (int i = 2; i <= N; ++i)
    FLAG &= (b[i] != b[i - 1]);
  if (FLAG)
    return b[N / 2 + 1] ^ ((N / 2) & 1);
  int l = 0, r = N + 1;
  for (int i = N / 2; i >= 1; --i)
    if (b[i] == b[i + 1]) {
      l = i;
      break;
    }
  for (int i = N / 2 + 2; i <= N; ++i)
    if (b[i] == b[i - 1]) {
      r = i;
      break;
    }
  if ((N / 2 + 1 - l) < (r - N / 2 - 1))
    return b[l];
  return b[r];
}

int main() {
  readi(N), N = N * 2 - 1;
  for (int i = 1; i <= N; ++i)
    readi(a[i]);
  int lb = 0, rb = N + 1;
  while (lb + 1 < rb) {
    int mid = lb + rb >> 1;
    if (Check(mid))
      lb = mid;
    else
      rb = mid;
  }
  printf("%d", lb);
  return 0;
}


Fixed submission:

#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
using namespace std;

#define fir first
#define sec second

typedef long long LL;
typedef pair<int, int> PP;

namespace INPUT {
const int L = 1 << 15;
char _buf[L], *S, *T, c;
char _gc() {
  if (S == T) {
    T = (S = _buf) + fread(_buf, 1, L, stdin);
    if (S == T)
      return EOF;
  }
  return *S++;
}
void readi(int &X) {
  for (c = _gc(); c < '0' || c > '9'; c = _gc())
    ;
  X = c & 15;
  for (c = _gc(); c >= '0' && c <= '9'; X = X * 10 + (c & 15), c = _gc())
    ;
}
} // namespace INPUT
using INPUT ::readi;

const int Maxn = 2E5 + 5;

int N;
int a[Maxn];
bool b[Maxn];

bool Check(int X) {
  bool FLAG = true;
  for (int i = 1; i <= N; ++i)
    b[i] = (a[i] >= X);
  for (int i = 2; i <= N; ++i)
    FLAG &= (b[i] != b[i - 1]);
  if (FLAG)
    return b[N / 2 + 1] ^ ((N / 2) & 1);
  int l = 0, r = N + 1;
  for (int i = N / 2; i >= 1; --i)
    if (b[i] == b[i + 1]) {
      l = i;
      break;
    }
  for (int i = N / 2 + 2; i <= N; ++i)
    if (b[i] == b[i - 1]) {
      r = i;
      break;
    }
  if ((N / 2 + 1 - l) < (r - N / 2 - 1))
    return b[l];
  return b[r];
}

int main() {
  readi(N), N = N * 2 - 1;
  for (int i = 1; i <= N; ++i)
    readi(a[i]);
  int lb = 0, rb = N + 1;
  while (lb + 1 < rb) {
    int mid = lb + rb >> 1;
    if (Check(mid))
      lb = mid;
    else
      rb = mid;
  }
  printf("%d", lb);
  return 0;
}
Problem p03954 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;
int read();

int N, x[200005], st[200005], a[200005];
int work() {
  int m = N / 2 + 1, res = a[m], l = m, r = m;
  a[0] = a[1], a[N + 1] = a[N];
  for (; l >= 1 && a[l] != a[l - 1] && a[r] != a[r + 1]; --l, ++r)
    res ^= 1;
  return res;
}

int main() {
  freopen("triangle.in", "r", stdin);
  freopen("triangle.out", "w", stdout);
  N = read() * 2 - 1;
  for (int i = 1; i <= N; ++i)
    st[i] = x[i] = read();
  sort(st + 1, st + 1 + N);
  int l = 1, r = N, res = r;
  while (l <= r) {
    int mid = l + r >> 1;
    for (int i = 1; i <= N; ++i)
      a[i] = x[i] > st[mid];
    if (!work())
      r = mid - 1, res = mid;
    else
      l = mid + 1;
  }
  printf("%d\n", st[res]);
  return 0;
}
int read() {
  int x = 0, f = 1;
  char c = getchar();
  while (!isdigit(c))
    f = (c == '-') ? -1 : f, c = getchar();
  while (isdigit(c))
    x = x * 10 + c - '0', c = getchar();
  return x * f;
}

Fixed submission:
#include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;
int read();

int N, x[200005], st[200005], a[200005];
int work() {
  int m = N / 2 + 1, res = a[m], l = m, r = m;
  a[0] = a[1], a[N + 1] = a[N];
  for (; l >= 1 && a[l] != a[l - 1] && a[r] != a[r + 1]; --l, ++r)
    res ^= 1;
  return res;
}

int main() {
  N = read() * 2 - 1;
  for (int i = 1; i <= N; ++i)
    st[i] = x[i] = read();
  sort(st + 1, st + 1 + N);
  int l = 1, r = N, res = r;
  while (l <= r) {
    int mid = l + r >> 1;
    for (int i = 1; i <= N; ++i)
      a[i] = x[i] > st[mid];
    if (!work())
      r = mid - 1, res = mid;
    else
      l = mid + 1;
  }
  printf("%d\n", st[res]);
  return 0;
}
int read() {
  int x = 0, f = 1;
  char c = getchar();
  while (!isdigit(c))
    f = (c == '-') ? -1 : f, c = getchar();
  while (isdigit(c))
    x = x * 10 + c - '0', c = getchar();
  return x * f;
}
Problem p03954 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#include <cstring>
#define mid (l + r) / 2

const int N = 1e5 + 51;

int n, m, a[N];
bool check(int x) {
  for (int i = 0; i < m - 1; i++) {
    if ((a[m + i] <= x && a[m + i + 1] <= x) ||
        (a[m - i] <= x && a[m - i - 1] <= x))
      return 1;
    if ((a[m + i] > x && a[m + i + 1] > x) ||
        (a[m - i] > x && a[m - i - 1] > x))
      return 0;
  }
  return a[1] <= x;
}

int l, r;
int main() {
  scanf("%d", &n);
  m = n, n = n * 2 - 1;
  for (int i = 1; i <= n; i++)
    scanf("%d", a + i);
  for (l = 1, r = n; l <= r;)
    if (check(mid))
      r = mid - 1;
    else
      l = mid + 1;
  printf("%d", l);
}

Fixed submission:
#include <algorithm>
#include <cstdio>
#include <cstring>
#define mid (l + r) / 2

const int N = 2e5 + 52;

int n, m, a[N];
bool check(int x) {
  for (int i = 0; i < m - 1; i++) {
    if ((a[m + i] <= x && a[m + i + 1] <= x) ||
        (a[m - i] <= x && a[m - i - 1] <= x))
      return 1;
    if ((a[m + i] > x && a[m + i + 1] > x) ||
        (a[m - i] > x && a[m - i - 1] > x))
      return 0;
  }
  return a[1] <= x;
}

int l, r;
int main() {
  scanf("%d", &n);
  m = n, n = n * 2 - 1;
  for (int i = 1; i <= n; i++)
    scanf("%d", a + i);
  for (l = 1, r = n; l <= r;)
    if (check(mid))
      r = mid - 1;
    else
      l = mid + 1;
  printf("%d", l);
}
Problem p03954 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 9;

int n, a[N], m, b[N];

bool Judge() {
  int l = n, r = n;
  while (l > 1 && b[l - 1] ^ b[l])
    --l;
  while (r < m && b[r] ^ b[r + 1])
    ++r;
  int x = min(n - l, r - n);
  return b[n] ^ (x & 1);
}

int main() {
  scanf("%d", &n);
  int l = 1, r = m = n * 2 - 1, mid;
  for (int i = 1; i <= m; ++i)
    scanf("%d", &a[i]);
  while (l <= r) {
    mid = (l + r) >> 1;
    for (int i = 1; i <= m; ++i)
      b[i] = (a[i] <= mid);
    if (Judge())
      r = mid - 1;
    else
      l = mid + 1;
  }
  printf("%d\n", l);
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 9;

int n, a[N], m, b[N];

bool Judge() {
  int l = n, r = n;
  while (l > 1 && b[l - 1] ^ b[l])
    --l;
  while (r < m && b[r] ^ b[r + 1])
    ++r;
  int x = min(n - l, r - n);
  return b[n] ^ (x & 1);
}

int main() {
  scanf("%d", &n);
  int l = 1, r = m = n * 2 - 1, mid;
  for (int i = 1; i <= m; ++i)
    scanf("%d", &a[i]);
  while (l <= r) {
    mid = (l + r) >> 1;
    for (int i = 1; i <= m; ++i)
      b[i] = (a[i] <= mid);
    if (Judge())
      r = mid - 1;
    else
      l = mid + 1;
  }
  printf("%d\n", l);
  return 0;
}
Problem p03957 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  string a;
  cin >> a;
  if (a.find('C') == string::npos) {
    cout << "No" << endl;
    exit(1);
  } else {
    a.erase(0, a.find('C'));
    if (a.find('F') != string::npos)
      cout << "Yes";
    else
      cout << "No";
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  string a;
  cin >> a;
  if (a.find('C') == string::npos) {
    cout << "No" << endl;
  } else {
    a.erase(0, a.find('C'));
    if (a.find('F') != string::npos)
      cout << "Yes";
    else
      cout << "No";
  }
  return 0;
}
Problem p03957 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
typedef long long int ll;
using namespace std;

int main() {
  string s;
  cin >> s;
  ll last = 0;
  ll l = s.length();
  ll ans = 0;
  ll sum = 0;
  for (ll i = 0; i < l; ++i) {
    if (s[i] == 'C') {
      last = i;
      ans += 1;
      break;
    }
  }
  for (ll i = 0; last < l; ++i) {
    if (s[i] == 'F') {
      sum += 1;
      break;
    }
  }
  if (ans == 1 and sum == 1) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Fixed submission:
#include <bits/stdc++.h>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
typedef long long int ll;
using namespace std;

int main() {
  string s;
  cin >> s;
  ll last = 0;
  ll l = s.length();
  ll ans = 0;
  ll sum = 0;
  for (ll i = 0; i < l; ++i) {
    if (s[i] == 'C') {
      last = i;
      ans += 1;
      break;
    }
  }
  for (ll i = last; i < l; ++i) {
    if (s[i] == 'F') {
      sum += 1;
      break;
    }
  }
  if (ans == 1 and sum == 1) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}
Problem p03957 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
int main() {
  char ch;
  bool f = 0;
  while (scanf("%c", &ch))
    if (f)
      if (ch == 'F')
        return 0 * printf("Yes\n");
      else if (ch == 'C')
        f = 1;
  return 0 * printf("No\n");
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  char z[1000];
  gets(z);
  int a = 0, b = 0;
  for (int i = 0; i < strlen(z); i++) {
    if (z[i] == 'C')
      a = 1;
    if (a && z[i] == 'F')
      b = 1;
  }
  if (b)
    printf("Yes");
  else
    printf("No");
  return 0;
}
Problem p03957 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
string s;
vector<char> a;
int main() {
  cin >> s;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == 'C' || s[i] == 'F')
      a.push_back(s[i]);
  }
  for (int i = 0; i < a.size() - 1; i++) {
    if (a[i] == 'C' && a[i + 1] == 'F') {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
string s;
vector<char> a;
int main() {
  cin >> s;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == 'C' || s[i] == 'F')
      a.push_back(s[i]);
  }
  if (a.empty()) {
    puts("No");
    return 0;
  }
  for (int i = 0; i < a.size() - 1; i++) {
    if (a[i] == 'C' && a[i + 1] == 'F') {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}
Problem p03957 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll mod = 1000000007;
const int MAX_N = 1000; // n の最大値

// nCk を取得
double nCk(int n, int k) {
  double res = 1.0;
  for (int i = 0; i < n; i++) {
    res *= 0.5;
  }
  for (int i = 0; i < k; i++) {
    res *= (double)(n - i);
    res /= (double)(k - i);
  }
  return res;
}

int main() {
  string s;
  cin >> s;
  ll k = 0;
  ll g = 0;
  ll r = 0;
  for (ll i = 0; i < (ll)s.size(); i++) {
    if (s.at(i) == 'C') {
      k = i;
      r++;
      break;
    }
  }
  for (ll i = s.size(); i > k; i--) {
    if (s.at(i) == 'F') {
      g = i;
      r++;
      break;
    }
  }
  if (r == 2)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll mod = 1000000007;
const int MAX_N = 1000; // n の最大値

// nCk を取得
double nCk(int n, int k) {
  double res = 1.0;
  for (int i = 0; i < n; i++) {
    res *= 0.5;
  }
  for (int i = 0; i < k; i++) {
    res *= (double)(n - i);
    res /= (double)(k - i);
  }
  return res;
}

int main() {
  string s;
  cin >> s;
  ll k = 0;
  ll g = 0;
  ll r = 0;
  for (ll i = 0; i < (ll)s.size(); i++) {
    if (s.at(i) == 'C') {
      k = i;
      r++;
      break;
    }
  }
  for (ll i = s.size() - 1; i > k; i--) {
    if (s.at(i) == 'F') {
      g = i;
      r++;
      break;
    }
  }
  if (r == 2)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}
Problem p03957 (C++)

Buggy submission (status: Runtime Error):
#include <cstring>
#include <iostream>
using namespace std;
int main() {
  string a, s;
  int j;
  cin >> a;
  for (int i = 1; i <= a.length(); i++) {
    s = 'CF';
    if (a[i] == s[j]) {
      j++;
      if (j == 2) {
        break;
      }
    }
  }
  if (j == 2)
    cout << "Yes";
  else
    cout << "No";
  return 0;
}


Fixed submission:
#include <cstring>
#include <iostream>
using namespace std;
int main() {
  string s;
  getline(cin, s);
  if (s.find("C") < s.length()) {
    int k = s.find("C");
    if (s.find("F", k) < s.length())
      cout << "Yes";
    else
      cout << "No";
  } else
    cout << "No";
  return 0;
}
Problem p03957 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
using namespace std;
int main() {
  string a;
  int j = 0;
  cin >> a;
  for (int i = 0; i < a.size(); i++) {
    while (a[i] == 'C' && j < a.size()) {
      j = i;
      j++;
      if (a[j] == 'F') {
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define us using namespace std;
us
#define MAXN [10001400]
#define ll long long
#define cc cin >>
#define st strlen
#define bo bool
#define ch char
#define out cout <<
#define rrr return 0;
#define iC(x)                                                                  \
  if ((x) == 'C')                                                              \
    flagC = true;
#define iF(x)                                                                  \
  if ((x) == 'F' && flagC)                                                     \
    flagF = true;
#define _if(a, b)                                                              \
  if ((a) && (b))                                                              \
    cout << "Yes";                                                             \
  else                                                                         \
    cout << "No";
#define _for(i, a, b)                                                          \
  ;                                                                            \
  for (int i = (a); i <= (b); i++)
#define IM int main()
    ch as MAXN;
bo flagC, flagF;
IM { cc as _for(i, 0, strlen(as)){iC(as[i]) iF(as[i])} _if(flagC, flagF) rrr }
Problem p03957 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <typeinfo>
#include <utility>
#include <vector>
#define REP(i, n) for (int i = 0; i < n; i++)
typedef long long int ll;
using namespace std;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<string> vs;

int main() {
  string s;
  cin >> s;
  int pc = -1;
  int pf = -1;
  for (int i = s.length() - 1; i >= 0; i--)
    if (s[i] == 'F') {
      pf = i;
      break;
    }
  for (int i = 0; i >= 0; i++)
    if (s[i] == 'C') {
      pc = i;
      break;
    }
  if (pc != -1 && pf != -1) {
    if (pc < pf) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <typeinfo>
#include <utility>
#include <vector>
#define REP(i, n) for (int i = 0; i < n; i++)
typedef long long int ll;
using namespace std;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<string> vs;

int main() {
  string s;
  cin >> s;
  int pc = -1;
  int pf = -1;
  for (int i = s.length() - 1; i >= 0; i--)
    if (s[i] == 'F') {
      pf = i;
      break;
    }
  for (int i = 0; i < s.length(); i++)
    if (s[i] == 'C') {
      pc = i;
      break;
    }
  if (pc != -1 && pf != -1) {
    if (pc < pf) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}
Problem p03957 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
const long long mod = pow(10, 9) + 7;
const long long INF = 1LL << 60;
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() {
  string s;
  cin >> s;
  int N = s.size();

  int firstC = 200;
  int lastF = -200;

  for (int i = 0; i < N; i++) {
    if (s.at(i) == 'C') {
      firstC = i;
      break;
    }
  }

  for (int i = N; i >= 0; i--) {
    if (s.at(i) == 'F') {
      lastF = i;
      break;
    }
  }

  string ans = "No";
  if (firstC < lastF)
    ans = "Yes";

  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
const long long mod = pow(10, 9) + 7;
const long long INF = 1LL << 60;
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() {
  string s;
  cin >> s;
  int N = s.size();

  int firstC = 200;
  int lastF = -200;

  for (int i = 0; i < N; i++) {
    if (s.at(i) == 'C') {
      firstC = i;
      break;
    }
  }

  for (int i = N - 1; i >= 0; i--) {
    if (s.at(i) == 'F') {
      lastF = i;
      break;
    }
  }

  string ans = "No";
  if (firstC < lastF)
    ans = "Yes";

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

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep0(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i < (n); ++i)
#define REP(i, a, b) for (int i = a; i < (b); ++i)
#define mREP(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; }
int main() {
  string s;
  rep0(i, s.size() - 1) {
    if (s[i] == 'C') {
      REP(j, i, s.size()) {
        if (s[j] == 'F') {
          cout << "Yes" << endl;
          return 0;
        }
      }
    }
  }
  cout << "No" << endl;

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define rep0(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i < (n); ++i)
#define REP(i, a, b) for (int i = a; i < (b); ++i)
#define mREP(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; }
int main() {
  string s;
  cin >> s;
  rep0(i, s.size() - 1) {
    if (s[i] == 'C') {
      REP(j, i, s.size()) {
        if (s[j] == 'F') {
          cout << "Yes" << endl;
          return 0;
        }
      }
    }
  }
  cout << "No" << endl;

  return 0;
}
Problem p03957 (Python)

Buggy submission (status: Runtime Error):
s = input()
if s.index("C") >= 0 and s.index("F") >= 0:
    if s.index("C") < s.rindex("F"):
        print("Yes")
    else:
        print("No")
else:
    print("No")


Fixed submission:
s = input()
if s.find("C") >= 0 and s.find("F") >= 0:
    if s.index("C") < s.rindex("F"):
        print("Yes")
    else:
        print("No")
else:
    print("No")
Problem p03957 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
#include <string>
using namespace std;

int main() {
  string s;
  cin >> s;
  int ans = 0;

  for (int i = 0; i < s.size(); i++) {
    if (s[i] == 'C') {

      for (int j = i + 1; j < s.size(); i++) {
        if (s[j] == 'F') {
          cout << "Yes" << endl;
          return 0;
        }
      }

      cout << "No" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
}

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

int main() {
  string s;
  cin >> s;
  int ans = 0;

  for (int i = 0; i < s.size(); i++) {
    if (s[i] == 'C') {

      for (int j = i + 1; j < s.size(); j++) {
        if (s[j] == 'F') {
          cout << "Yes" << endl;
          return 0;
        }
      }

      cout << "No" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
}
Problem p03957 (C++)

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

int main() {
  string a;
  cin >> a;

  int pre = 100;

  bool x = false;

  for (int i = 0; i < a.size(); i++) {
    if (a[i] == 'C') {
      pre = i;
      break;
    }
  }
  for (int i = pre; i < a.size() - pre; i++) {
    if (a[i] == 'F') {
      x = true;
    }
  }
  if (x)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

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

int main() {
  string a;
  cin >> a;

  int pre = 100;

  bool x = false;

  for (int i = 0; i < a.size(); i++) {
    if (a[i] == 'C') {
      pre = i;
      break;
    }
  }
  for (int i = pre; i < a.size(); i++) {
    if (a[i] == 'F') {
      x = true;
    }
  }
  if (x)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}
Problem p03957 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define rep(i, a, n) for (int i = a; i < n; i++)
#define per(i, a, n) for (int i = n - 1; i >= a; i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int, int> PII;
const ll mod = 1000000007;
ll powmod(ll a, ll b) {
  ll res = 1;
  a %= mod;
  assert(b >= 0);
  for (; b; b >>= 1) {
    if (b & 1)
      res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}

char s[200];
int main() {
  FILE *fp = fopen("input.txt", "r");
  fscanf(fp, "%s", &s);
  int n = strlen(s);
  int x = -1, y = -1;
  rep(i, 0, n) if (s[i] == 'C') {
    x = i;
    break;
  }
  per(i, 0, n) if (s[i] == 'F') {
    y = i;
    break;
  }
  if ((x == -1) || (y == -1) || (x > y))
    cout << "No" << endl;
  else
    cout << "Yes" << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define rep(i, a, n) for (int i = a; i < n; i++)
#define per(i, a, n) for (int i = n - 1; i >= a; i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int, int> PII;
const ll mod = 1000000007;
ll powmod(ll a, ll b) {
  ll res = 1;
  a %= mod;
  assert(b >= 0);
  for (; b; b >>= 1) {
    if (b & 1)
      res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}

char s[200];
int main() {
  FILE *fp = stdin; // fopen("input.txt","r");
  fscanf(fp, "%s", &s);
  int n = strlen(s);
  int x = -1, y = -1;
  rep(i, 0, n) if (s[i] == 'C') {
    x = i;
    break;
  }
  per(i, 0, n) if (s[i] == 'F') {
    y = i;
    break;
  }
  if ((x == -1) || (y == -1) || (x > y))
    cout << "No" << endl;
  else
    cout << "Yes" << endl;
  return 0;
}