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

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define REP(i, a, n) for (int i = (a); i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define FOR(it, c)                                                             \
  for (__typeof((c).begin()) it = (c).begin(); it != (c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

ll solve(ll X, ll Y) {
  ll ret = 0;
  while (X <= Y) {
    ret++;
    X *= 2;
  }
  return ret;
}

int main() {
  ll X, Y;
  cin >> X >> Y;

  ll ret = -1;
  while (true) {
    ll res = solve(X, Y);
    if (res < ret)
      break;
    ret = max(ret, res);
    X++;
  }

  cout << ret << endl;

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define REP(i, a, n) for (int i = (a); i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define FOR(it, c)                                                             \
  for (__typeof((c).begin()) it = (c).begin(); it != (c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

ll solve(ll X, ll Y) {
  ll ret = 0;
  while (X <= Y) {
    ret++;
    X *= 2;
  }
  return ret;
}

int main() {
  ll X, Y;
  cin >> X >> Y;

  ll ret = -1;
  while (true) {
    ll res = solve(X, Y);
    if (res <= ret)
      break;
    ret = max(ret, res);
    X++;
  }

  cout << ret << endl;

  return 0;
}
Problem p03481 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define fore(x, a, b) for (int x = a, qwert = b; x < qwert; x++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(a) ((int)(a).size())
#define FIN                                                                    \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);                                                                  \
  cout.tie(0)
#define pb push_back
#define fst first
#define snd second
using namespace std;
typedef long long ll;

int main() {
  ll X, Y;
  int ans = 0;
  while (X <= Y) {
    ans++;
    X *= 2;
  }
  cout << ans << "\n";
}

Fixed submission:
#include <bits/stdc++.h>
#define fore(x, a, b) for (int x = a, qwert = b; x < qwert; x++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(a) ((int)(a).size())
#define FIN                                                                    \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);                                                                  \
  cout.tie(0)
#define pb push_back
#define fst first
#define snd second
using namespace std;
typedef long long ll;

int main() {
  ll X, Y;
  cin >> X >> Y;
  int ans = 0;
  while (X <= Y) {
    ans++;
    X *= 2;
  }
  cout << ans << "\n";
}
Problem p03481 (C++)

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

#define MaxN 100005
#define MOD 1000000007
#define INF 2140000000

using namespace std;

string S;
int Solve() {
  char type = 'z';
  S.push_back('a');
  int L = 0, A = 0, Max = (S.size() + 1) / 2;
  for (int i = 0; i < S.size(); i++) {
    if (type != S[i]) {
      Max = max(max(L, Max), min(A, min(L + (int)S.size() - i - 1, i - L)));
      A = L;
      L = 1, type = S[i];
    } else
      L++, A++;
  }
  cout << Max;
}
int main() {
  int X, Y;
  cin >> X >> Y;
  int Ans = 1;
  while (X * 2 <= Y)
    X *= 2, Ans++;
  cout << Ans;
  return 0;
}


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

#define MaxN 100005
#define MOD 1000000007
#define INF 2140000000

using namespace std;

string S;
int Solve() {
  char type = 'z';
  S.push_back('a');
  int L = 0, A = 0, Max = (S.size() + 1) / 2;
  for (int i = 0; i < S.size(); i++) {
    if (type != S[i]) {
      Max = max(max(L, Max), min(A, min(L + (int)S.size() - i - 1, i - L)));
      A = L;
      L = 1, type = S[i];
    } else
      L++, A++;
  }
  cout << Max;
}
int main() {
  long long X, Y;
  cin >> X >> Y;
  int Ans = 1;
  while (X * 2 <= Y)
    X *= 2, Ans++;
  cout << Ans;
  return 0;
}
Problem p03481 (C++)

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

int main() {
  unsigned long long a, b;
  cin >> a >> b;
  unsigned long long cnt = 1;
  while (1) {
    if (a * 2 <= b) {
      cnt++;
      a *= 2;
    }
  }
  cout << cnt << endl;
  return 0;
}

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

int main() {
  unsigned long long a, b;
  cin >> a >> b;
  unsigned long long cnt = 1;
  while (1) {
    if (a * 2 <= b) {
      cnt++;
      a *= 2;
    } else
      break;
  }
  cout << cnt << endl;
  return 0;
}
Problem p03481 (C++)

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

int main() {
  int X, Y;
  cin >> X >> Y;
  int ans = 1;
  while (X < Y) {
    X *= 2;
    if (X <= Y) {
      ans++;
    }
  }
  cout << ans << endl;
}

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

int main() {
  long long X, Y;
  cin >> X >> Y;
  int ans = 1;
  while (X < Y) {
    X *= 2;
    if (X <= Y) {
      ans++;
    }
  }
  cout << ans << endl;
}
Problem p03481 (C++)

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

#define F first
#define S second
#define pb push_back
#define all(x) x.begin(), x.end()
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")

using namespace std;

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

const int N = 200000 + 10;
const ll MOD = 1000000000 + 7;
const ll INF = 1000000010;
const ll LOG = 25;

int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ll x, y;
  int cnt = 1;
  while (x * 2 <= y) {
    x *= 2;
    cnt++;
  }
  cout << cnt;

  return 0;
}


Fixed submission:
// khodaya khodet komak kon
#include <bits/stdc++.h>

#define F first
#define S second
#define pb push_back
#define all(x) x.begin(), x.end()
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")

using namespace std;

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

const int N = 200000 + 10;
const ll MOD = 1000000000 + 7;
const ll INF = 1000000010;
const ll LOG = 25;

int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ll x, y;
  cin >> x >> y;

  int cnt = 1;
  while (x * 2 <= y) {
    x *= 2;
    cnt++;
  }
  cout << cnt;

  return 0;
}
Problem p03481 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <string>
#include <vector>

int main() {
  long long X, Y;
  std::cin >> X >> Y;
  int ans = 0;
  while (X <= Y) {
    X * 2;
    ++ans;
  }
  std::cout << ans << std::endl;

  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <string>
#include <vector>

int main() {
  long long X, Y;
  std::cin >> X >> Y;
  int ans = 0;
  while (X <= Y) {
    X *= 2;
    ++ans;
  }
  std::cout << ans << std::endl;

  return 0;
}
Problem p03482 (C++)

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

using namespace std;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, i = 0;
  string str;
  cin >> str;
  N = str.length();
  string str1 = string(N, '1');
  string str0 = string(N, '0');
  while ((str0.substr(i, N - 2 * i) != str.substr(i, N - 2 * i)) &&
         (str1.substr(i, N - 2 * i) != str.substr(i, N - 2 * i)) &&
         (i <= N / 2)) {
    ++i;
  }
  cout << N - i << "\n";
  return 0;
}


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

using namespace std;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, i = 0;
  string str;
  cin >> str;
  N = str.length();
  string str1 = string(N, '1');
  string str0 = string(N, '0');
  for (;
       (str0.substr(i, N - 2 * i) != str.substr(i, N - 2 * i)) &&
       (str1.substr(i, N - 2 * i) != str.substr(i, N - 2 * i)) && (i <= N / 2);
       ++i) {
  }
  cout << N - i << "\n";
  return 0;
}
Problem p03482 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <climits>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <vector>

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;

string s;
int base[100001];

int main() {
  cin >> s;
  int N = s.size();
  int back, front;
  if (N % 2 == 0) {
    back = N / 2 - 1;
    front = N / 2;
  } else {
    back = N / 2;
    front = N / 2;
  }
  char med = s.at(back);
  while (s.at(back) == med && s.at(front) == med) {
    back--;
    front++;
    if (back == 0) {
      break;
    }
  }
  cout << front << endl;
}


Fixed submission:
#include <algorithm>
#include <climits>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <vector>

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;

string s;
int base[100001];

int main() {
  cin >> s;
  int N = s.size();
  int back, front;
  if (N % 2 == 0) {
    back = N / 2 - 1;
    front = N / 2;
  } else {
    back = N / 2;
    front = N / 2;
  }
  char med = s.at(back);
  while (s.at(back) == med && s.at(front) == med) {
    back--;
    front++;
    if (back < 0) {
      break;
    }
  }
  cout << front << endl;
}
Problem p03482 (C++)

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

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<int> VI;
typedef vector<VI> VVI;
const double EPS = 1e-12;
const int INF = numeric_limits<int>::max() / 2;
const int NEG_INF = numeric_limits<int>::min() / 2;
const int MOD = 1e9 + 7;

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

  string s;
  cin >> s;
  int len = s.length();
  vector<int> res;
  for (int i = 1; i < len; i++) {
    if (s[i] == s[i - 1])
      continue;
    res.push_back(max(i, len - i));
  }
  sort(res.begin(), res.end());
  cout << res[0] << endl;
}


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

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<int> VI;
typedef vector<VI> VVI;
const double EPS = 1e-12;
const int INF = numeric_limits<int>::max() / 2;
const int NEG_INF = numeric_limits<int>::min() / 2;
const int MOD = 1e9 + 7;

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

  string s;
  cin >> s;
  int len = s.length();
  vector<int> res;
  for (int i = 1; i < len; i++) {
    if (s[i] == s[i - 1])
      continue;
    res.push_back(max(i, len - i));
  }
  if (res.size() == 0) {
    cout << len << endl;
    return 0;
  }
  sort(res.begin(), res.end());
  cout << res[0] << endl;
}
Problem p03482 (C++)

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

#ifdef BTK
#include <dvector.h>
#define DEBUG if (1)
#else
#define CIN_ONLY if (1)
struct cww {
  cww() {
    CIN_ONLY {
      ios::sync_with_stdio(false);
      cin.tie(0);
    }
  }
} star;
#define DEBUG if (0)
#endif

#define fin "\n"
#define FOR(i, bg, ed) for (int i = (bg); i < (ed); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(v) (v).begin(), (v).end()
#define fi first
#define se second
#define pb push_back
#define REC(ret, ...) std::function<ret(__VA_ARGS__)>
template <typename T> inline bool chmin(T &l, T r) {
  bool a = l > r;
  if (a)
    l = r;
  return a;
}
template <typename T> inline bool chmax(T &l, T r) {
  bool a = l < r;
  if (a)
    l = r;
  return a;
}
template <typename T> istream &operator>>(istream &is, vector<T> &v) {
  for (auto &it : v)
    is >> it;
  return is;
}

int main() {
  string s;
  cin >> s;
  int n = s.size();
  int col = s[n / 2];
  int K = 0;
  if (n % 2 == 0)
    return -1;
  REP(i, n / 2) if (col != s[i]) chmax(K, i);
  reverse(ALL(s));
  REP(i, n / 2) if (col != s[i]) chmax(K, i);
  K = n - (K + 1);
  cout << K << endl;
  return 0;
}


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

#ifdef BTK
#include <dvector.h>
#define DEBUG if (1)
#else
#define CIN_ONLY if (1)
struct cww {
  cww() {
    CIN_ONLY {
      ios::sync_with_stdio(false);
      cin.tie(0);
    }
  }
} star;
#define DEBUG if (0)
#endif

#define fin "\n"
#define FOR(i, bg, ed) for (int i = (bg); i < (ed); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(v) (v).begin(), (v).end()
#define fi first
#define se second
#define pb push_back
#define REC(ret, ...) std::function<ret(__VA_ARGS__)>
template <typename T> inline bool chmin(T &l, T r) {
  bool a = l > r;
  if (a)
    l = r;
  return a;
}
template <typename T> inline bool chmax(T &l, T r) {
  bool a = l < r;
  if (a)
    l = r;
  return a;
}
template <typename T> istream &operator>>(istream &is, vector<T> &v) {
  for (auto &it : v)
    is >> it;
  return is;
}

int main() {
  string s;
  cin >> s;
  int n = s.size();
  int col = s[n / 2];
  int K = -1;
  REP(i, n / 2) if (col != s[i]) chmax(K, i);
  reverse(ALL(s));
  REP(i, n / 2) if (col != s[i]) chmax(K, i);
  K = n - (K + 1);
  cout << K << endl;
  return 0;
}
Problem p03482 (C++)

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

#define each(i, c) for (auto &i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template <typename P, typename Q>
ostream &operator<<(ostream &os, pair<P, Q> p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <typename T> ostream &operator<<(ostream &os, vector<T> v) {
  os << "(";
  each(i, v) os << i << ",";
  os << ")";
  return os;
}

int main(int argc, char *argv[]) {
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  string s;
  while (cin >> s) {
    assert(s.size() != count(s.begin(), s.end(), '0'));
    assert(s.size() != count(s.begin(), s.end(), '1'));
    int mn = 1 << 29;
    for (int i = 0; i + 1 < s.size(); ++i) {
      if (s[i] != s[i + 1]) {
        int x = max<int>(i + 1, (int)s.size() - i - 1);
        mn = min(mn, x);
      }
    }
    cout << mn << endl;
  }

  return 0;
}


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

#define each(i, c) for (auto &i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template <typename P, typename Q>
ostream &operator<<(ostream &os, pair<P, Q> p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <typename T> ostream &operator<<(ostream &os, vector<T> v) {
  os << "(";
  each(i, v) os << i << ",";
  os << ")";
  return os;
}

int main(int argc, char *argv[]) {
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  string s;
  while (cin >> s) {
    int a = count(s.begin(), s.end(), '0');
    int b = count(s.begin(), s.end(), '1');
    if (s.size() == a || s.size() == b) {
      cout << s.size() << endl;
      continue;
    }

    int mn = 1 << 29;
    for (int i = 0; i + 1 < s.size(); ++i) {
      if (s[i] != s[i + 1]) {
        int x = max<int>(i + 1, (int)s.size() - i - 1);
        mn = min(mn, x);
      }
    }
    cout << mn << endl;
  }

  return 0;
}
Problem p03483 (C++)

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

const int MAXN = 200000 + 9;
char S[MAXN];
int len;
int cnt[30];
int pred[MAXN], succ[MAXN], head[30];
int num[MAXN];
bool vis[30];
int tmp[MAXN];
typedef long long LL;
int tree[MAXN];

int lowbit(int x) { return x & -x; }

void add(int pos, int val) {
  for (int i = pos; i <= len; i += lowbit(i))
    tree[i] += val;
}

LL getsum(int pos) {
  LL re = 0;
  for (int i = pos; i; i -= lowbit(i))
    re += tree[i];
  return re;
}

void PRE() {
  memset(head, -1, sizeof(head));
  for (int i = len; i; i--) {
    succ[i] = head[num[i]];
    head[num[i]] = i;
  }
  memset(head, -1, sizeof(head));
  for (int i = 1; i <= len; i++) {
    pred[i] = head[num[i]];
    head[num[i]] = i;
  }
}

LL Invpair(int *A) {
  LL re = 0;
  for (int i = 1; i <= len; i++) {
    re += (i - getsum(A[i] - 1) - 1);
    add(A[i], 1);
  }
  return re;
}

void solve() {
  int l, r;
  for (int i = 1; i <= len; i++) {
    if (!vis[i]) {
      l = i, r = head[num[i]];
      while (r != -1) {
        tmp[len - l + 1] = r;
        vis[l] = 1;
        l = succ[l];
        r = pred[r];
      }
    }
  }
  printf("%lld\n", Invpair(tmp) >> 1);
}

int main() {
  scanf("%s", S + 1);
  len = strlen(S + 1);
  for (int i = 1; i <= len; i++) {
    num[i] = S[i] - 'a' + 1;
    cnt[num[i]]++;
  }
  int odd = 0;
  for (int i = 1; i <= 26; i++)
    if (cnt[i] & 1)
      odd++;
  if (odd > 1) {
    puts("-1");
    return 0;
  }
  PRE();
  solve();
  return 0;
}

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

const int MAXN = 200000 + 9;
char S[MAXN];
int len;
int cnt[30];
int pred[MAXN], succ[MAXN], head[30];
int num[MAXN];
bool vis[MAXN];
int tmp[MAXN];
typedef long long LL;
int tree[MAXN];

int lowbit(int x) { return x & -x; }

void add(int pos, int val) {
  for (int i = pos; i <= len; i += lowbit(i))
    tree[i] += val;
}

LL getsum(int pos) {
  LL re = 0;
  for (int i = pos; i; i -= lowbit(i))
    re += tree[i];
  return re;
}

void PRE() {
  memset(head, -1, sizeof(head));
  for (int i = len; i; i--) {
    succ[i] = head[num[i]];
    head[num[i]] = i;
  }
  memset(head, -1, sizeof(head));
  for (int i = 1; i <= len; i++) {
    pred[i] = head[num[i]];
    head[num[i]] = i;
  }
}

LL Invpair(int *A) {
  LL re = 0;
  for (int i = 1; i <= len; i++) {
    re += (i - getsum(A[i] - 1) - 1);
    add(A[i], 1);
  }
  return re;
}

void solve() {
  int l, r;
  for (int i = 1; i <= len; i++) {
    if (!vis[i]) {
      l = i, r = head[num[i]];
      while (r != -1) {
        tmp[len - l + 1] = r;
        vis[l] = 1;
        l = succ[l];
        r = pred[r];
      }
    }
  }
  printf("%lld\n", Invpair(tmp) >> 1);
}

int main() {
  scanf("%s", S + 1);
  len = strlen(S + 1);
  for (int i = 1; i <= len; i++) {
    num[i] = S[i] - 'a' + 1;
    cnt[num[i]]++;
  }
  int odd = 0;
  for (int i = 1; i <= 26; i++)
    if (cnt[i] & 1)
      odd++;
  if (odd > 1) {
    puts("-1");
    return 0;
  }
  PRE();
  solve();
  return 0;
}
Problem p03483 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define N 100005
using namespace std;
int t[N];
char s[N];
int len;
int used[N];
vector<int> g[30];
void add(int x, int y) {
  for (; x <= len; x += x & (-x))
    t[x] += y;
}
int ask(int x) {
  int s = 0;
  for (; x; x -= x & (-x))
    s += t[x];
  return s;
}
int main() {
  scanf("%s", s + 1);
  len = strlen(s + 1);
  for (int i = 1; i <= len; i++)
    g[s[i] - 'a'].push_back(i);
  int tmp = 0;
  for (int i = 0; i < 26; i++)
    tmp += (g[i].size()) & 1;
  if (tmp > 1) {
    puts("-1");
    return 0;
  }
  for (int i = 1; i <= len; i++)
    add(i, 1);
  long long ans = 0;
  memset(used, 0, sizeof(used));
  for (int i = 1; i <= len; i++)
    if (!used[i]) {
      int ch = s[i] - 'a';
      int sz = g[ch].size();
      int u = g[ch][sz - 1];
      if (i == u)
        ans += (ask(len) - ask(i)) / 2;
      else
        ans += ask(len) - ask(u);
      add(u, -1);
      add(i, -1);
      used[i] = used[u] = 1;
      g[ch].erase(g[ch].end() - 1);
    }
  cout << ans;
}

Fixed submission:
#include <bits/stdc++.h>
#define N 200005
using namespace std;
int t[N];
char s[N];
int len;
int used[N];
vector<int> g[30];
void add(int x, int y) {
  for (; x <= len; x += x & (-x))
    t[x] += y;
}
int ask(int x) {
  int s = 0;
  for (; x; x -= x & (-x))
    s += t[x];
  return s;
}
int main() {
  scanf("%s", s + 1);
  len = strlen(s + 1);
  for (int i = 1; i <= len; i++)
    g[s[i] - 'a'].push_back(i);
  int tmp = 0;
  for (int i = 0; i < 26; i++)
    tmp += (g[i].size()) & 1;
  if (tmp > 1) {
    puts("-1");
    return 0;
  }
  for (int i = 1; i <= len; i++)
    add(i, 1);
  long long ans = 0;
  memset(used, 0, sizeof(used));
  for (int i = 1; i <= len; i++)
    if (!used[i]) {
      int ch = s[i] - 'a';
      int sz = g[ch].size();
      int u = g[ch][sz - 1];
      if (i == u)
        ans += (ask(len) - ask(i)) / 2;
      else
        ans += ask(len) - ask(u);
      add(u, -1);
      add(i, -1);
      used[i] = used[u] = 1;
      g[ch].erase(g[ch].end() - 1);
    }
  cout << ans;
}
Problem p03483 (C++)

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

using namespace std;

#define X first
#define Y second
typedef long long ll;
typedef pair<int, int> pii;

const int INF = 0x3f3f3f3f;
const int N = 1e5 + 500;

int n, nep;
int par[N], p[N];
char str[N];
vector<int> v[30];
ll F[N];

void update(int pos, ll val) {
  for (; pos <= n; pos += pos & -pos) {
    F[pos] += val;
  }
}

ll query(int pos) {
  ll res = 0;
  for (; pos > 0; pos -= pos & -pos) {
    res += F[pos];
  }
  return res;
}

int main() {
  scanf("%s", str);
  n = strlen(str);
  for (int i = 0; i < n; ++i) {
    v[str[i] - 'a'].push_back(i);
  }
  for (int i = 0; i < 26; ++i) {
    int l = 0, r = v[i].size() - 1;
    while (l < r) {
      par[v[i][l]] = v[i][r];
      par[v[i][r]] = v[i][l];
      l++;
      r--;
    }
    if (l == r) {
      ++nep;
      par[v[i][l]] = v[i][l];
    }
  }
  if (nep > 1) {
    printf("-1");
    return 0;
  }
  memset(p, -1, sizeof p);
  int l = 1, r = n;
  for (int i = 0; i < n; ++i) {
    if (p[i] != -1)
      continue;
    if (par[i] == i) {
      p[i] = n / 2 + 1;
      continue;
    }
    p[i] = l;
    p[par[i]] = r;
    l++;
    r--;
  }
  ll sol = 0;
  for (int i = 0; i < n; ++i) {
    // printf("%d ", p[i]);
    sol += (ll)i - query(p[i]);
    // printf("p[i]: %d, %lld\n", p[i], (ll)query(p[i]));
    update(p[i], 1LL);
  }
  printf("%lld", sol);
  return 0;
}


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

using namespace std;

#define X first
#define Y second
typedef long long ll;
typedef pair<int, int> pii;

const int INF = 0x3f3f3f3f;
const int N = 2e5 + 500;

int n, nep;
int par[N], p[N];
char str[N];
vector<int> v[30];
ll F[N];

void update(int pos, ll val) {
  for (; pos <= n; pos += pos & -pos) {
    F[pos] += val;
  }
}

ll query(int pos) {
  ll res = 0;
  for (; pos > 0; pos -= pos & -pos) {
    res += F[pos];
  }
  return res;
}

int main() {
  scanf("%s", str);
  n = strlen(str);
  for (int i = 0; i < n; ++i) {
    v[str[i] - 'a'].push_back(i);
  }
  for (int i = 0; i < 26; ++i) {
    int l = 0, r = v[i].size() - 1;
    while (l < r) {
      par[v[i][l]] = v[i][r];
      par[v[i][r]] = v[i][l];
      l++;
      r--;
    }
    if (l == r) {
      ++nep;
      par[v[i][l]] = v[i][l];
    }
  }
  if (nep > 1) {
    printf("-1");
    return 0;
  }
  memset(p, -1, sizeof p);
  int l = 1, r = n;
  for (int i = 0; i < n; ++i) {
    if (p[i] != -1)
      continue;
    if (par[i] == i) {
      p[i] = n / 2 + 1;
      continue;
    }
    p[i] = l;
    p[par[i]] = r;
    l++;
    r--;
  }
  ll sol = 0;
  for (int i = 0; i < n; ++i) {
    // printf("%d ", p[i]);
    sol += (ll)i - query(p[i]);
    // printf("p[i]: %d, %lld\n", p[i], (ll)query(p[i]));
    update(p[i], 1LL);
  }
  printf("%lld", sol);
  return 0;
}
Problem p03483 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 87;
char s[N];
deque<int> p[26];
int f[N];
void add(int i, int v) {
  for (; i < N; i += i & -i)
    f[i] += v;
}
int qry(int i) {
  int r = 0;
  for (; i; i ^= i & -i)
    r += f[i];
  return r;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> (s + 1);
  int n = strlen(s + 1);
  for (int i = 1; i <= n; ++i) {
    p[s[i] - 'a'].push_back(i);
    add(i, 1);
  }
  int mi = -1;
  for (int i = 0; i < 26; ++i)
    if (p[i].size() & 1) {
      if (mi != -1 || n % 2 == 0) {
        cout << "-1\n";
        return 0;
      }
      mi = i;
    }
  int l = 1;
  long long ans = 0;
  for (int i = 0; i < n / 2; ++i) {
    while (l != p[s[l] - 'a'].front() || p[s[l] - 'a'].size() == 1)
      ++l;
    auto &q = p[s[l] - 'a'];
    ans += qry(l - 1) + n - 2 * i - qry(q.back());
    add(l, -1);
    add(q.back(), -1);
    q.pop_front();
    q.pop_back();
  }
  cout << ans << '\n';
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 87;
char s[N];
deque<int> p[26];
int f[N];
void add(int i, int v) {
  for (; i < N; i += i & -i)
    f[i] += v;
}
int qry(int i) {
  int r = 0;
  for (; i; i ^= i & -i)
    r += f[i];
  return r;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> (s + 1);
  int n = strlen(s + 1);
  for (int i = 1; i <= n; ++i) {
    p[s[i] - 'a'].push_back(i);
    add(i, 1);
  }
  int mi = -1;
  for (int i = 0; i < 26; ++i)
    if (p[i].size() & 1) {
      if (mi != -1 || n % 2 == 0) {
        cout << "-1\n";
        return 0;
      }
      mi = i;
    }
  int l = 1;
  long long ans = 0;
  for (int i = 0; i < n / 2; ++i) {
    while (p[s[l] - 'a'].size() <= 1 || l != p[s[l] - 'a'].front())
      ++l;
    auto &q = p[s[l] - 'a'];
    ans += qry(l - 1) + n - 2 * i - qry(q.back());
    add(l, -1);
    add(q.back(), -1);
    q.pop_front();
    q.pop_back();
  }
  cout << ans << '\n';
}
Problem p03483 (C++)

Buggy submission (status: Runtime Error):
#include <cstdio>
#include <cstring>
#include <vector>
using namespace std;
const int N = 1e5 + 10;
char s[N];
vector<int> a[26];
int n, f[N], num[N];
long long ans;
inline int lowbit(int x) { return x & -x; }
inline void add(int x, int k) {
  while (x <= n) {
    f[x] += k;
    x += lowbit(x);
  }
  return;
}
inline int sum(int x) {
  int ans = 0;
  while (x) {
    ans += f[x];
    x -= lowbit(x);
  }
  return ans;
}
int main() {
  scanf("%s", s + 1);
  n = strlen(s + 1);
  for (int i = 1; i <= n; i++) {
    a[s[i] - 'a'].push_back(i);
    add(i, 1);
  }
  for (int i = 0; i < 26; i++)
    if (a[i].size() & 1)
      ans++;
  if (ans > 1) {
    puts("-1");
    return 0;
  } else
    ans = 0;
  for (int i = 0; i < 26; i++)
    for (int j = 0; j < (int)a[i].size(); j++)
      num[a[i][j]] = a[i][a[i].size() - j - 1];
  for (int i = 1; i <= n; i++) {
    ans += sum(n) - sum(num[i]);
    add(num[i], -1);
  }
  printf("%lld", ans >> 1);
  return 0;
}

Fixed submission:
#include <cstdio>
#include <cstring>
#include <vector>
using namespace std;
const int N = 2e5 + 10;
char s[N];
vector<int> a[26];
int n, f[N], num[N];
long long ans;
inline int lowbit(int x) { return x & -x; }
inline void add(int x, int k) {
  while (x <= n) {
    f[x] += k;
    x += lowbit(x);
  }
  return;
}
inline int sum(int x) {
  int ans = 0;
  while (x) {
    ans += f[x];
    x -= lowbit(x);
  }
  return ans;
}
int main() {
  scanf("%s", s + 1);
  n = strlen(s + 1);
  for (int i = 1; i <= n; i++) {
    a[s[i] - 'a'].push_back(i);
    add(i, 1);
  }
  for (int i = 0; i < 26; i++)
    if (a[i].size() & 1)
      ans++;
  if (ans > 1) {
    puts("-1");
    return 0;
  } else
    ans = 0;
  for (int i = 0; i < 26; i++)
    for (int j = 0; j < (int)a[i].size(); j++)
      num[a[i][j]] = a[i][a[i].size() - j - 1];
  for (int i = 1; i <= n; i++) {
    ans += sum(n) - sum(num[i]);
    add(num[i], -1);
  }
  printf("%lld", ans >> 1);
  return 0;
}
Problem p03483 (C++)

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

using namespace std;

typedef long long lli;
typedef vector<lli> vll;
typedef vector<bool> vbl;
typedef vector<vector<lli>> mat;
typedef vector<unordered_map<lli, lli>> graph;

string s;
vll b;
vll c;
vector<stack<lli>> idx;
lli ans;

class bit {
private:
  vll *v;
  lli n;

public:
  bit(lli n) {
    this->v = new vll(n + 1);
    this->n = n;
  }
  void add(lli i, lli val) {
    for (; i <= n; i += i & -i)
      this->v->at(i) += val;
  }
  lli sum(lli i) {
    lli ret = 0;
    for (; i > 0; i -= i & -i)
      ret += this->v->at(i);
    return ret;
  }
};

bit *cnt;

void error() {
  cout << -1 << endl;
  exit(0);
}

int main() {
  cin >> s;
  idx = vector<stack<lli>>(128);
  c = vll(128);
  b = vll(s.size());
  for (lli i = 0; i < s.size(); i++) {
    c[s[i]]++;
    b[i] = c[s[i]];
  }
  for (lli i = 0, j = 0; i < s.size(); i++) {
    if (c[s[i]] % 2 == 1 && b[i] == c[s[i]] / 2 + 1)
      b[i] = s.size() - 1;
    else if (b[i] > c[s[i]] / 2)
      b[i] = idx[s[i]].top(), idx[s[i]].pop();
    else
      idx[s[i]].push(++j), b[i] = s.size();
  }
  if (count(b.begin(), b.end(), s.size() - 1) > 1)
    error();
  reverse(b.begin(), b.end());
  cnt = new bit(s.size() + 1);
  for (lli i = 0; i < s.size(); i++) {
    ans += cnt->sum(s.size()) - cnt->sum(b[i]);
    cnt->add(b[i], 1);
  }
  cout << ans << endl;
  return 0;
}


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

using namespace std;

typedef long long lli;
typedef vector<lli> vll;
typedef vector<bool> vbl;
typedef vector<vector<lli>> mat;
typedef vector<unordered_map<lli, lli>> graph;

string s;
vll b;
vll c;
vector<stack<lli>> idx;
lli ans;

class bit {
private:
  vll *v;
  lli n;

public:
  bit(lli n) {
    this->v = new vll(n + 1);
    this->n = n;
  }
  void add(lli i, lli val) {
    for (; i <= n; i += i & -i)
      this->v->at(i) += val;
  }
  lli sum(lli i) {
    lli ret = 0;
    for (; i > 0; i -= i & -i)
      ret += this->v->at(i);
    return ret;
  }
};

bit *cnt;

void error() {
  cout << -1 << endl;
  exit(0);
}

int main() {
  cin >> s;
  if (s.size() == 1) {
    cout << 0 << endl;
    return 0;
  }
  idx = vector<stack<lli>>(128);
  c = vll(128);
  b = vll(s.size());
  for (lli i = 0; i < s.size(); i++) {
    c[s[i]]++;
    b[i] = c[s[i]];
  }
  for (lli i = 0, j = 0; i < s.size(); i++) {
    if (c[s[i]] % 2 == 1 && b[i] == c[s[i]] / 2 + 1)
      b[i] = s.size() - 1;
    else if (b[i] > c[s[i]] / 2)
      b[i] = idx[s[i]].top(), idx[s[i]].pop();
    else
      idx[s[i]].push(++j), b[i] = s.size();
  }
  if (count(b.begin(), b.end(), s.size() - 1) > 1)
    error();
  reverse(b.begin(), b.end());
  cnt = new bit(s.size() + 1);
  for (lli i = 0; i < s.size(); i++) {
    ans += cnt->sum(s.size()) - cnt->sum(b[i]);
    cnt->add(b[i], 1);
  }
  cout << ans << endl;
  return 0;
}
Problem p03483 (C++)

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

const int mx = 100005;
int memo[26][mx], sz, c[26], pr[mx], bit[mx * 2];
long long ans;
bool safe = true;
string s;

int main() {
  cin >> s;
  sz = s.size();
  for (int i = 0; i < sz; i++) {
    int t = s[i] - 'a';
    memo[t][c[t]++] = i;
  }
  for (int i = 0; i < 26; i++) {
    if (c[i] & 1) {
      if (safe)
        safe = false;
      else
        return puts("-1") * 0;
    }
    for (int j = 0; j < c[i]; j++)
      pr[memo[i][j]] = memo[i][c[i] - 1 - j];
  }
  for (int i = 0; i < sz; i++) {
    for (int j = pr[i] + 1; j > 0; j -= j & -j)
      ans += bit[j];
    for (int j = pr[i] + 1; j < mx * 2; j += j & -j)
      bit[j]++;
  }
  printf("%lld\n", ans / 2);
}

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

const int mx = 200005;
int memo[26][mx], sz, c[26], pr[mx], bit[mx * 2];
long long ans;
bool safe = true;
string s;

int main() {
  cin >> s;
  sz = s.size();
  for (int i = 0; i < sz; i++) {
    int t = s[i] - 'a';
    memo[t][c[t]++] = i;
  }
  for (int i = 0; i < 26; i++) {
    if (c[i] & 1) {
      if (safe)
        safe = false;
      else
        return puts("-1") * 0;
    }
    for (int j = 0; j < c[i]; j++)
      pr[memo[i][j]] = memo[i][c[i] - 1 - j];
  }
  for (int i = 0; i < sz; i++) {
    for (int j = pr[i] + 1; j > 0; j -= j & -j)
      ans += bit[j];
    for (int j = pr[i] + 1; j < mx * 2; j += j & -j)
      bit[j]++;
  }
  printf("%lld\n", ans / 2);
}
Problem p03483 (C++)

Buggy submission (status: Runtime Error):
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#define LL long long
using namespace std;
char s[200010];
int n, last[30], pos[30], tr[200010], num[30];
void change(int k, int c) {
  for (int i = k; i <= n; i += i & -i)
    tr[i] += c;
}
int get(int k) {
  int ans = 0;
  for (int i = k; i >= 1; i -= i & -i)
    ans += tr[i];
  return ans;
}
bool vis[200010];
int main() {
  scanf("%s", s + 1);
  n = strlen(s + 1);
  for (int i = 1; i <= n; i++) {
    int c = s[i] - 'a';
    num[c]++;
    pos[i] = last[c];
    last[c] = i;
  }
  int tot = 0;
  for (int i = 0; i < 26; i++)
    tot += (num[i] & 1);
  if (tot > 1)
    return puts("-1"), 0;
  memset(vis, false, sizeof(vis));
  LL ans = 0;
  for (int i = 1; i <= n; i++)
    change(i, 1);
  for (int i = 1; i <= n; i++)
    if (!vis[i]) {
      int c = s[i] - 'a';
      int j = last[c];
      last[c] = pos[j];
      if (i == j)
        continue;
      ans += get(i - 1);
      ans += (get(n) - get(j));
      change(i, -1);
      change(j, -1);
      vis[j] = true;
      // printf("%d %d %d %lld\n",i,j,get(n),ans);
    }
  printf("%lld", ans);
}

Fixed submission:
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#define LL long long
using namespace std;
char s[200010];
int n, last[30], pos[200010], tr[200010], num[30];
void change(int k, int c) {
  for (int i = k; i <= n; i += i & -i)
    tr[i] += c;
}
int get(int k) {
  int ans = 0;
  for (int i = k; i >= 1; i -= i & -i)
    ans += tr[i];
  return ans;
}
bool vis[200010];
int main() {
  scanf("%s", s + 1);
  n = strlen(s + 1);
  for (int i = 1; i <= n; i++) {
    int c = s[i] - 'a';
    num[c]++;
    pos[i] = last[c];
    last[c] = i;
  }
  int tot = 0;
  for (int i = 0; i < 26; i++)
    tot += (num[i] & 1);
  if (tot > 1)
    return puts("-1"), 0;
  memset(vis, false, sizeof(vis));
  LL ans = 0;
  for (int i = 1; i <= n; i++)
    change(i, 1);
  for (int i = 1; i <= n; i++)
    if (!vis[i]) {
      int c = s[i] - 'a';
      int j = last[c];
      last[c] = pos[j];
      if (i == j)
        continue;
      ans += get(i - 1);
      ans += (get(n) - get(j));
      change(i, -1);
      change(j, -1);
      vis[j] = true;
      // printf("%d %d %d %lld\n",i,j,get(n),ans);
    }
  printf("%lld", ans);
}
Problem p03485 (C++)

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

int main() {
  int a, b;
  cin >> a >> b;
  int X;
  X == a + b;
  if ((X / 2) % 0) {
    cout << X << endl;
  } else {
    cout << X / 2 + 1 << endl;
  }
}

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

int main() {
  int a, b;
  cin >> a >> b;
  int X;
  X = a + b + 1;
  cout << X / 2 << endl;
}
Problem p03485 (C++)

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

int main() {
  int a, b, c;
  cin >> a, b;
  c = (a + b) / c;
  cout << c << endl;
}

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

int main() {
  int a, b, c, d;
  cin >> a >> b;
  c = a % 2;
  d = b % 2;
  a = a + c;
  b = b + d;
  cout << ((a + b) / 2) - ((c + d) / 2) << endl;
}
Problem p03485 (C++)

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

int main() {
  int a;
  int b;

  cin >> a;
  cin >> b;

  cout << (a + b) / 2 + (a % b) / (a % b - 1) << endl;
}

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

int main() {
  int a;
  int b;

  cin >> a;
  cin >> b;

  cout << (a + b + 1) / 2 << endl;
}
Problem p03485 (C++)

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

#define pb push_back
#define pf push_front
#define ssort(e) sort(e.begin(), e.end())
#define ll long long int
#define ull unsigned long long

typedef vector<int> VII;
typedef vector<string> VSS;
typedef vector<char> VCC;
typedef pair<int, int> PII;
typedef vector<PII> VP;
typedef map<int, int> MII;
typedef stack<int> STI;
typedef queue<int> QUI;
typedef set<int> SII;
typedef set<char> SCC;

string to_String(double num) {
  ostringstream ss;
  ss << num;
  return ss.str();
}

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

  int a, b;
  cin >> a >> b;

  double x = (a + b) / 2;

  string s = to_String(x);

  if (s[s.size() - 1] - '0' < 5) {
    string ans = "";
    for (int i = 0; s[i] != '.'; i++) {
      ans += s[i];
    }
    cout << ans << endl;
  } else {
    cout << round(x) + 1 << endl;
  }

  return 0;
}


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

#define pb push_back
#define pf push_front
#define ssort(e) sort(e.begin(), e.end())
#define ll long long int
#define ull unsigned long long

typedef vector<int> VII;
typedef vector<string> VSS;
typedef vector<char> VCC;
typedef pair<int, int> PII;
typedef vector<PII> VP;
typedef map<int, int> MII;
typedef stack<int> STI;
typedef queue<int> QUI;
typedef set<int> SII;
typedef set<char> SCC;

string to_String(double num) {
  ostringstream ss;
  ss << num;
  return ss.str();
}

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

  int a, b;
  cin >> a >> b;

  cout << (a + b + 1) / 2 << endl;

  return 0;
}
Problem p03485 (C++)

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

int main() {
  int a, b;
  cin >> a >> b;
  cout << (a / 2) % (b / 2) + (a + b) / 2 << endl;
}

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

int main() {
  int a, b;
  cin >> a >> b;
  cout << (a + b + 1) / 2 << endl;
}
Problem p03485 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)

int main() {
  int a, b;
  cin >> a >> b;
  return (a + b + 1) / 2;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)

int main() {
  int a, b;
  cin >> a >> b;
  cout << (a + b + 1) / 2 << endl;
}
Problem p03485 (C++)

Buggy submission (status: Runtime Error):
#include <cstdio>
using namespace std;
int main() {
  int a, s, b;
  scanf("%d %d", a, b);
  s = a + b;
  if (s % 2 == 0) {
    s /= 2;
  } else {
    s /= 2;
    s += 1;
  }
  printf("%d", s);
}


Fixed submission:
#include <cstdio>
using namespace std;
int main() {
  int a, s, b;
  scanf("%d %d", &a, &b);
  s = a + b;
  if (s % 2 == 0) {
    s /= 2;
  } else {
    s /= 2;
    s += 1;
  }
  printf("%d", s);
}
Problem p03485 (Python)

Buggy submission (status: Runtime Error):
import math


def main():
    x, y = map(int, input())
    print(math.floor((x + y) / 2))


if __name__ == "__main__":
    main()


Fixed submission:
import math


def main():
    x, y = map(int, input().split())
    print(math.ceil((x + y) / 2))


if __name__ == "__main__":
    main()
Problem p03485 (Python)

Buggy submission (status: Runtime Error):
a, b = map(float, input().split())
print(int(round((a + b) / 2), 0))


Fixed submission:
a, b = map(float, input().split())
if int((a + b) / 2) < ((a + b) / 2):
    print(int((a + b) / 2) + 1)
else:
    print(int((a + b) / 2))
Problem p03485 (Python)

Buggy submission (status: Runtime Error):
from math import ceil

a, b = map(int, input())
print(ceil((a + b) / 2))


Fixed submission:
from math import ceil

a, b = map(int, input().split())
print(ceil((a + b) / 2))
Problem p03485 (C++)

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

int main() {
  int a, b;
  cout << (a + (b - 1)) / b << endl;
}

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

int main() {
  int a, b;
  cin >> a >> b;
  if ((a + b) % 2 == 0) {
    cout << (a + b) / 2 << endl;
  } else {
    int x = a + (b + 1);
    cout << x / 2 << endl;
  }
}
Problem p03486 (C++)

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

int main() {
  string s, t;
  cin >> s >> t;
  sort(s.begin(), s.end());
  sort(t.end(), t.begin());
  if (s < t) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

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

int main() {
  string s, t;
  cin >> s >> t;
  sort(s.begin(), s.end());
  sort(t.begin(), t.end(), greater<>());
  if (s < t) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}
Problem p03486 (C++)

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

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

  sort(s.begin(), s.end());
  sort(t.begin(), t.end());
  reverse(t.begin(), t.end());

  int si = s.size();
  int ti = t.size();
  bool che = true;
  for (int i = 0; i < si; i++) {
    if (s.at(i) < t.at(i))
      break;
    else if (s.at(i) > t.at(i)) {
      che = false;
      break;
    }
    if (s >= t)
      che = false;
  }
  if (s == t)
    che = false;
  if (che)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

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

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

  sort(s.begin(), s.end());
  sort(t.begin(), t.end());
  reverse(t.begin(), t.end());

  if (s < t)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}
Problem p03486 (C++)

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

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

  sort(s.begin(), s.end());
  sort(t.begin(), t.end(), greater<char>());

  if (s.at(0) < t.at(0)) {
    printf("Yes");
    return 0;
  }
  if (s.at(0) == t.at(0)) {
    for (int i = 0; i < s.size(); i++) {
      if (s.at(i) < t.at(i)) {
        printf("Yes");
        return 0;
      }
    }
  }
  if (s == t.substr(0, s.size()) && s.size() < t.size()) {
    printf("Yes");
    return 0;
  }
  printf("No");
  return 0;
}

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

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

  sort(s.begin(), s.end());
  sort(t.begin(), t.end(), greater<char>());

  if (s.at(0) < t.at(0)) {
    printf("Yes");
    return 0;
  }
  if (s.at(0) == t.at(0) && s.size() < t.size() && s.size() > 1) {
    for (int i = 1; i < s.size(); i++) {
      if (s.at(i) < t.at(i)) {
        printf("Yes");
        return 0;
      }
    }
  } else if (s.at(0) == t.at(0) && s.size() > t.size() && t.size() > 1) {
    for (int i = 1; i < t.size(); i++) {
      if (s.at(i) < t.at(i)) {
        printf("Yes");
        return 0;
      }
    }
  }
  if (s == t.substr(0, s.size()) && s.size() < t.size()) {
    printf("Yes");
    return 0;
  }
  printf("No");
  return 0;
}
Problem p03486 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define mini(vec) return *std::min_element(vec.begin(), vec.end());
#define maxi(vec) return *std::max_element(vec.begin(), vec.end());

int main() {
  string a, b;
  cin >> a >> b;
  sort(a.begin(), a.end());
  sort(b.end(), b.begin(), std::greater<int>());
  if (a < b) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


Fixed submission:
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define mini(vec) return *std::min_element(vec.begin(), vec.end());
#define maxi(vec) return *std::max_element(vec.begin(), vec.end());

int main() {
  string a, b;
  cin >> a >> b;
  sort(a.begin(), a.end());
  sort(b.begin(), b.end(), std::greater<int>());
  if (a < b) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}
Problem p03486 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
char s[101], t[101];
int main() {
  scanf("%s", s);
  scanf("%s", t);
  sort(s, s + strlen(s));
  sort(s, t + strlen(t), greater<char>());
  printf("%s", strcmp(s, t) < 0 ? "Yes" : "No");
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
char s[101], t[101];
int main() {
  scanf("%s", s);
  scanf("%s", t);
  sort(s, s + strlen(s));
  sort(t, t + strlen(t), greater<char>());
  printf("%s", strcmp(s, t) < 0 ? "Yes" : "No");
  return 0;
}
Problem p03486 (C++)

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

int main() {
  char s[10], t[10];
  string x, y;
  cin >> s >> t;
  sort(s, s + strlen(s));
  sort(t, t + strlen(t), greater<char>());
  x = s;
  y = t;
  if (x < y)
    cout << "Yes";
  else
    cout << "No";
}

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

int main() {
  char s[1000], t[1000];
  string x, y;
  cin >> s >> t;
  sort(s, s + strlen(s));
  sort(t, t + strlen(t), greater<char>());
  x = s;
  y = t;
  if (x < y)
    cout << "Yes";
  else
    cout << "No";
}
Problem p03486 (C++)

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

int main() {
  string s, t;
  cin >> s >> t;
  string x, y;
  do {
    x = s;
  } while (next_permutation(s.begin(), s.end()));
  do {
    y = t;
  } while (next_permutation(t.begin(), t.end()));
  reverse(x.begin(), x.end());
  if (x < y)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;

  return 0;
}

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

int main() {
  string s, t;
  cin >> s >> t;
  sort(s.begin(), s.end());
  sort(t.begin(), t.end());
  reverse(t.begin(), t.end());
  if (s < t)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;

  return 0;
}
Problem p03486 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
#define FOR(i, a) for (int i = 0; i < a; i++)
#define REP(i, a, b) for (int i = a; i < b; i++)
#define ll long long
using namespace std;
string a;
string b;
int main() {
  cin >> a >> b;
  sort(a.begin(), a.begin() + a.size());
  sort(b.begin(), b.begin() + a.size(), greater<char>());
  if (a < b)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
#define FOR(i, a) for (int i = 0; i < a; i++)
#define REP(i, a, b) for (int i = a; i < b; i++)
#define ll long long
using namespace std;
string a;
string b;
int main() {
  cin >> a >> b;
  sort(a.begin(), a.end());
  sort(b.begin(), b.end(), greater<char>());
  if (a < b)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}
Problem p03486 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <string>
using namespace std;
int main() {
  int lens, lent;
  char s[105], t[105], temp;
  while (~scanf("%s", &s + 1)) {
    scanf("%s", &t + 1);
    lens = strlen(s);
    lent = strlen(t);
    for (int i = 0; i < lens; i++) {
      for (int j = i; j < lens; j++) {
        if (s[i] > s[j]) {
          temp = s[i];
          s[i] = s[j];
          s[j] = temp;
        }
      }
    }
    for (int i = 0; i < lent; i++) {
      for (int j = i; j < lent; j++) {
        if (t[i] < t[j]) {
          temp = t[i];
          t[i] = t[j];
          t[j] = temp;
        }
      }
    }
    if (strcmp(s, t) < 0)
      printf("Yes\n");
    else
      printf("No\n");
    memset(s, 0, sizeof(s));
    memset(t, 0, sizeof(t));
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <string>
using namespace std;
int main() {
  int lens, lent;
  char s[105], t[105], temp;
  while (~scanf("%s", &s)) {
    scanf("%s", &t);
    lens = strlen(s);
    lent = strlen(t);
    for (int i = 0; i < lens; i++) {
      for (int j = i; j < lens; j++) {
        if (s[i] > s[j]) {
          temp = s[i];
          s[i] = s[j];
          s[j] = temp;
        }
      }
    }
    for (int i = 0; i < lent; i++) {
      for (int j = i; j < lent; j++) {
        if (t[i] < t[j]) {
          temp = t[i];
          t[i] = t[j];
          t[j] = temp;
        }
      }
    }
    if (strcmp(s, t) < 0)
      printf("Yes\n");
    else
      printf("No\n");
    memset(s, 0, sizeof(s));
    memset(t, 0, sizeof(t));
  }
  return 0;
}