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

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

  int n;
  cin >> n;
  vector<char> S(n);

  for (int i = 0; i < n; i++) {
    cin >> S.at(i);
  }

  int count = 0;

  for (int i = 0; i < n; i++) {
    if (S.at(i) == 'A') {
      if (S.at(i + 1) == 'B') {
        if (S.at(i + 2) == 'C') {
          count++;
        }
      }
    }
  }

  cout << count << endl;
  return 0;
}

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

  int n;
  cin >> n;
  vector<char> S(n);

  for (int i = 0; i < n; i++) {
    cin >> S.at(i);
  }

  int count = 0;

  for (int i = 0; i < n - 2; i++) {
    if (S.at(i) == 'A') {
      if (S.at(i + 1) == 'B') {
        if (S.at(i + 2) == 'C') {
          count++;
        }
      }
    }
  }

  cout << count << endl;
  return 0;
}
Problem p02812 (C++)

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

int main() {
  string a;
  int sum, b;
  sum = 0;
  b = 0;
  cin >> b >> a;
  for (int i = 0; i < b - 1; i++) {
    if (a.at(i) == 'A' && a.at(i + 1) == 'B' && a.at(i + 2) == 'C')
      sum = sum + 1;
  }
  cout << sum << endl;
}

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

int main() {
  string a;
  int sum, b;
  sum = 0;
  b = 0;
  cin >> b >> a;
  for (int i = 0; i < b - 2; i++) {
    if (a.at(i) == 'A' && a.at(i + 1) == 'B' && a.at(i + 2) == 'C')
      sum = sum + 1;
  }
  cout << sum << endl;
}
Problem p02812 (C++)

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

int main() {
  string s;
  cin >> s;
  string check = "ABC";
  int count = 0;
  for (int i = 0; i < s.size() - 2; i++) {
    if (s.substr(i, 3) == check) {
      count++;
    }
  }
  cout << count << endl;
}

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

int main() {
  string s;
  int n;
  cin >> n;
  cin >> s;
  string check = "ABC";
  int count = 0;
  for (int i = 0; i < s.size() - 2; i++) {
    if (s.substr(i, 3) == check) {
      count++;
    }
  }
  cout << count << endl;
}
Problem p02812 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  string s;
  int counter = 0;
  for (int i = 0; i < N - 2; i++) {
    if (s.at(i) == 'A' && s.at(i + 1) == 'B' && s.at(i + 2) == 'C') {
      counter++;
    }
  }
  cout << counter << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  string s;
  cin >> s;
  int counter = 0;
  for (int i = 0; i < N - 2; i++) {
    if (s.at(i) == 'A' && s.at(i + 1) == 'B' && s.at(i + 2) == 'C') {
      counter++;
    }
  }
  cout << counter << endl;
}
Problem p02812 (C++)

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

int main() {
  int N;
  int count = 0;
  string S;
  cin >> N >> S;
  for (int i = 0; i < N; i++) {
    if (S.at(i) == 'A') {
      if (S.at(i + 1) == 'B') {
        if (S.at(i + 2) == 'C') {
          count++;
        }
      }
    }
  }
  cout << count << endl;
}

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

int main() {
  int N;
  int count = 0;
  string S;
  cin >> N >> S;
  for (int i = 0; i < N - 2; i++) {
    if (S.at(i) == 'A') {
      if (S.at(i + 1) == 'B') {
        if (S.at(i + 2) == 'C') {
          count++;
        }
      }
    }
  }
  cout << count << endl;
}
Problem p02812 (C++)

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

int main() {
  string s;
  cin >> s;
  int g;
  g = 0;
  for (int i = 0; i < s.size() - 2; i++) {
    if (s[i] == 'A') {
      if (s[i + 1] == 'B' && s[i + 2] == 'C')
        g++;
    }
  }
  cout << g << endl;
}


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

int main() {
  string s;
  int n;
  cin >> n >> s;
  int g;
  g = 0;
  for (int i = 0; i < s.size() - 2; i++) {
    if (s[i] == 'A') {
      if (s[i + 1] == 'B' && s[i + 2] == 'C')
        g++;
    }
  }
  cout << g << endl;
}
Problem p02812 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
const double PI = 3.14159265358979323846;

int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  int cnt = 0;
  rep(i, s.size()) {
    if (i > (int)s.size() - 2)
      break;
    if (s.at(i) == 'A' && s.at(i + 1) == 'B' && s.at(i + 2) == 'C')
      cnt++;
  }
  cout << cnt << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
const double PI = 3.14159265358979323846;

int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  int cnt = 0;
  rep(i, n) {
    if (i >= n - 2)
      break;
    if (s.at(i) == 'A' && s.at(i + 1) == 'B' && s.at(i + 2) == 'C')
      cnt++;
  }
  cout << cnt << endl;
  return 0;
}
Problem p02812 (Python)

Buggy submission (status: Runtime Error):
N = int(input())
S = input()
count = 0
for i in range(N):
    if S[i] == "A" and S[i + 1] == "B" and S[i + 2] == "C":
        count += 1
print(count)


Fixed submission:
N = int(input())
S = input()
count = 0
for i in range(N):
    try:
        if S[i] == "A" and S[i + 1] == "B" and S[i + 2] == "C":
            count += 1
    except IndexError:
        break
print(count)
Problem p02812 (C++)

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

// @author: pashka

int main() {
  ios::sync_with_stdio(false);

  int n;
  cin >> n;
  string s;
  int res = 0;
  for (int i = 0; i < n - 2; i++) {
    if (s.substr(i, 3) == "ABC")
      res++;
  }
  cout << res << "\n";

  return 0;
}

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

// @author: pashka

int main() {
  ios::sync_with_stdio(false);

  int n;
  cin >> n;
  string s;
  cin >> s;
  int res = 0;
  for (int i = 0; i < n - 2; i++) {
    if (s.substr(i, 3) == "ABC")
      res++;
  }
  cout << res << "\n";

  return 0;
}
Problem p02812 (C++)

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

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

  int cnt = 0;

  // for (int i=0;i<n+3;i++){
  //     cin>>s.at(i);
  // }
  for (int i = 0; i < n + 2; i++) {
    if (s.at(i) == 'A' && s.at(i + 1) == 'B' && s.at(i + 2) == 'C') {
      cnt++;
    }
  }
  cout << cnt << endl;

  return 0;
}


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

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

  int cnt = 0;

  // for (int i=0;i<n+3;i++){
  //     cin>>s.at(i);
  // }
  for (int i = 0; i < n - 2; i++) {
    if (s.at(i) == 'A' && s.at(i + 1) == 'B' && s.at(i + 2) == 'C') {
      cnt++;
    }
  }
  cout << cnt << endl;

  return 0;
}
Problem p02812 (C++)

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

int main() {
  int N, count = 0;
  string S;
  cin >> N >> S;

  rep(i, N) {
    if (S.at(i) == 'A' && S.at(i + 1) == 'B' && S.at(i + 2) == 'C') {
      count++;
    }
  }
  cout << count << endl;
}

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

int main() {
  int N, count = 0;
  string S;
  cin >> N >> S;

  rep(i, N - 2) {
    if (S.at(i) == 'A' && S.at(i + 1) == 'B' && S.at(i + 2) == 'C') {
      count++;
    }
  }
  cout << count << endl;
}
Problem p02812 (C++)

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

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

  for (int i = 0; i < n; i++) {
    if (s.at(i) == 'A' && s.at(i + 1) == 'B' && s.at(i + 2) == 'C')
      ans++;
  }
  cout << ans << endl;
}

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

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

  for (int i = 0; i < n - 2; i++) {
    if (s.at(i) == 'A' && s.at(i + 1) == 'B' && s.at(i + 2) == 'C')
      ans++;
  }
  cout << ans << endl;
}
Problem p02812 (C++)

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

int solve(int n) {
  int N = n;
  int count = 0;
  string S;
  cin >> S;
  for (int i = 0; i < N; i++) {
    if (S[i] == 'A' && S[i + 1] == 'B' && S[i + 2] == 'C') {
      count++;
    }
  }
  cout << count << endl;
}

int main() {
  int N;
  cin >> N;
  solve(N);
  return 0;
}


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

void solve(int n) {
  int N = n;
  int count = 0;
  string S;
  cin >> S;
  for (int i = 0; i < N; i++) {
    if (S[i] == 'A' && S[i + 1] == 'B' && S[i + 2] == 'C') {
      count++;
    }
  }
  cout << count << endl;
}

int main() {
  int N;
  cin >> N;
  solve(N);
  return 0;
}
Problem p02812 (C++)

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

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

  int count = 0;
  for (int i = 1; N - 1; i++) {
    if (s[i - 1] == 'A' && s[i] == 'B' && s[i + 1] == 'C')
      count++;
  }
  cout << count << endl;
}


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

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

  int count = 0;
  for (int i = 1; i < N - 1; i++) {
    if (s[i - 1] == 'A' && s[i] == 'B' && s[i + 1] == 'C')
      count++;
  }
  cout << count << endl;
}
Problem p02812 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <queue>
using namespace std;
int main() {
  string s;
  int cnt = 0;
  cin >> s;
  for (int i = 0; i < s.length() - 2; i++) {
    if (s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C') {
      cnt += 1;
    }
  }
  cout << cnt << endl;
}

Fixed submission:
#include <iostream>
#include <queue>
using namespace std;
int main() {
  string s;
  int cnt = 0, n;
  cin >> n >> s;
  for (int i = 0; i < n - 2; i++) {
    if (s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C') {
      cnt += 1;
    }
  }
  cout << cnt << endl;
}
Problem p02812 (C++)

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

int main() {
  int n;
  string x;
  cin >> n >> x;
  vector<char> word(n);
  for (int i; i < n; i++) {
    word.at(i) = x[i];
  }
  int count = 0;
  for (int i; i < n; i++) {
    if (word.at(i) == 'A') {
      if (word.at(i + 1) == 'B') {
        if (word.at(i + 2) == 'C') {
          count++;
        }
      }
    }
  }
  cout << count << endl;
}

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

int main() {
  int n;
  string x;
  cin >> n >> x;
  vector<char> word(n);
  for (int i; i < n; i++) {
    word.at(i) = x[i];
  }
  int count = 0;
  for (int i; i < n - 2; i++) {
    if (word.at(i) == 'A') {
      if (word.at(i + 1) == 'B') {
        if (word.at(i + 2) == 'C') {
          count++;
        }
      }
    }
  }
  cout << count << endl;
}
Problem p02812 (C++)

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

int main() {
  int N;
  cin >> N;
  string s;
  cin >> s;
  int count = 0;
  for (int i = 0; i < N; i++) {
    if (s.at(i) == 'A' && s.at(i + 1) == 'B' && s.at(i + 2) == 'C')
      count++;
  }
  cout << count << endl;
}

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

int main() {
  int N;
  cin >> N;
  string s;
  cin >> s;
  int count = 0;
  for (int i = 0; i < N - 2; i++) {
    if (s.at(i) == 'A' && s.at(i + 1) == 'B' && s.at(i + 2) == 'C')
      count++;
  }
  cout << count << endl;
}
Problem p02812 (C++)

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

int main() {
  int m;
  cin >> m;
  string s;
  cin >> s;
  int n = 0;
  for (int i = 0; i < s.size(); i++) {
    if (s.at(i) == 'A' && s.at(i + 1) == 'B' && s.at(i + 2) == 'C') {
      n++;
    }
  }
  cout << n << endl;
}


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

int main() {
  int m;
  cin >> m;
  string s;
  cin >> s;
  int n = 0;
  for (int i = 0; i < s.size() - 2; i++) {
    if (s.at(i) == 'A' && s.at(i + 1) == 'B' && s.at(i + 2) == 'C') {
      n++;
    }
  }
  cout << n << endl;
}
Problem p02812 (C++)

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

int main() {
  int N;
  string S;
  cin >> N >> S;

  int count = 0;
  for (int i = 0; i < N; i++) {
    if (S.at(i) == 'A' && S.at(i + 1) == 'B' && S.at(i + 2) == 'C') {
      count++;
    }
  }

  cout << count << endl;

  return 0;
}

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

int main() {
  int N;
  string S;
  cin >> N >> S;

  int count = 0;
  for (int i = 0; i < N - 2; i++) {
    if (S.at(i) == 'A' && S.at(i + 1) == 'B' && S.at(i + 2) == 'C') {
      count++;
    }
  }

  cout << count << endl;

  return 0;
}
Problem p02812 (C++)

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

int main() {
  int N, ans;
  string S;
  cin >> N >> S;
  ans = 0;

  for (int i = 0; i < N; i++) {
    if (S.at(i) != 'A') {
      continue;
    } else if (S.at(i + 1) != 'B') {
      continue;
    } else if (S.at(i + 2) != 'C') {
      continue;
    }
    ans++;
  }
  cout << ans << endl;
}

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

int main() {
  int N, ans;
  string S;
  cin >> N >> S;
  ans = 0;

  for (int i = 0; i < N - 2; i++) {
    if (S.at(i) != 'A') {
      continue;
    } else if (S.at(i + 1) != 'B') {
      continue;
    } else if (S.at(i + 2) != 'C') {
      continue;
    }
    ans++;
  }
  cout << ans << endl;
}
Problem p02812 (C++)

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

int main() {
  int N;
  string S;
  cin >> N >> S;

  int ans = 0;
  rep(i, N) {
    if (S.at(i) == 'A') {
      if (S.at(i + 1) == 'B') {
        if (S.at(i + 2) == 'C') {
          ans++;
        }
      }
    }
  }
  cout << ans << endl;
}

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

int main() {
  int N;
  string S;
  cin >> N >> S;

  int ans = 0;
  rep(i, N) {
    if (S.at(i) == 'A' && i + 1 <= N - 1) {
      if (S.at(i + 1) == 'B' && i + 2 <= N - 1) {
        if (S.at(i + 2) == 'C') {
          ans++;
        }
      }
    }
  }
  cout << ans << endl;
}
Problem p02812 (C++)

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

int main() {
  int N;
  string S;
  cin >> N >> S;
  int count = 0;
  for (int i = 0; i < N; i++) {
    if (S.at(i) == 'A' && S.at(i + 1) == 'B' && S.at(i + 2) == 'C') {
      count++;
    }
  }
  cout << count << endl;
}

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

int main() {
  int N;
  string S;
  cin >> N >> S;
  int count = 0;
  for (int i = 0; i < N - 2; i++) {
    if (S.at(i) == 'A' && S.at(i + 1) == 'B' && S.at(i + 2) == 'C') {
      count++;
    }
  }
  cout << count << endl;
}
Problem p02812 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 100;
int main() {
  int n;
  char s[N];
  scanf("%d%s", n, s);

  int sum = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C')
      sum++;
  }
  printf("%d\n", sum);
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 100;
int main() {
  int n;
  char s[N];
  scanf("%d%s", &n, s);

  int sum = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C')
      sum++;
  }
  printf("%d\n", sum);
  return 0;
}
Problem p02812 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;
int main() {
  long long int c = 0, i, j, k, l, x, n;
  string s;
  cin >> s;
  for (i = 0; i < s.length() - 2; i++) {
    if (s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C') {
      c++;
    }
  }
  cout << c;
}


Fixed submission:
#include <iostream>
using namespace std;
int main() {
  long long int c = 0, i, j, k, l, x, n;
  string s;
  cin >> n;
  cin >> s;
  for (i = 0; i < s.length() - 2; i++) {
    if (s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C') {
      c++;
    }
  }
  cout << c;
}
Problem p02812 (C++)

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

int main() {
  int N;
  string S;
  cin >> N;
  cin >> S;

  int j;
  char A;
  char B;
  char C;

  j = 0;

  for (int i = 0; i < N; i++) {
    if (S.at(i) == 'A') {
      if (S.at(i + 1) == 'B') {
        if (S.at(i + 2) == 'C') {
          j++;
        }
      }
    }
  }

  cout << j << endl;
}


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

int main() {
  int N;
  string S;
  cin >> N;
  cin >> S;

  int j;
  char A;
  char B;
  char C;

  j = 0;

  for (int i = 0; i < N - 2; i++) {
    if (S.at(i) == 'A') {
      if (S.at(i + 1) == 'B') {
        if (S.at(i + 2) == 'C') {
          j++;
        }
      }
    }
  }

  cout << j << endl;
}
Problem p02812 (C++)

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

int main() {
  int n, count = 0;
  string s;
  cin >> n >> s;

  for (int i = 0; i < n; i++) {
    if (s.at(i) == 'A') {
      if (s.at(i + 1) == 'B' && s.at(i + 2) == 'C') {
        count++;
      }
    }
  }
  cout << count << endl;
}

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

int main() {
  int n, count = 0;
  string s;
  cin >> n >> s;

  for (int i = 0; i < n - 2; i++) {
    if (s.at(i) == 'A' && s.at(i + 1) == 'B' && s.at(i + 2) == 'C') {
      count++;
    }
  }
  cout << count << endl;
}
Problem p02812 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long int
#define N 200100
#define pii pair<int, int>
#define rep(i, k, n) for (int i = k; i < n; i++)
#define vi vector<int>
#define inf 1e9
void solve() {
  int n;
  string s;
  cin >> n;
  cin >> s;
  ll ans = 0;
  int i = 0;
  while (i < n) {
    if (i + 2 < n && s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C') {
      ans++;
      i += 3;
      continue;
    }
    i++;
  }
  cout << ans << endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w+", stdout);
#endif
  solve();
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long int
#define N 200100
#define pii pair<int, int>
#define rep(i, k, n) for (int i = k; i < n; i++)
#define vi vector<int>
#define inf 1e9
void solve() {
  int n;
  string s;
  cin >> n;
  cin >> s;
  ll ans = 0;
  int i = 0;
  while (i < n) {
    if (i + 2 < n && s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C') {
      ans++;
      i += 3;
      continue;
    }
    i++;
  }
  cout << ans << endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  solve();
}
Problem p02812 (Python)

Buggy submission (status: Runtime Error):
N = int(input())
S = input()

ans = 0
while "ABC" in S:
    ans += 1
    S.remove("ABC")

print(ans)


Fixed submission:
N = int(input())
S = input()

ans = S.count("ABC")
print(ans)
Problem p02812 (Python)

Buggy submission (status: Runtime Error):
N = int(input())
S = input()

ans = 0
i = 0
while i < N:
    if S[i] == "A":
        i += 1
        if S[i] == "B":
            i += 1
            if S[i] == "C":
                ans += 1
            else:
                i += 1
        else:
            i += 1
    else:
        i += 1

print(ans)


Fixed submission:
N = int(input())
S = input()

ans = 0
for i in range(N):
    if S[i : i + 3] == "ABC":
        ans += 1

print(ans)
Problem p02812 (Python)

Buggy submission (status: Runtime Error):
def main():
    N, S = open(0).read().split("\n")
    print(S.count("ABC"))


if __name__ == "__main__":
    main()


Fixed submission:
def main():
    N = input()
    S = input()
    print(S.count("ABC"))


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

Buggy submission (status: Runtime Error):
a = int(input())
b = input()
print(a.count("ABC"))


Fixed submission:
a = int(input())
b = input()
print(b.count("ABC"))
Problem p02812 (Python)

Buggy submission (status: Runtime Error):
n = int(input())
s = input()
ans = 0
for i in range(n):
    if s[i] == "A" and s[i + 1] == "B" and s[i + 2] == "C":
        ans += 1
print(ans)


Fixed submission:
n = int(input())
s = input()
ans = 0
for i in range(n):
    if s[i : i + 3] == "ABC":
        ans += 1
print(ans)
Problem p02812 (C++)

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

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

  int t = 0;
  for (int i = 0; i < s.size() - 2; i++)
    if (s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C')
      t++;

  cout << t << endl;
  return 0;
}

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

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

  string s;
  cin >> s;

  int t = 0;
  for (int i = 0; i < s.size() - 2; i++)
    if (s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C')
      t++;

  cout << t << endl;
  return 0;
}
Problem p02812 (C++)

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

int main() {
  string S;
  int N, i = 0, count = 0;

  cin >> N;
  cin >> S;

  for (i + 2; i < N; i++) {
    if (S.at(i - 2) == 'A' && S.at(i - 1) == 'B' && S.at(i) == 'C') {
      count++;
    }
  }

  cout << count << endl;
}


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

int main() {
  string S;
  int N, i = 0, count = 0;

  cin >> N;
  cin >> S;

  for (i; i < N - 2; i++) {
    if (S.at(i) == 'A' && S.at(i + 1) == 'B' && S.at(i + 2) == 'C') {
      count++;
    }
  }

  cout << count << endl;
}
Problem p02812 (C++)

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

int main() {
  int N;
  string A;
  cin >> N >> A;
  int count = 0;
  for (int i = 0; i < N; i++) {
    if (A.at(i) == 'A') {
      if (A.at(i + 1) == 'B') {
        if (A.at(i + 2) == 'C') {
          count++;
        } else
          continue;
      } else
        continue;
    } else
      continue;
  }
  cout << count << endl;
  return 0;
}

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

int main() {
  int N;
  string A;
  cin >> N >> A;
  int count = 0;
  for (int i = 0; i < N - 2; i++) {
    if (A.at(i) == 'A') {
      if (A.at(i + 1) == 'B') {
        if (A.at(i + 2) == 'C') {
          count++;
        } else
          continue;
      } else
        continue;
    } else
      continue;
  }
  cout << count << endl;
  return 0;
}
Problem p02812 (C++)

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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
typedef pair<int, int> P;

const int INF = 1001001001;

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

  int ans = 0;
  char n;
  string s;
  cin >> n >> s;
  for (int i = 0; i <= n - 3; ++i) {
    if (s.at(i) == 'A' && s.at(i + 1) == 'B' && s.at(i + 2) == 'C') {
      ans++;
    }
  }
  cout << ans << endl;
  cout << endl;
  return 0;
}

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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
typedef pair<int, int> P;

const int INF = 1001001001;

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

  int ans = 0;
  int n;
  string s;
  cin >> n >> s;
  for (int i = 0; i <= n - 3; ++i) {
    if (s.at(i) == 'A' && s.at(i + 1) == 'B' && s.at(i + 2) == 'C') {
      ans++;
    }
  }
  cout << ans << endl;
  cout << endl;
  return 0;
}
Problem p02812 (C++)

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

  string str = S;
  int count = 0;
  for (int i = 0; i < N; i++) {
    int j = i + 1;
    int k = j + 1;
    if (str.at(i) == 'A' && str.at(j) == 'B' && str.at(k) == 'C') {
      count++;
    }
  }
  cout << count << endl;
  return 0;
}


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

  string str = S;
  int count = 0;
  for (int i = 0; i < N - 2; i++) {
    int j = i + 1;
    int k = j + 1;
    if (str.at(i) == 'A' && str.at(j) == 'B' && str.at(k) == 'C') {
      count++;
    }
  }
  cout << count << endl;
  return 0;
}
Problem p02812 (C++)

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

int main() {
  int n;
  string s;
  cin >> n >> s;
  int ans = 0;
  rep(i, n) {
    if (s.at(i) == 'A') {
      if (s.at(i + 1) == 'B') {
        if (s.at(i + 2) == 'C') {
          ans++;
        }
      }
    }
  }
  cout << ans << endl;
}

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

int main() {
  int n;
  string s;
  cin >> n >> s;
  int ans = 0;
  rep(i, n - 2) {
    if (s.at(i) == 'A') {
      if (s.at(i + 1) == 'B') {
        if (s.at(i + 2) == 'C') {
          ans++;
        }
      }
    }
  }
  cout << ans << endl;
}
Problem p02812 (C++)

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

int main() {
  int N;
  int sum = 0;
  string str;
  cin >> N >> str;
  for (int i = 0; i < N; i++) {
    if (i == N - 1) {
      break;
    } else if (str.at(i) == 'A' && str.at(i + 1) == 'B' &&
               str.at(i + 2) == 'C') {
      sum++;
    }
  }
  cout << sum << endl;
}

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

int main() {
  int N;
  int sum = 0;
  string str;
  cin >> N >> str;
  for (int i = 0; i < N; i++) {
    if (i == N - 2) {
      break;
    } else if (str.at(i) == 'A' && str.at(i + 1) == 'B' &&
               str.at(i + 2) == 'C') {
      sum++;
    }
  }
  cout << sum << endl;
}
Problem p02812 (C++)

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

int main() {
  string s;
  cin >> s;
  int ans = 0;
  for (int i = 0; i < s.size() - 2; i++) {
    if (s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C') {
      ans++;
    }
  }
  cout << ans << endl;
}

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

int main() {
  string s;
  int n;
  cin >> n >> s;
  int ans = 0;
  for (int i = 0; i < s.size() - 2; i++) {
    if (s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C') {
      ans++;
    }
  }
  cout << ans << endl;
}
Problem p02812 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <stdexcept>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using ll = long long;

int main() {
  int n;
  cin >> n;
  string s;
  int res = 0;
  for (int i = 0; i + 3 <= n; i++) {
    if (s.substr(i, 3) == "ABC")
      res++;
  }
  cout << res << endl;

  return 0;
}


Fixed submission:
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <stdexcept>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using ll = long long;

int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  int res = 0;
  for (int i = 0; i + 3 <= n; i++) {
    if (s.substr(i, 3) == "ABC")
      res++;
  }
  cout << res << endl;

  return 0;
}
Problem p02812 (C++)

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

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

  int ans = 0;

  for (int i = 0; i < n; ++i) {
    if (s.at(i) == 'A' && s.at(i + 1) == 'B' && s.at(i + 2) == 'C') {
      ans++;
    }
  }
  cout << ans << endl;

  return 0;
}


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

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

  int ans = 0;

  for (int i = 0; i < n - 2; ++i) {
    if (s.at(i) == 'A' && s.at(i + 1) == 'B' && s.at(i + 2) == 'C') {
      ans++;
    }
  }
  cout << ans << endl;

  return 0;
}
Problem p02812 (C++)

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

int main() {
  int n;
  int ans = 0;
  string s;
  cin >> n >> s;
  for (int i = 0; i < n - 1; i++) {
    //   cout << s.at(i);

    if ((s.at(i) == 'A') && (s.at(i + 1) == 'B') && (s.at(i + 2) == 'C'))
      ans++;
  }
  cout << ans;
}


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

int main() {
  int n;
  int ans = 0;
  string s;
  cin >> n >> s;
  for (int i = 0; i < n - 2; i++) {

    if ((s.at(i) == 'A') && (s.at(i + 1) == 'B') && (s.at(i + 2) == 'C'))
      ans++;
  }
  cout << ans;
}
Problem p02812 (C++)

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

int main() {
  string s;
  cin >> s;
  int count = 0;
  for (int i = 0; i <= s.size() - 3; i++) {
    if (s.at(i) == 'A') {
      if (s.at(i + 1) == 'B' && s.at(i + 2) == 'C') {
        count++;
      }
    }
  }
  cout << count << endl;
}


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

int main() {
  int N;
  cin >> N;
  string s;
  cin >> s;
  int count = 0;
  for (int i = 0; i <= s.size() - 3; i++) {
    if (s.at(i) == 'A') {
      if (s.at(i + 1) == 'B' && s.at(i + 2) == 'C') {
        count++;
      }
    }
  }
  cout << count << endl;
}
Problem p02812 (C++)

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

int main() {
  int N;
  string S;

  cin >> N;

  cin >> S;

  int cow = 0;

  for (int i = 0; i < N; i++) {
    if (S.at(i) == 'A' && S.at(i + 1) == 'B' && S.at(i + 2) == 'C') {
      cow++;
    }
  }

  cout << cow << endl;

  return 0;
}

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

int main() {
  int N;
  string S;

  cin >> N;

  cin >> S;

  int cow = 0;

  /*
  N -
  3�ɂ��闝�R�Ƃ��āAString��i����i+2�܂ł����āA���O����n�܂�̂ŁA
  �Ō�͓񌅁A�ꌅ�ɂȂ�̂Œ��ׂ�K�v���Ȃ��̂� i <= N-3
  �ɂ��Ă���B i <= N-3�ɂ��Ȃ������ꍇ�ARunTime
  Error(���s���G���[)�ɂȂ�\��������B
  �܂��AN < N-3 �ɂ����ꍇ�A�Ⴆ�� N
  ���P�O���Ƃ��āA�񌅂ɂȂ�����O�̂V�񒲂ׂ����̂ɁA
  i < N-3 �Ƃ����ꍇ�Ai < 7
  �܂�A(i��7����(7���܂܂Ȃ�)�̊�)�ƂȂ�̂�7��ڂ����s����Ȃ��Ȃ�A
  Wrong answer�ƂȂ�ꍇ������B
  */
  for (int i = 0; i <= N - 3; i++) {
    if (S.at(i) == 'A' && S.at(i + 1) == 'B' && S.at(i + 2) == 'C') {
      cow++;
    }
  }

  cout << cow << endl;

  return 0;
}
Problem p02812 (C++)

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

int main() {
  long long N;
  string S;
  cin >> N >> S;

  int count = 0;

  for (int i = 0; i < N; i++) {
    if (S.at(i) == 'A' && S.at(i + 1) == 'B' && S.at(i + 2) == 'C') {
      count++;
    }
  }
  cout << count;
}

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

int main() {
  long long N;
  string S;
  cin >> N >> S;

  int count = 0;

  for (int i = 0; i < N - 2; i++) {
    if (S.at(i) == 'A' && S.at(i + 1) == 'B' && S.at(i + 2) == 'C') {
      count++;
    }
  }
  cout << count;
}
Problem p02813 (Python)

Buggy submission (status: Runtime Error):
# ABC150C - Count Order
from itertools import permutations


def main():
    N, *PQ = map(int, open(0).read().split())
    P, Q = PQ[:N], PQ[N:]
    perms = list(permutations(range(1, N + 1), N))
    ans = abs(perms.index(P) - perms.index(Q))
    print(ans)


if __name__ == "__main__":
    main()


Fixed submission:
# ABC150C - Count Order
from itertools import permutations


def main():
    N = int(input())
    P = tuple(map(int, input().split()))
    Q = tuple(map(int, input().split()))
    perms = list(permutations(range(1, N + 1)))
    ans = abs(perms.index(P) - perms.index(Q))
    print(ans)


if __name__ == "__main__":
    main()
Problem p02813 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define ios ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
using namespace std;
int a[100], b[100], n, f[100], c[100];
int lowbit(int x) { return x & (-x); }
int add(int x) {
  while (x <= n) {
    c[x] += 1;
    x += lowbit(x);
  }
}
int pre(int x) {
  int sum = 0;
  while (x) {
    sum += c[x];
    x -= lowbit(x);
  }
  return sum;
}
void init() {
  f[0] = 1;
  for (int i = 1; i <= 8; ++i) {
    f[i] = f[i - 1] * i;
  }
}
int cantor_exp(int p[], int len) {
  int sum = 0;
  for (int i = n; i >= 1; --i) {
    int a = pre(p[i]);
    sum += a * f[n - i];
    add(p[i]);
  }
  return sum;
}
int main() {
  ios;
  cin >> n;
  init();
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
  }
  for (int i = 1; i <= n; ++i) {
    cin >> b[i];
  }
  int s1, s2;
  s1 = cantor_exp(a, n);
  memset(c, 0, sizeof c);
  s2 = cantor_exp(b, n);
  cout << abs(s1 - s2) << '\n';
}

Fixed submission:
#include <bits/stdc++.h>
#define ios ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
using namespace std;
int a[100], b[100], n, f[100], c[100];
int lowbit(int x) { return x & (-x); }
void add(int x) {
  while (x <= n) {
    c[x] += 1;
    x += lowbit(x);
  }
}
int pre(int x) {
  int sum = 0;
  while (x) {
    sum += c[x];
    x -= lowbit(x);
  }
  return sum;
}
void init() {
  f[0] = 1;
  for (int i = 1; i <= 8; ++i) {
    f[i] = f[i - 1] * i;
  }
}
int cantor_exp(int p[], int len) {
  int sum = 0;
  for (int i = n; i >= 1; --i) {
    int a = pre(p[i]);
    sum += a * f[n - i];
    add(p[i]);
  }
  return sum;
}
int main() {
  ios;
  cin >> n;
  init();
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
  }
  for (int i = 1; i <= n; ++i) {
    cin >> b[i];
  }
  int s1, s2;
  s1 = cantor_exp(a, n);
  memset(c, 0, sizeof c);
  s2 = cantor_exp(b, n);
  cout << abs(s1 - s2) << '\n';
}
Problem p02813 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
using namespace std;
int rui(int a, int b) {
  if (b == 0)
    return 1;
  return a * rui(a, b - 1);
}
int main() {
  int N, P = 0, Q = 0, pre, num = 0, re, a = 0, b = 0;
  bool te[10], flag;
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> re;
    P += re;
    P *= 10;
  }
  P /= 10;
  for (int i = 0; i < N; i++) {
    cin >> re;
    Q += re;
    Q *= 10;
  }
  Q /= 10;
  for (int i = 0; i < rui(10, N); i++) {
    pre = i;
    flag = false;
    for (int j = 0; j < 10; j++)
      te[j] = false;
    for (int j = 0; j < N; j++) {
      if (te[pre % 10] || pre % 10 > N || pre % 10 == 0) {
        flag = true;
        break;
      }
      te[pre % 10] = true;
      pre /= 10;
    }
    if (!flag)
      num++;
    if (i == P)
      a = num;
    if (i == Q)
      b = num;
    if (a != 0 && b != 0)
      break;
  }
  cout << max(a - b, b - a);
  return 0;
}


Fixed submission:
#include <algorithm>
#include <iostream>
using namespace std;
int rui(int a, int b) {
  if (b == 0)
    return 1;
  return a * rui(a, b - 1);
}
int main() {
  int N, P = 0, Q = 0, pre, num = 0, re, a = 0, b = 0;
  bool te[10], flag;
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> re;
    P += re;
    P *= 10;
  }
  P /= 10;
  for (int i = 0; i < N; i++) {
    cin >> re;
    Q += re;
    Q *= 10;
  }
  Q /= 10;
  for (int i = rui(10, N - 1); i < rui(10, N); i++) {
    pre = i;
    flag = false;
    for (int j = 0; j < 10; j++)
      te[j] = false;
    for (int j = 0; j < N; j++) {
      if (te[pre % 10] || pre % 10 > N || pre % 10 == 0) {
        flag = true;
        break;
      }
      te[pre % 10] = true;
      pre /= 10;
    }
    if (!flag)
      num++;
    if (i == P)
      a = num;
    if (i == Q)
      b = num;
    if (a != 0 && b != 0)
      break;
  }
  cout << max(a - b, b - a);
  return 0;
}
Problem p02813 (C++)

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

using ll = long long;

int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
#endif
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, i, c = 0;
  char ch;
  string s = "", t = "", u = "";
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> ch;
    s += ch;
    u += (char)('1' + i);
  }
  for (i = 0; i < n; i++) {
    cin >> ch;
    t += ch;
  }
  int a = 0, b = 0;
  while (u != s) {
    next_permutation(u.begin(), u.end());
    a++;
  }
  sort(u.begin(), u.end());
  while (u != t) {
    next_permutation(u.begin(), u.end());
    b++;
  }
  cout << abs(a - b);
}

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

using ll = long long;

int main() {
#ifndef ONLINE_JUDGE
  // freopen("input.txt","r",stdin);
#endif
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, i, c = 0;
  char ch;
  string s = "", t = "", u = "";
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> ch;
    s += ch;
    u += (char)('1' + i);
  }
  for (i = 0; i < n; i++) {
    cin >> ch;
    t += ch;
  }
  int a = 0, b = 0;
  while (u != s) {
    next_permutation(u.begin(), u.end());
    a++;
  }
  sort(u.begin(), u.end());
  while (u != t) {
    next_permutation(u.begin(), u.end());
    b++;
  }
  cout << abs(a - b);
}
Problem p02813 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <tuple>
#include <vector>

using namespace std;
#define PI 3.14159265359
#define ll long long int

int main(void) {
  ll N;
  cin >> N;
  vector<ll> P(N), Q(N), R(N);
  for (ll i = 1; i <= N; i++) {
    ll p;
    cin >> p;
    P.push_back(p);
    R.push_back(i);
  }

  for (ll i = 0; i < N; i++) {
    ll q;
    cin >> q;
    Q.push_back(q);
  }

  ll a, b;
  ll i = 0;
  do {
    if (P == R)
      a = i;
    if (Q == R)
      b = i;
    i++;
  } while (next_permutation(R.begin(), R.end()));

  cout << abs(a - b) << endl;
}

Fixed submission:
#include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <tuple>
#include <vector>

using namespace std;
#define PI 3.14159265359
#define ll long long int

int main(void) {
  ll N;
  cin >> N;
  vector<ll> P(N), Q(N), R(N);
  for (ll i = 1; i <= N; i++) {
    ll p;
    cin >> p;
    P.push_back(p);
    R.push_back(i);
  }

  for (ll i = 0; i < N; i++) {
    ll q;
    cin >> q;
    Q.push_back(q);
  }

  ll a, b;
  ll i = 0;
  do {
    if (P == R)
      a = i;
    if (Q == R)
      b = i;
    if (R > max(P, Q))
      break;
    i++;
  } while (next_permutation(R.begin(), R.end()));

  cout << abs(a - b) << endl;
}
Problem p02813 (C++)

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

#define pb push_back
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define ll long long
#define ii pair<int, int>
#define vi vector<int>
#define vll vector<ll>
#define vii vector<ii>

using namespace std;

bool compare(vi a, vi b) {

  for (int i = 0; i < a.size(); i++) {
    if (a[i] != b[i])
      return false;
  }

  return true;
}

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  int n, n1, n2;
  vector<int> aux;
  cin >> n;
  for (int i = 0; i < n; i++)
    aux.push_back(i + 1);
  vector<vector<int>> v;

  vi b(n);
  vi a(n);

  do {
    v.push_back(aux);
  } while (next_permutation(all(aux)));

  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> b[i];
  }

  sort(all(v));

  for (int i = 0; i < v.size(); i++) {
    if (compare(v[i], a))
      n1 = i;
    if (compare(v[i], b))
      n2 = i;
  }

  cout << abs(n1 - n2) << endl;
  return 0;
}

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

#define pb push_back
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define ll long long
#define ii pair<int, int>
#define vi vector<int>
#define vll vector<ll>
#define vii vector<ii>

using namespace std;

bool compare(vi a, vi b) {

  for (int i = 0; i < a.size(); i++) {
    if (a[i] != b[i])
      return false;
  }

  return true;
}

int32_t main() {

  int n, n1, n2;
  vector<int> aux;
  cin >> n;
  for (int i = 0; i < n; i++)
    aux.push_back(i + 1);
  vector<vector<int>> v;

  vi b(n);
  vi a(n);

  do {
    v.push_back(aux);
  } while (next_permutation(all(aux)));

  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> b[i];
  }

  sort(all(v));

  for (int i = 0; i < v.size(); i++) {
    if (compare(v[i], a))
      n1 = i;
    if (compare(v[i], b))
      n2 = i;
  }

  cout << abs(n1 - n2) << endl;
  return 0;
}
Problem p02813 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <vector>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9) + 7;

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

  vector<int> p(n), q(n);
  for (int i = 0; i < n; ++i) {
    cin >> p[i];
  }

  for (int i = 0; i < n; ++i) {
    cin >> q[i];
  }

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

  int a = 0, b = 0;
  int cnt = 0;

  do {
    if (p == x)
      a = cnt;
    if (q == x)
      b = cnt;

    cnt++;

  } while (next_permutation(p.begin(), q.end()));

  cout << abs(a - b) << endl;

  return 0;
}


Fixed submission:
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <vector>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9) + 7;

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

  vector<int> p(n), q(n);
  for (int i = 0; i < n; ++i) {
    cin >> p[i];
  }

  for (int i = 0; i < n; ++i) {
    cin >> q[i];
  }

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

  int a = 0, b = 0;
  int cnt = 0;

  do {
    if (p == x)
      a = cnt;
    if (q == x)
      b = cnt;

    cnt++;

  } while (next_permutation(x.begin(), x.end()));

  cout << abs(a - b) << endl;

  return 0;
}
Problem p02813 (C++)

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

#define ll long long int
#define ld long double
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define INF 0x3f3f3f3f
#define show(x) cerr << #x << " : " << x << '\n';
#define yogeshk972()                                                           \
  cerr << "\nTime Taken : " << (float)(clock() - time_p) / CLOCKS_PER_SEC      \
       << "\n";
clock_t time_p = clock();

using namespace std;
const int N = 1e3 + 10, mod = 1e9 + 7;

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

#ifndef ONLINE_JUDGE
  freopen("in.txt", "r", stdin);
  freopen("out.txt", "w", stdout);
#endif

  int n;
  cin >> n;
  vector<int> v1(n), v2(n);

  for (auto &x : v1)
    cin >> x;
  for (auto &x : v2)
    cin >> x;

  int a, b, ct = 0;
  vector<int> v;
  for (int i = 1; i <= n; i++)
    v.pb(i);

  do {
    if (v == v1)
      a = ct;
    if (v == v2)
      b = ct;
    ct++;
  } while (next_permutation(v.begin(), v.end()));

  cout << abs(a - b);

  return 0;
}


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

#define ll long long int
#define ld long double
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define INF 0x3f3f3f3f
#define show(x) cerr << #x << " : " << x << '\n';
#define yogeshk972()                                                           \
  cerr << "\nTime Taken : " << (float)(clock() - time_p) / CLOCKS_PER_SEC      \
       << "\n";
clock_t time_p = clock();

using namespace std;
const int N = 1e3 + 10, mod = 1e9 + 7;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  /*
    #ifndef ONLINE_JUDGE
    freopen("in.txt","r",stdin);
    freopen("out.txt","w",stdout);
    #endif
    */
  int n;
  cin >> n;
  vector<int> v1(n), v2(n);

  for (auto &x : v1)
    cin >> x;
  for (auto &x : v2)
    cin >> x;

  int a, b, ct = 0;
  vector<int> v;
  for (int i = 1; i <= n; i++)
    v.pb(i);

  do {
    if (v == v1)
      a = ct;
    if (v == v2)
      b = ct;
    ct++;
  } while (next_permutation(v.begin(), v.end()));

  cout << abs(a - b);

  return 0;
}
Problem p02813 (Python)

Buggy submission (status: Runtime Error):
# ABC150C - Count Order
from itertools import permutations


def main():
    N, *PQ = map(int, open(0).read().split())
    P, Q = PQ[:N], PQ[N:]
    perms = list(permutations(range(1, N + 1)))
    ans = abs(perms.index(P) - perms.index(Q))
    print(ans)


if __name__ == "__main__":
    main()


Fixed submission:
# ABC150C - Count Order
from itertools import permutations


def main():
    N = int(input())
    P = tuple(map(int, input().split()))
    Q = tuple(map(int, input().split()))
    perms = tuple(permutations(range(1, N + 1)))
    ans = abs(perms.index(P) - perms.index(Q))
    print(ans)


if __name__ == "__main__":
    main()
Problem p02813 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  vector<int> a, b, c, d;

  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    c.push_back(x);
  }

  for (int i = 0; i < n; i++) {
    int y;
    cin >> y;
    d.push_back(y);
  }

  for (int i = 0; i < n; i++) {
    a.push_back(i + 1);
    b.push_back(i + 1);
  }

  if (c == d) {
    cout << 0 << endl;
  } else {
    int cnt1 = 0, cnt2 = 0;

    while (a != c) {
      cnt1++;
      next_permutation(a.begin(), a.end());
    }

    while (b != d) {
      cnt2++;
      next_permutation(b.begin(), b.end());
    }
    cout << abs(cnt1 - cnt2) << endl;
  }
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  // #ifndef ONLINE_JUDGE
  // freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);
  // #endif
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  vector<int> a, b, c, d;

  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    c.push_back(x);
  }

  for (int i = 0; i < n; i++) {
    int y;
    cin >> y;
    d.push_back(y);
  }

  for (int i = 0; i < n; i++) {
    a.push_back(i + 1);
    b.push_back(i + 1);
  }

  if (c == d) {
    cout << 0 << endl;
  } else {
    int cnt1 = 0, cnt2 = 0;

    while (a != c) {
      cnt1++;
      next_permutation(a.begin(), a.end());
    }

    while (b != d) {
      cnt2++;
      next_permutation(b.begin(), b.end());
    }
    cout << abs(cnt1 - cnt2) << endl;
  }
}