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

Buggy submission (status: Time Limit Exceeded):
#define _USE_MAT_DEFINES
#include <algorithm>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;

int main() {
  long long N, M;
  cin >> N >> M;

  while (N < M / 2) {
    N++;
    M -= 2;
  }
  cout << M / 2 << endl;

  return 0;
}

Fixed submission:
#define _USE_MAT_DEFINES
#include <algorithm>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;

int main() {
  long long N, M;
  cin >> N >> M;

  if (N < M / 2)
    M -= ((M - 2 * N) + 1) / 2;
  cout << M / 2 << endl;

  return 0;
}
Problem p03797 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <climits>
#include <complex>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

// using
using namespace std;

// typedef
typedef long long ll;

// define
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REVERSE(c) reverse(ALL(c))
#define UNIQ(c) unique(ALL(c))
#define FOR(i, a, b, c) for (int i = (int)(a); i < (int)(b); i += (int)(c))
#define REP(i, n) FOR(i, 0, n, 1)
#define RFOR(i, a, b, c) for (int i = (int)(a); i >= (int)(b); i -= (int)(c))
#define RREP(i, n) RFOR(i, n, 0, 1)

// functions
template <class T> T ceil(T a, T b) { return (a + b - 1) / b; }
template <class T> T round(T a, T b) { return (a + b / 2) / b; }
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template <class T> T lcm(T a, T b) { return a * b / gcd(a, b); }
template <class T> bool amax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool amin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return true;
  }
  return false;
}

// main
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll N, M;
  cin >> N >> M;
  ll res = 0;
  while (N > 0 && M > 1) {
    N--;
    M -= 2;
    res++;
  }
  cout << res + M / 4 << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <climits>
#include <complex>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

// using
using namespace std;

// typedef
typedef long long ll;

// define
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REVERSE(c) reverse(ALL(c))
#define UNIQ(c) unique(ALL(c))
#define FOR(i, a, b, c) for (int i = (int)(a); i < (int)(b); i += (int)(c))
#define REP(i, n) FOR(i, 0, n, 1)
#define RFOR(i, a, b, c) for (int i = (int)(a); i >= (int)(b); i -= (int)(c))
#define RREP(i, n) RFOR(i, n, 0, 1)

// functions
template <class T> T ceil(T a, T b) { return (a + b - 1) / b; }
template <class T> T round(T a, T b) { return (a + b / 2) / b; }
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template <class T> T lcm(T a, T b) { return a * b / gcd(a, b); }
template <class T> bool amax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool amin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return true;
  }
  return false;
}

// main
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll N, M;
  cin >> N >> M;
  ll res = min(N, M / 2);
  cout << res + (M - res * 2) / 4 << endl;
  return 0;
}
Problem p03797 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
int main() {
  long n, m, ans = 0;
  cin >> n >> m;
  while (n >= 1 && m >= 2) {
    ans++;
    n--;
    m -= 2;
  }
  ans += m / 4;

  cout << ans << endl;

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  long n, m, ans = 0;
  cin >> n >> m;
  if (n >= m / 2) {
    ans += m / 2;
    m -= ans * 2;
  } else {
    ans += n;
    m -= ans * 2;
  }
  ans += m / 4;

  cout << ans << endl;

  return 0;
}
Problem p03797 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>    // bitset
#include <cctype>    // isupper, islower, isdigit, toupper, tolower
#include <cstdint>   // int64_t, int*_t
#include <cstdio>    // printf
#include <deque>     // deque
#include <iomanip>
#include <iostream> // cout, endl, cin
#include <map>      // map
#include <math.h>
#include <numeric>
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <string>        // string, to_string, stoi
#include <tuple>         // tuple, make_tuple
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <utility>       // pair, make_pair
#include <vector>        // vector
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++)
const int INF = 1001001001;
const int BG = 1000000007;

int main() {
  int64_t N, M;
  cin >> N >> M;
  int64_t ans = 0;
  while (true) {
    if (N <= 0) {
      break;
    }
    if (M >= 2) {
      ans++;
      N--;
      M -= 2;
    } else {
      break;
    }
  }
  ans += M / 4;

  cout << ans << endl;
}


Fixed submission:
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>    // bitset
#include <cctype>    // isupper, islower, isdigit, toupper, tolower
#include <cstdint>   // int64_t, int*_t
#include <cstdio>    // printf
#include <deque>     // deque
#include <iomanip>
#include <iostream> // cout, endl, cin
#include <map>      // map
#include <math.h>
#include <numeric>
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <string>        // string, to_string, stoi
#include <tuple>         // tuple, make_tuple
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <utility>       // pair, make_pair
#include <vector>        // vector
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++)
const int INF = 1001001001;
const int BG = 1000000007;

int main() {
  int64_t N, M;
  cin >> N >> M;
  int64_t ans = 0;
  ans = min(N, M / 2);
  N -= ans;
  M -= ans * 2;
  ans += M / 4;

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

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

int main(void) {
  int n;
  cin >> n;
  string ox;
  cin >> ox;
  ox += ox;
  vector<int> ss(n + 2);
  ss[0] = 1;
  ss[1] = 1;

  for (int j = 0; j < 4; j++) {

    for (int i = 2; i <= n + 2; i++) {
      if (ss[i - 1] == 1) {
        if (ox[i - 1] == 'o') {
          ss[i] = ss[i - 2];
        } else {
          ss[i] = ss[i - 2] * (-1);
        }
      } else {
        if (ox[i - 1] == 'o') {
          ss[i] = ss[i - 2] * (-1);
        } else {
          ss[i] = ss[i - 2];
        }
      }
    }

    if (ss[0] == ss[n] and ss[1] == ss[n + 1]) {
      for (int i = 0; i < n; i++) {
        if (ss[i] == 1)
          cout << 'S';
        else
          cout << 'W';
      }
      cout << endl;
      return 0;
    }

    if (j % 2 == 0)
      ss[0] *= (-1);
    else
      ss[1] *= (-1);
  }
  cout << -1 << endl;
  return 0;
}


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

int main(void) {
  int n;
  cin >> n;
  string ox;
  cin >> ox;
  ox += ox;
  vector<int> ss(n + 2);
  ss[0] = 1;
  ss[1] = 1;

  for (int j = 0; j < 4; j++) {
    for (int i = 2; i <= n + 1; i++) {
      if (ss[i - 1] == 1) {
        if (ox[i - 1] == 'o') {
          ss[i] = ss[i - 2];
        } else {
          ss[i] = ss[i - 2] * (-1);
        }
      } else {
        if (ox[i - 1] == 'o') {
          ss[i] = ss[i - 2] * (-1);
        } else {
          ss[i] = ss[i - 2];
        }
      }
    }

    if (ss[0] == ss[n] and ss[1] == ss[n + 1]) {
      for (int i = 0; i < n; i++) {
        if (ss[i] == 1)
          cout << 'S';
        else
          cout << 'W';
      }
      cout << endl;
      return 0;
    }

    if (j % 2 == 0)
      ss[0] *= (-1);
    else
      ss[1] *= (-1);
  }
  cout << -1 << endl;
  return 0;
}
Problem p03798 (C++)

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

using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define MIN(a, b) ((a) > (b) ? (b) : (a))
#define MAX(a, b) ((a) < (b) ? (b) : (a))

const long long INF = 1LL << 60;
typedef unsigned long long ll;
const long long MOD = 1000000000 + 7;

int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  char res[n + 2];
  rep(i, n + 1) {
    rep(j, n + 1) res[j] = 'N';
    if (i % 2 == 0)
      res[0] = 'S';
    else
      res[0] = 'W';
    if (i / 2 == 0)
      res[1] = 'S';
    else
      res[1] = 'W';
    rep(j, n) {
      char bs = res[j];
      char ns = res[j + 1];
      if (bs == 'S' && ns == 'S') {
        if (s[j] == 'o')
          res[j + 2] = 'S';
        else
          res[j + 2] = 'W';
      } else if (bs == 'S' && ns == 'W') {
        if (s[j] == 'o')
          res[j + 2] = 'W';
        else
          res[j + 2] = 'S';
      } else if (bs == 'W' && ns == 'S') {
        if (s[j] == 'o')
          res[j + 2] = 'W';
        else
          res[j + 2] = 'S';
      } else if (bs == 'W' && ns == 'W') {
        if (s[j] == 'o')
          res[j + 2] = 'S';
        else
          res[j + 2] = 'W';
      }
    }
    if (res[n] == res[0] && res[n + 1] == res[1]) {
      for (int j = 1; j < n + 1; j++)
        cout << res[j];
      cout << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}

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

using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define MIN(a, b) ((a) > (b) ? (b) : (a))
#define MAX(a, b) ((a) < (b) ? (b) : (a))

const long long INF = 1LL << 60;
typedef unsigned long long ll;
const long long MOD = 1000000000 + 7;

int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  rep(i, 4) {
    char res[n + 2];
    if (i % 2 == 0)
      res[0] = 'S';
    else
      res[0] = 'W';
    if (i / 2 == 0)
      res[1] = 'S';
    else
      res[1] = 'W';
    rep(j, n) {
      char bs = res[j];
      char ns = res[j + 1];
      if (bs == 'S' && ns == 'S') {
        if (s[j] == 'o')
          res[j + 2] = 'S';
        else
          res[j + 2] = 'W';
      } else if (bs == 'S' && ns == 'W') {
        if (s[j] == 'o')
          res[j + 2] = 'W';
        else
          res[j + 2] = 'S';
      } else if (bs == 'W' && ns == 'S') {
        if (s[j] == 'o')
          res[j + 2] = 'W';
        else
          res[j + 2] = 'S';
      } else if (bs == 'W' && ns == 'W') {
        if (s[j] == 'o')
          res[j + 2] = 'S';
        else
          res[j + 2] = 'W';
      }
    }
    if (res[n] == res[0] && res[n + 1] == res[1]) {
      for (int j = 1; j < n + 1; j++)
        cout << res[j];
      cout << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
Problem p03798 (C++)

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

using namespace std;
typedef long long ll;
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;
}

int main() {
  int N;
  cin >> N;
  string S1;
  cin >> S1;
  string S = S1 + S1;

  vector<int> res(N, 0);
  // 0...羊 1...狼
  for (int k = 0; k < 4; k++) {
    for (int i = 0; i < 2 * N; i++)
      res[i] = 0;
    res[0] = k & 1;
    res[1] = (k & 2) / 2;

    for (int i = 2; i < N; i++) {
      if (S[i - 1] == 'o')
        res[i] = res[i - 2] ^ res[i - 1];
      else
        res[i] = !(res[i - 2] ^ res[i - 1]);
    }
    bool flag = true;

    if (S[0] == 'o' && (res[1] != res[N - 1] ^ res[0]))
      flag = false;
    if (S[0] == 'x' && (res[1] == res[N - 1] ^ res[0]))
      flag = false;
    if (S[N - 1] == 'o' && (res[0] != res[N - 2] ^ res[N - 1]))
      flag = false;
    if (S[N - 1] == 'x' && (res[0] == res[N - 2] ^ res[N - 1]))
      flag = false;

    if (flag) {
      for (int i = 0; i < N; i++) {
        if (res[i] == 0)
          cout << 'S';
        else
          cout << 'W';
      }
      cout << endl;
      return 0;
    }
  }
  cout << "-1\n";
}

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

using namespace std;
typedef long long ll;
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;
}

int main() {
  int N;
  cin >> N;
  string S1;
  cin >> S1;
  string S = S1 + S1;

  vector<int> res(2 * N, 0);
  // 0...羊 1...狼
  for (int k = 0; k < 4; k++) {
    for (int i = 0; i < 2 * N; i++)
      res[i] = 0;
    res[0] = k & 1;
    res[1] = (k & 2) / 2;

    for (int i = 2; i < N; i++) {
      if (S[i - 1] == 'o')
        res[i] = res[i - 2] ^ res[i - 1];
      else
        res[i] = !(res[i - 2] ^ res[i - 1]);
    }
    bool flag = true;

    if (S[0] == 'o' && (res[1] != res[N - 1] ^ res[0]))
      flag = false;
    if (S[0] == 'x' && (res[1] == res[N - 1] ^ res[0]))
      flag = false;
    if (S[N - 1] == 'o' && (res[0] != res[N - 2] ^ res[N - 1]))
      flag = false;
    if (S[N - 1] == 'x' && (res[0] == res[N - 2] ^ res[N - 1]))
      flag = false;

    if (flag) {
      for (int i = 0; i < N; i++) {
        if (res[i] == 0)
          cout << 'S';
        else
          cout << 'W';
      }
      cout << endl;
      return 0;
    }
  }
  cout << "-1\n";
}
Problem p03798 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <vector>
#define N 1009
using namespace std;
const int INF = 0x3f3f3f3f;
char s[N];
int ans[N];
int nx[4] = {1, 1, 0, 0};
int ny[4] = {1, 0, 0, 1};

bool check(int a, int b, int n) {
  ans[0] = a;
  ans[1] = b;
  for (int i = 1; i < n - 1; i++) {
    if (s[i] == 'o') {
      if (ans[i])
        ans[i + 1] = ans[i - 1];
      else
        ans[i + 1] = !ans[i - 1];
    } else {
      if (ans[i])
        ans[i + 1] = !ans[i - 1];
      else
        ans[i + 1] = ans[i - 1];
    }
  }
  if (s[0] == 'o') {
    if (ans[0]) {
      if (ans[1] != ans[n - 1])
        return false;
    } else if (ans[1] == ans[n - 1])
      return false;
  } else {
    if (ans[0]) {
      if (ans[1] == ans[n - 1])
        return false;
    } else if (ans[1] != ans[n - 1])
      return false;
  }
  if (s[n - 1] == 'o') {
    if (ans[n - 1]) {
      if (ans[0] != ans[n - 2])
        return false;
    } else if (ans[0] == ans[n - 2])
      return false;
  } else {
    if (ans[n - 1]) {
      if (ans[0] == ans[n - 2])
        return false;
    } else if (ans[0] != ans[n - 2])
      return false;
  }
  return true;
}

int main() {
  int n;
  scanf("%d %s", &n, s);
  for (int i = 0; i < 4; i++) {
    if (check(nx[i], ny[i], n)) {
      for (int i = 0; i < n; i++) {
        if (ans[i])
          printf("S");
        else
          printf("W");
      }
      printf("\n");
      exit(0);
    }
  }
  puts("-1");
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <vector>
#define N 100009
using namespace std;
const int INF = 0x3f3f3f3f;
char s[N];
int ans[N];
int nx[4] = {1, 1, 0, 0};
int ny[4] = {1, 0, 0, 1};

bool check(int a, int b, int n) {
  ans[0] = a;
  ans[1] = b;
  for (int i = 1; i < n - 1; i++) {
    if (s[i] == 'o') {
      if (ans[i])
        ans[i + 1] = ans[i - 1];
      else
        ans[i + 1] = !ans[i - 1];
    } else {
      if (ans[i])
        ans[i + 1] = !ans[i - 1];
      else
        ans[i + 1] = ans[i - 1];
    }
  }
  if (s[0] == 'o') {
    if (ans[0]) {
      if (ans[1] != ans[n - 1])
        return false;
    } else if (ans[1] == ans[n - 1])
      return false;
  } else {
    if (ans[0]) {
      if (ans[1] == ans[n - 1])
        return false;
    } else if (ans[1] != ans[n - 1])
      return false;
  }
  if (s[n - 1] == 'o') {
    if (ans[n - 1]) {
      if (ans[0] != ans[n - 2])
        return false;
    } else if (ans[0] == ans[n - 2])
      return false;
  } else {
    if (ans[n - 1]) {
      if (ans[0] == ans[n - 2])
        return false;
    } else if (ans[0] != ans[n - 2])
      return false;
  }
  return true;
}

int main() {
  int n;
  scanf("%d %s", &n, s);
  for (int i = 0; i < 4; i++) {
    if (check(nx[i], ny[i], n)) {
      for (int i = 0; i < n; i++) {
        if (ans[i])
          printf("S");
        else
          printf("W");
      }
      printf("\n");
      exit(0);
    }
  }
  puts("-1");
  return 0;
}
Problem p03798 (C++)

Buggy submission (status: Runtime Error):
#include <cstdio>
#include <iostream>
using namespace std;
char ans[10010], spe[10010];
int n;
bool c(char l) {
  switch (l) {
  case 'o':
    return true;
  case 'x':
    return false;
  case 'S':
    return true;
  case 'W':
    return false;
  }
}
char c(bool l) { return (l ? 'S' : 'W'); }
char func(int i, int j) { return (c((c(spe[i]) == c(ans[i])) == (c(spe[j])))); }
bool comp(char f, char s) {
  int i;
  spe[0] = f;
  spe[1] = s;
  for (i = 2; i < n; i++) {
    spe[i] = func(i - 1, i - 2);
  }
  return (func(n - 1, n - 2) == spe[0] && func(0, n - 1) == spe[1]);
}
int main() {
  cin >> n >> ans;
  if (comp('S', 'S')) {
    cout << spe;
    return 0;
  }
  if (comp('S', 'W')) {
    cout << spe;
    return 0;
  }
  if (comp('W', 'S')) {
    cout << spe;
    return 0;
  }
  if (comp('W', 'W')) {
    cout << spe;
    return 0;
  }
  cout << "-1";
  return 0;
}


Fixed submission:
#include <cstdio>
#include <iostream>
using namespace std;
char ans[100010], spe[100010];
int n;
bool c(char l) {
  switch (l) {
  case 'o':
    return true;
  case 'x':
    return false;
  case 'S':
    return true;
  case 'W':
    return false;
  }
}
char c(bool l) { return (l ? 'S' : 'W'); }
char func(int i, int j) { return (c((c(spe[i]) == c(ans[i])) == (c(spe[j])))); }
bool comp(char f, char s) {
  int i;
  spe[0] = f;
  spe[1] = s;
  for (i = 2; i < n; i++) {
    spe[i] = func(i - 1, i - 2);
  }
  return (func(n - 1, n - 2) == spe[0] && func(0, n - 1) == spe[1]);
}
int main() {
  cin >> n >> ans;
  if (comp('S', 'S')) {
    cout << spe;
    return 0;
  }
  if (comp('S', 'W')) {
    cout << spe;
    return 0;
  }
  if (comp('W', 'S')) {
    cout << spe;
    return 0;
  }
  if (comp('W', 'W')) {
    cout << spe;
    return 0;
  }
  cout << "-1";
  return 0;
}
Problem p03798 (C++)

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

int main(void) {
  int n;
  string ox;
  cin >> n >> ox;
  vector<int> ss(n);

  for (auto a0 : {-1, 1})
    for (auto a1 : {-1, 1}) {
      ss[0] = a0;
      ss[1] = a1;

      for (int i = 2; i <= n + 1; i++) {
        bool c1 = ss[(i - 1) % n] == 1, c2 = ox[i - 1] == 'x';
        ss[i] = ss[i - 2] * (c1 xor c2 ? 1 : -1);
      }

      if (ss[0] == a0 and ss[1] == a1) {
        for (int i = 0; i < n; i++) {
          cout << (ss[i] == 1 ? 'S' : 'W');
        }
        cout << endl;
        return 0;
      }
    }
  cout << -1 << endl;
}


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

int main(void) {
  int n;
  string ox;
  cin >> n >> ox;
  vector<int> ss(n);

  for (auto a0 : {-1, 1})
    for (auto a1 : {-1, 1}) {
      ss[0] = a0;
      ss[1] = a1;

      for (int i = 2; i <= n + 1; i++) {
        bool c1 = ss[(i - 1) % n] == 1, c2 = ox[(i - 1) % n] == 'x';
        ss[i % n] = ss[(i - 2) % n] * (c1 xor c2 ? 1 : -1);
      }

      if (ss[0] == a0 and ss[1] == a1) {
        for (int i = 0; i < n; i++) {
          cout << (ss[i] == 1 ? 'S' : 'W');
        }
        cout << endl;
        return 0;
      }
    }
  cout << -1 << endl;
}
Problem p03798 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h> //Menagerie
using namespace std;
char dat[10005];
bool zz[100005];
int main() {
  int n;
  scanf("%d%s", &n, dat);
  dat[0];
  for (int i = 0; i < 2; i++) {
    for (int j = 0; j < 2; j++) {
      zz[0] = i;
      zz[1] = j;
      for (int k = 1; k < n - 1; k++) {
        zz[k + 1] = zz[k - 1] ^ zz[k] ^ (dat[k] == 'x');
      }
      if ((dat[n - 1] == 'x') == zz[n - 2] ^ zz[n - 1] ^ zz[0] &&
          (dat[0] == 'x') == (zz[n - 1] ^ zz[0] ^ zz[1])) {
        for (int k = 0; k < n; k++) {
          printf("%c", zz[k] ? 'W' : 'S');
        }
        printf("\n");
        return 0;
      }
    }
  }
  printf("-1\n");
  return 0;
}

Fixed submission:
#include <bits/stdc++.h> //Menagerie
using namespace std;
char dat[100005];
bool zz[100005];
int main() {
  int n;
  scanf("%d%s", &n, dat);
  dat[0];
  for (int i = 0; i < 2; i++) {
    for (int j = 0; j < 2; j++) {
      zz[0] = i;
      zz[1] = j;
      for (int k = 1; k < n - 1; k++) {
        zz[k + 1] = zz[k - 1] ^ zz[k] ^ (dat[k] == 'x');
      }
      if ((dat[n - 1] == 'x') == zz[n - 2] ^ zz[n - 1] ^ zz[0] &&
          (dat[0] == 'x') == (zz[n - 1] ^ zz[0] ^ zz[1])) {
        for (int k = 0; k < n; k++) {
          printf("%c", zz[k] ? 'W' : 'S');
        }
        printf("\n");
        return 0;
      }
    }
  }
  printf("-1\n");
  return 0;
}
Problem p03798 (C++)

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

#define rep2(x, fr, to) for (int(x) = (fr); (x) < (to); (x)++)
#define rep(x, to) for (int(x) = 0; (x) < (to); (x)++)
#define repr(x, fr, to) for (int(x) = (fr); (x) >= (to); (x)--)
#define all(c) (c).begin(), (c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef pair<int, int> pii;
const int MD = (int)1e9 + 7;
typedef vector<ll> VL;
void dbg() { cerr << "\n"; }
template <class T, class... T2> void dbg(const T &fst, const T2 &...rst) {
  cerr << fst << ": ";
  dbg(rst...);
}
template <class T, class T2> void amin(T &a, T2 b) {
  if (a > b)
    a = b;
}

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int n;
  string s;
  cin >> n >> s;
  VI sd(n);
  rep(i, 2 * n) sd[i] = s[i % n] == 'o' ? 0 : 1;
  rep(i, 4) {
    VI ck(2 * n + 2, -1);
    ck[0] = i & 1;
    ck[1] = (i >> 1) & 1;
    rep2(i, 1, 2 * n) {
      if (ck[i] == sd[i])
        ck[i + 1] = ck[i - 1];
      else
        ck[i + 1] = ck[i - 1] ^ 1;
    }

    bool ok = true;
    rep(i, n) if (ck[i] != ck[i + n]) ok = false;
    // for(auto x :ck) cerr<<x<<" "; dbg("::", ok);
    if (ok) {
      rep(i, n) cout << (ck[i] == 0 ? 'S' : 'W');
      cout << "\n";
      return 0;
    }
  }
  puts("-1");
  return 0;
}


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

#define rep2(x, fr, to) for (int(x) = (fr); (x) < (to); (x)++)
#define rep(x, to) for (int(x) = 0; (x) < (to); (x)++)
#define repr(x, fr, to) for (int(x) = (fr); (x) >= (to); (x)--)
#define all(c) (c).begin(), (c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef pair<int, int> pii;
const int MD = (int)1e9 + 7;
typedef vector<ll> VL;
void dbg() { cerr << "\n"; }
template <class T, class... T2> void dbg(const T &fst, const T2 &...rst) {
  cerr << fst << ": ";
  dbg(rst...);
}
template <class T, class T2> void amin(T &a, T2 b) {
  if (a > b)
    a = b;
}

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int n;
  string s;
  cin >> n >> s;
  VI sd(2 * n);
  rep(i, 2 * n) sd[i] = s[i % n] == 'o' ? 0 : 1;
  rep(i, 4) {
    VI ck(2 * n + 2, -1);
    ck[0] = i & 1;
    ck[1] = (i >> 1) & 1;
    rep2(i, 1, 2 * n) {
      if (ck[i] == sd[i])
        ck[i + 1] = ck[i - 1];
      else
        ck[i + 1] = ck[i - 1] ^ 1;
    }

    bool ok = true;
    rep(i, n) if (ck[i] != ck[i + n]) ok = false;
    // for(auto x :ck) cerr<<x<<" "; dbg("::", ok);
    if (ok) {
      rep(i, n) cout << (ck[i] == 0 ? 'S' : 'W');
      cout << "\n";
      return 0;
    }
  }
  puts("-1");
  return 0;
}
Problem p03798 (C++)

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

#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define per(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define pb push_back
#define mp make_pair
#define bg begin()
#define en end()
#define all(v) (v).begin(), (v).end()
#define sz(v) (int)(v).size()

using namespace std;

typedef long long ll;

static const long long MOD = 1000000007;
static const long long INF = 1 << 31;

string s;
int n, dp[100][4];

int main(void) {
  cin >> n >> s;

  for (int i = 0; i <= 1; i++)
    for (int j = 0; j <= 3; j++)
      dp[i][j] = (j >> i) & 1;

  for (int i = 1; i < n - 1; i++)
    for (int j = 0; j <= 3; j++) {
      dp[i + 1][j] = (dp[i - 1][j] + dp[i][j] + (s[i] == 'o' ? 1 : 0)) % 2;
    }

  int idx = -1;
  for (int i = 0; i <= 3; i++) {
    if (((dp[n - 2][i] + dp[n - 1][i] + (s[n - 1] == 'o' ? 1 : 0)) % 2 ==
         dp[0][i]) &&
        (dp[0][i] + dp[1][i] + (s[0] == 'o' ? 1 : 0)) % 2 == dp[n - 1][i])
      idx = i;
  }

  if (idx == -1) {
    puts("-1");
    return 0;
  }

  for (int i = 0; i < n; i++) {
    if (dp[i][idx])
      printf("S");
    else
      printf("W");
  }

  printf("\n");

  // cout << ans << "\n";

  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define per(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define pb push_back
#define mp make_pair
#define bg begin()
#define en end()
#define all(v) (v).begin(), (v).end()
#define sz(v) (int)(v).size()

using namespace std;

typedef long long ll;

static const long long MOD = 1000000007;
static const long long INF = 1 << 31;

string s;
int n, dp[100005][4];

int main(void) {
  cin >> n >> s;

  for (int i = 0; i <= 1; i++)
    for (int j = 0; j <= 3; j++)
      dp[i][j] = (j >> i) & 1;

  for (int i = 1; i < n - 1; i++)
    for (int j = 0; j <= 3; j++) {
      dp[i + 1][j] = (dp[i - 1][j] + dp[i][j] + (s[i] == 'o' ? 1 : 0)) % 2;
    }

  int idx = -1;
  for (int i = 0; i <= 3; i++) {
    if (((dp[n - 2][i] + dp[n - 1][i] + (s[n - 1] == 'o' ? 1 : 0)) % 2 ==
         dp[0][i]) &&
        (dp[0][i] + dp[1][i] + (s[0] == 'o' ? 1 : 0)) % 2 == dp[n - 1][i])
      idx = i;
  }

  if (idx == -1) {
    puts("-1");
    return 0;
  }

  for (int i = 0; i < n; i++) {
    if (dp[i][idx])
      printf("S");
    else
      printf("W");
  }

  printf("\n");

  // cout << ans << "\n";

  return 0;
}
Problem p03798 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;
#define M 10009

int N;
string s;
char ox[M];
char sw[M];

char inv(char c) { return c == 'S' ? 'W' : 'S'; }
int main() {
  cin >> N >> s;
  for (int i = 0; i < N; i++) {
    ox[i] = s.at(i);
  }
  ox[N] = ox[0];
  ox[N + 1] = ox[1];
  char init[2][4] = {{'S', 'S', 'W', 'W'}, {'S', 'W', 'S', 'W'}};
  for (int I = 0; I < 4; I++) {
    sw[0] = init[0][I];
    sw[1] = init[1][I];
    for (int i = 2; i <= N + 1; i++) {
      sw[i] = (sw[i - 1] == 'S')
                  ? (ox[i - 1] == 'o' ? sw[i - 2] : inv(sw[i - 2]))
                  : (ox[i - 1] == 'o' ? inv(sw[i - 2]) : sw[i - 2]);
    }
    if (sw[0] == sw[N] && sw[1] == sw[N + 1]) {
      for (int i = 0; i < N; i++) {
        cout << sw[i];
      }
      cout << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}

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

int N;
string s;
char ox[M];
char sw[M];

char inv(char c) { return c == 'S' ? 'W' : 'S'; }
int main() {
  cin >> N >> s;
  for (int i = 0; i < N; i++) {
    ox[i] = s.at(i);
  }
  ox[N] = ox[0];
  ox[N + 1] = ox[1];
  char init[2][4] = {{'S', 'S', 'W', 'W'}, {'S', 'W', 'S', 'W'}};
  for (int I = 0; I < 4; I++) {
    sw[0] = init[0][I];
    sw[1] = init[1][I];
    for (int i = 2; i <= N + 1; i++) {
      sw[i] = (sw[i - 1] == 'S')
                  ? (ox[i - 1] == 'o' ? sw[i - 2] : inv(sw[i - 2]))
                  : (ox[i - 1] == 'o' ? inv(sw[i - 2]) : sw[i - 2]);
    }
    if (sw[0] == sw[N] && sw[1] == sw[N + 1]) {
      for (int i = 0; i < N; i++) {
        cout << sw[i];
      }
      cout << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
Problem p03799 (Python)

Buggy submission (status: Time Limit Exceeded):
n, m = map(int, input().split())

cnt = 0
for _ in range(n):
    if m >= 2:
        m -= 2
        cnt += 1
for _ in range(m // 4):
    if m >= 4:
        m -= 4
        cnt += 1
print(cnt)


Fixed submission:
n, m = map(int, input().split())

cnt = min(n, m // 2)
print(cnt + (m - cnt * 2) // 4)
Problem p03799 (C++)

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

#define ll long long
#define vecll vector<long long>
#define vec2ll vector<vector<long long>>
#define vecbool vector<bool>
#define vecpairll vector<pair<long long, long long>>
#define forll(s, a, b) for (long long s = a; s < b; s++)
#define forllde(s, a) for (long long s = a; s > 0; s--)

int main() {
  ll n, m, c = 0;
  cin >> n >> m;
  forll(i, 0, n) {
    if (m < 2) {
      break;
    }
    m -= 2;
    c++;
  }
  while (m >= 4) {
    m -= 4;
    c++;
  }

  cout << c << endl;
}


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

#define ll long long
#define vecll vector<long long>
#define vec2ll vector<vector<long long>>
#define vecbool vector<bool>
#define vecpairll vector<pair<long long, long long>>
#define forll(s, a, b) for (long long s = a; s < b; s++)
#define forllde(s, a) for (long long s = a; s > 0; s--)

int main() {
  ll n, m, c = 0;
  cin >> n >> m;
  c = min(n, m / 2);
  m -= c * 2;
  c += m / 4;
  cout << c << endl;
}
Problem p03799 (C++)

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

using lint = long long;

lint s, c;

lint f(lint x) { return min(s + x, (c - 2 * x) / 2); }

int main() {
  cin >> s >> c;

  lint l = 0, r = 1e12;

  while (r - l > 2) {
    lint m1 = (l * 2 + r) / 3, m2 = (l + 2 * r) / 3;

    if (f(m1) < f(m2))
      l = m1;
    else
      r = m2;
  }

  lint ans = 0;

  for (int i = l; i <= r; i++) {
    ans = max(ans, f(i));
  }

  cout << ans << '\n';
}

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

using lint = long long;

lint s, c;

lint f(lint x) { return min(s + x, (c - 2 * x) / 2); }

int main() {
  cin >> s >> c;

  lint l = 0, r = 1e12;

  while (r - l > 2) {
    lint m1 = (l * 2 + r) / 3, m2 = (l + 2 * r) / 3;

    if (f(m1) < f(m2))
      l = m1;
    else
      r = m2;
  }

  lint ans = 0;

  for (lint i = l; i <= r; i++) {
    ans = max(ans, f(i));
  }

  cout << ans << '\n';
}
Problem p03799 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define rep(i, n) for (int(i) = 0; (i) < (n); i++)
#define ll long long
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;

int main() {
  ll N = 0, M = 0;
  cin >> N >> M;
  if (N == 0 || M < 2) {
    cout << "0";
    return 0;
  }
  while (1) {
    if (N * 2 >= M) {
      cout << M / 2;
      return 0;
    }
    N++;
    M -= 2;
  }
}


Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int(i) = 0; (i) < (n); i++)
#define ll long long
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;

int main() {
  ll N = 0, M = 0;
  cin >> N >> M;
  if (N == 0 || M < 2) {
    cout << "0";
    return 0;
  }
  while (1) {
    if (N * 2 >= M) {
      cout << M / 2;
      return 0;
    }
    if (M > 1000000000) {
      N += 5000;
      M -= 10000;
      continue;
    }
    N++;
    M -= 2;
  }
}
Problem p03799 (C++)

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

using namespace std;

int main() {
  long long n, m;
  cin >> n >> m;
  long long now = 0;
  long long ans = 0;
  for (int i = 0; i < m / 2; i++) {
    now = min(n, m / 2);
    ans = max(now, ans);
    n++;
    m -= 2;
  }
  cout << ans << endl;
}


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

using namespace std;

int main() {
  long long n, m;
  cin >> n >> m;
  if (n >= m / 2)
    cout << m / 2 << endl;
  else
    cout << (m - n * 2) / 4 + n << endl;
}
Problem p03799 (C++)

Buggy submission (status: Time Limit Exceeded):
#include "bits/stdc++.h"
using namespace std;
#define rep(i, a, n) for (int i = a; i < n; i++)
#define ALL(s) s.begin(), s.end()
const int M = 100010;
int INF = 1000000007;
using ll = long long;

int main() {
  ll n, m, ans;
  cin >> n >> m;
  while (n < m / 2) {
    n++, m -= 2;
  }
  ans = min(n, m / 2);
  cout << ans << endl;
}

Fixed submission:
#include "bits/stdc++.h"
using namespace std;
#define rep(i, a, n) for (int i = a; i < n; i++)
#define ALL(s) s.begin(), s.end()
const int M = 100010;
int INF = 1000000007;
using ll = long long;

int main() {
  ll n, m, ans;
  cin >> n >> m;
  ll tmp = m - n, ans2;
  if (tmp > 0) {
    ans = (m / 2 - n) / 2;
    ans2 = n / 2 + m / 4;
    ans = max(ans, ans2);
  } else
    ans = min(n, m / 2);
  if (ans == 1)
    cout << "2" << endl;
  else
    cout << ans << endl;
}
Problem p03799 (C++)

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

using namespace std;

#define sqr(x) ((x) * (x))
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()

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

const int MOD = 1000000007;

void solve() {
  ll N, M;
  cin >> N >> M;
  ll ans = 0;
  while (true) {
    if (N <= 0 && M >= 4) {
      M -= 4;
    } else if (N > 0 && M >= 2) {
      N--;
      M -= 2;
    } else {
      break;
    }
    ans++;
  }
  cout << ans << endl;
}

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

  solve();

  return 0;
}


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

using namespace std;

#define sqr(x) ((x) * (x))
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()

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

const int MOD = 1000000007;

void solve() {
  ll N, M;
  cin >> N >> M;
  ll ans = 0;
  if (N <= M / 2) {
    ans = N + (M - 2 * N) / 4;
  } else {
    ans = M / 2;
  }
  cout << ans << endl;
}

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

  solve();

  return 0;
}
Problem p03799 (C++)

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

int main(int argc, char **argv) {
  ll S, C;
  cin >> S >> C;

  ll res{0};
  while (true) {
    if (S - 1 < 0 || C - 2 < 0)
      break;
    ++res;
    --S;
    C -= 2;
  }

  std::cout << res + C / 4 << std::endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll MOD = 1000000007;
constexpr ll INF = 1ll << 60;

int main(int argc, char **argv) {
  ll S, C;
  cin >> S >> C;

  ll res{0};
  res = min(S, C / 2);
  C = max(0ll, C - res * 2);
  std::cout << res + C / 4 << std::endl;
}
Problem p03799 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
/* #define int long long */
/* #define double long double */
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define repa(i, s, n) for (int i = s; i < (int)n; i++)
#define MOD 1000000007
using namespace std;
using ll = long long;
typedef vector<int> vi;
typedef pair<int, int> P;
#define rrep(i, a, b) for (int i = a; i >= b; i--)
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

signed main() {
  ll n, m;
  cin >> n >> m;
  ll ans = 0;

  ll cc = m / 2;
  ll norm_scc = min(n, cc);
  n -= norm_scc;
  m -= 2 * norm_scc;

  ans += norm_scc;

  while (true) {
    if (n == 0) {
      m -= 2;
      n++;
    }
    if (n <= 0 || m <= 1)
      break;
    n--;
    m -= 2;
    ans++;
  }
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
/* #define int long long */
/* #define double long double */
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define repa(i, s, n) for (int i = s; i < (int)n; i++)
#define MOD 1000000007
using namespace std;
using ll = long long;
typedef vector<int> vi;
typedef pair<int, int> P;
#define rrep(i, a, b) for (int i = a; i >= b; i--)
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

signed main() {
  ll n, m;
  cin >> n >> m;
  ll ans = 0;

  ll cc = m / 2;
  ll norm_scc = min(n, cc);
  n -= norm_scc;
  m -= 2 * norm_scc;

  ans += norm_scc;

  ll cc4 = m / 4;
  ans += cc4;
  cout << ans << endl;
}
Problem p03799 (C++)

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

using namespace std;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rrep(i, n) for (ll i = (n - 1); i >= 0; --i)
#define blank(ans) cout << (ans) << " ";
#define mp(p, q) make_pair(p, q)
#define mt(p, q, r) make_tuple(p, q, r)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef string str;

typedef vector<ll> vll;
typedef vector<ld> vd;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<str> vs;
typedef vector<vector<ll>> vvll;
typedef vector<vector<ld>> vvd;
typedef vector<vector<bool>> vvb;
typedef vector<vector<char>> vvc;
typedef vector<vector<str>> vvs;
typedef vector<pair<ll, ll>> vpll;
typedef vector<tuple<ll, ll, ll>> vtlll;

const ld PI = acos(-1.0);
const ll MAX = 9000000000000000000;
const ll MIN = -9000000000000000000;
const ld DMAX = 4500;
const ld DMIN = -4500;
const ll MOD = 1000000007;

template <typename T> void fin(T a) {
  cout << a << endl;
  exit(0);
}

// 実行部
void Main() {
  ll s, c;
  cin >> s >> c;
  ll ans = min(s, c / 2);
  while (1) {
    s++;
    c -= 2;
    ll flag = 0;
    ans = max(ans, min(s, c / 2));
    if (s > c / 2)
      break;
  }
  fin(ans);
}

// 前処理
int main() {
  ifstream in("text.txt");
  cin.rdbuf(in.rdbuf());
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(20); // 高精度少数表示
  Main();
  return 0;
}

/*
//test時
  g++ test.cpp -o test;./test
*/


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

using namespace std;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rrep(i, n) for (ll i = (n - 1); i >= 0; --i)
#define blank(ans) cout << (ans) << " ";
#define mp(p, q) make_pair(p, q)
#define mt(p, q, r) make_tuple(p, q, r)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef string str;

typedef vector<ll> vll;
typedef vector<ld> vd;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<str> vs;
typedef vector<vector<ll>> vvll;
typedef vector<vector<ld>> vvd;
typedef vector<vector<bool>> vvb;
typedef vector<vector<char>> vvc;
typedef vector<vector<str>> vvs;
typedef vector<pair<ll, ll>> vpll;
typedef vector<tuple<ll, ll, ll>> vtlll;

const ld PI = acos(-1.0);
const ll MAX = 9000000000000000000;
const ll MIN = -9000000000000000000;
const ld DMAX = 4500;
const ld DMIN = -4500;
const ll MOD = 1000000007;

template <typename T> void fin(T a) {
  cout << a << endl;
  exit(0);
}

// 実行部
void Main() {
  ll s, c;
  cin >> s >> c;
  ll ans = min(s, c / 2);
  s -= ans;
  c -= ans * 2;
  ans += c / 4;
  fin(ans);
}

// 前処理
int main() {
  ifstream in("text.txt");
  cin.rdbuf(in.rdbuf());
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(20); // 高精度少数表示
  Main();
  return 0;
}

/*
//test時
  g++ test.cpp -o test;./test
*/
Problem p03799 (C++)

Buggy submission (status: Time Limit Exceeded):
// https://atcoder.jp/contests/arc069/tasks/arc069_a
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
  ll n, m;
  cin >> n >> m;
  ll ans = 0;
  while (m > 0) {
    ans = max(ans, min(n, m / 2));
    m -= 2;
    n++;
  }
  cout << ans << "\n";
}

Fixed submission:
// https://atcoder.jp/contests/arc069/tasks/arc069_a
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
  ll n, m;
  cin >> n >> m;
  ll x = min(n, m / 2);
  x += (m - x * 2) / 4;
  cout << x << "\n";
}
Problem p03799 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <string>
#include <utility>
#include <vector>
#define INF 2147483647
#define llINF 9223372036854775807
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define ll long long

using namespace std;
int main() {
  ll s, c;
  cin >> s >> c;
  if (s == c / 2) {
    cout << s << endl;
  } else if (s > c / 2) {
    cout << c / 2 << endl;
  } else if (s < c / 2) {
    while (s < c / 2) {
      s++;
      c -= 2;
    }
    cout << c / 2 << endl;
  }
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <string>
#include <utility>
#include <vector>
#define INF 2147483647
#define llINF 9223372036854775807
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define ll long long

using namespace std;
int main() {
  ll s, c;
  cin >> s >> c;
  if (s == c / 2) {
    cout << s << endl;
  } else if (s > c / 2) {
    cout << c / 2 << endl;
  } else if (s < c / 2) {
    c -= s * 2;
    ll a = c / 4 + s;
    cout << a << endl;
  }
  return 0;
}
Problem p03799 (C++)

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

int main() {
  int64_t n, m;
  cin >> n >> m;
  if ((m / 2) <= n) {
    cout << m / 2;
  } else {
    int64_t s, t;
    for (int i = (m - 2 * n) / 4;; i++) {
      if ((m - 2 * i) / 2 <= (n + i)) {
        s = (m - 2 * i) / 2;
        t = n + i;
        break;
      }
    }
    cout << s;
  }
}

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

int main() {
  int64_t n, m;
  cin >> n >> m;
  if ((m / 2) <= n) {
    cout << m / 2;
  } else {
    cout << n + (m - 2 * n) / 4;
  }
}
Problem p03800 (C++)

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

int N;
string s;
int t[200005];

int main() {
  cin >> N >> s;

  for (int i = 0; i < 2; i++) {
    for (int j = 0; j < 2; j++) {
      t[0] = i;
      t[1] = j;

      for (int k = 2; k < N + N; k++) {
        if ((s[k - 1] == 'o') ^ t[k - 1])
          t[k] = t[k - 2];
        else
          t[k] = 1 - t[k - 2];
      }

      bool flg = true;
      for (int k = 0; k < N; k++)
        if (t[k] != t[k + N])
          flg = false;

      if (flg) {
        for (int k = 0; k < N; k++)
          cout << (t[k] == 0 ? 'S' : 'W');
        cout << endl;
        return 0;
      }
    }
  }
  cout << -1 << endl;
  return 0;
}


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

int N;
string s;
int t[200005];

int main() {
  cin >> N >> s;

  for (int i = 0; i < 2; i++) {
    for (int j = 0; j < 2; j++) {
      t[0] = i;
      t[1] = j;

      for (int k = 2; k < N + N; k++) {
        if ((s[(k - 1) % N] == 'o') ^ t[k - 1])
          t[k] = t[k - 2];
        else
          t[k] = 1 - t[k - 2];
      }

      bool flg = true;
      for (int k = 0; k < N; k++)
        if (t[k] != t[k + N])
          flg = false;

      if (flg) {
        for (int k = 0; k < N; k++)
          cout << (t[k] == 0 ? 'S' : 'W');
        cout << endl;
        return 0;
      }
    }
  }
  cout << -1 << endl;
  return 0;
}
Problem p03800 (C++)

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MAX = 5005;
const int INF = 0x3f3f3f3f;
const int MOD = 1000000007;
int n, ans[MAX], dx[4] = {1, 1, -1, -1}, dy[4] = {1, -1, 1, -1};
char s[MAX];
int cl() {
  for (int i = 0; i < n; i++)
    ans[i] = 0;
}
int fans(int x) {
  if (x == n) {
    return (((ans[0] == 1) == (s[0] == 'o')) == (ans[n - 1] == ans[1])) &&
           (((ans[n - 1] == 1) == (s[n - 1] == 'o')) == (ans[n - 2] == ans[0]));
  }
  if ((ans[x - 1] == 1) == (s[x - 1] == 'o'))
    ans[x] = ans[x - 2];
  else
    ans[x] = -ans[x - 2];
  return fans(x + 1);
}
int main() {
  scanf(" %d %s", &n, s);
  for (int i = 0; i < 4; i++) {
    cl();
    ans[0] = dx[i], ans[1] = dy[i];
    if (fans(2)) {
      for (int i = 0; i < n; i++) {
        if (ans[i] == 1)
          printf("S");
        else
          printf("W");
      }
      printf("\n");
      return 0;
    }
  }
  printf("-1\n");
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define x first
#define y second
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MAX = 500005;
const int INF = 0x3f3f3f3f;
const int MOD = 1000000007;
int n, ans[MAX], dx[4] = {1, 1, -1, -1}, dy[4] = {1, -1, 1, -1};
char s[MAX];
int cl() {
  for (int i = 0; i < n; i++)
    ans[i] = 0;
}
int fans(int x) {
  if (x == n) {
    return (((ans[0] == 1) == (s[0] == 'o')) == (ans[n - 1] == ans[1])) &&
           (((ans[n - 1] == 1) == (s[n - 1] == 'o')) == (ans[n - 2] == ans[0]));
  }
  if ((ans[x - 1] == 1) == (s[x - 1] == 'o'))
    ans[x] = ans[x - 2];
  else
    ans[x] = -ans[x - 2];
  return fans(x + 1);
}
int main() {
  scanf(" %d %s", &n, s);
  for (int i = 0; i < 4; i++) {
    cl();
    ans[0] = dx[i], ans[1] = dy[i];
    if (fans(2)) {
      for (int i = 0; i < n; i++) {
        if (ans[i] == 1)
          printf("S");
        else
          printf("W");
      }
      printf("\n");
      return 0;
    }
  }
  printf("-1\n");
  return 0;
}