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

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#include <iostream>
#include <limits.h>
#include <list>
#include <math.h>
#include <queue>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <vector>

using namespace std;

int main() {
  char *str;
  scanf("%s", str);

  for (int i = 0; i < 12; i++) {
    cout << str[i];
    if (i == 3)
      cout << " ";
  }
  cout << endl;

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#include <iostream>
#include <limits.h>
#include <list>
#include <math.h>
#include <queue>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <vector>

using namespace std;

int main() {
  char str[15];
  scanf("%s", str);

  for (int i = 0; i < 12; i++) {
    cout << str[i];
    if (i == 3)
      cout << " ";
  }
  cout << endl;

  return 0;
}
Problem p03992 (C++)

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

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

int main() {
  string s;
  for (int i = 0; i < 4; i++) {
    cout << s.at(i);
  }
  cout << " ";
  for (int i = 4; i < 12; i++) {
    cout << s.at(i);
  }
  cout << endl;
}

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

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

int main() {
  string s;
  cin >> s;
  for (int i = 0; i < 4; i++) {
    cout << s.at(i);
  }
  cout << " ";
  for (int i = 4; i < 12; i++) {
    cout << s.at(i);
  }
  cout << endl;
}
Problem p03992 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
#include <string>
int main() {
  std::string S;
  std::cin >> S;
  for (int i = 0; i < 4;)
    std::cout << S[i];

  std::cout << " ";

  for (int i = 4; i < 12; i++)
    std::cout << S[i];

  std::cout << std::endl;
}

Fixed submission:
#include <iostream>
#include <string>
int main() {
  std::string S;
  std::cin >> S;
  std::cout << S[0] << S[1] << S[2] << S[3] << " " << S[4] << S[5] << S[6]
            << S[7] << S[8] << S[9] << S[10] << S[11] << std::endl;
}
Problem p03992 (C++)

Buggy submission (status: Runtime Error):
#include <cstdio>

using namespace std;

typedef long long ll;

char s[10];

int main() {
  scanf("%s", s);
  for (int i = 0; i < 12; i++) {
    if (i == 4)
      putchar(' ');
    putchar(s[i]);
  }
  putchar('\n');
}


Fixed submission:
#include <cstdio>

using namespace std;

typedef long long ll;

char s[13];

int main() {
  scanf("%s", s);
  for (int i = 0; i < 12; i++) {
    if (i == 4)
      putchar(' ');
    putchar(s[i]);
  }
  putchar('\n');
}
Problem p03992 (C++)

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

int main() {
  string s;
  cin >> s;
  string str1, str2, str3;
  str2 = " ";
  for (int i = 0; i < 4; i++) {
    str1.at(i) = s.at(i);
  }
  for (int i = 0; i < 8; i++) {
    str3.at(i) = s.at(i + 4);
  }
  cout << str1 << str2 << str3 << endl;
}


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

int main() {
  string s;
  cin >> s;
  string str1 = "1234", str2 = " ", str3 = "12345678";
  for (int i = 0; i < 4; i++) {
    str1.at(i) = s.at(i);
  }
  for (int i = 0; i < 8; i++) {
    str3.at(i) = s.at(i + 4);
  }
  cout << str1 << str2 << str3 << endl;
}
Problem p03992 (C++)

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

int main() {
  string buff;
  getline(cin, buff);
  string add = " ";
  buff.append(add, 4, 1);
  cout << buff << endl;
}

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

int main() {
  string buff;
  getline(cin, buff);
  string add = " ";
  buff.insert(4, " ");
  cout << buff << endl;
}
Problem p03992 (C++)

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

using namespace std;

#define ALL(x) begin(x), end(x)

typedef long long ll;
typedef pair<int, int> ipair;

// const int INF = (int)1.1e9;

int main() {
#ifndef MY
  freopen("cards.in", "r", stdin);
  freopen("cards.out", "w", stdout);
  cin.tie(0);
#endif
  ios_base::sync_with_stdio(0);

  string s;
  cin >> s;
  cout << s.substr(0, 4) + " " + s.substr(4) << "\n";
}


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

using namespace std;

#define ALL(x) begin(x), end(x)

typedef long long ll;
typedef pair<int, int> ipair;

// const int INF = (int)1.1e9;

int main() {
#ifndef MY
  // freopen("cards.in", "r", stdin);
  // freopen("cards.out", "w", stdout);
  cin.tie(0);
#endif
  ios_base::sync_with_stdio(0);

  string s;
  cin >> s;
  cout << s.substr(0, 4) + " " + s.substr(4) << "\n";
}
Problem p03992 (C++)

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

using namespace std;

int main() {
#ifndef ONLINE_JUDGE
  freopen("in", "r", stdin);
  freopen("out", "w", stdout);
#endif
  ios_base::sync_with_stdio(0);
  string s;
  cin >> s;
  for (int i = 0; i < 4; i++) {
    cout << s[i];
  }
  cout << " ";
  for (int i = 4; i < s.size(); i++) {
    cout << s[i];
  }
  cout << "\n";
  return 0;
}


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

using namespace std;

int main() {
  /*
  #ifndef ONLINE_JUDGE
    freopen("in", "r", stdin);
    freopen("out", "w", stdout);
  #endif
  */
  ios_base::sync_with_stdio(0);
  string s;
  cin >> s;
  for (int i = 0; i < 4; i++) {
    cout << s[i];
  }
  cout << " ";
  for (int i = 4; i < s.size(); i++) {
    cout << s[i];
  }
  cout << "\n";
  return 0;
}
Problem p03992 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;
int main(void) {
  string s;
  cout << s.substr(0, 4) << " " << s.substr(4, 8);
}

Fixed submission:
#include <iostream>
using namespace std;
int main(void) {
  string s;
  cin >> s;
  cout << s.insert(4, " ") << endl;
}
Problem p03993 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 1000000007
int main() {
  int n;
  cin >> n;
  int a[10000], x;
  for (int i = 0; i < n; i++)
    a[i] = -1;
  for (int i = 0; i < n; i++) {
    cin >> x;
    a[i] = x - 1;
  }
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    if (i == a[a[i]])
      cnt += 1;
    // cout << a[a[i]] << i << endl;
  }
  cout << cnt / 2 << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 1000000007
int main() {
  int n;
  cin >> n;
  int a[100000], x;
  for (int i = 0; i < n; i++)
    a[i] = -1;
  for (int i = 0; i < n; i++) {
    cin >> x;
    a[i] = x - 1;
  }
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    if (i == a[a[i]])
      cnt += 1;
    // cout << a[a[i]] << i << endl;
  }
  cout << cnt / 2 << endl;
}
Problem p03993 (C++)

Buggy submission (status: Runtime Error):
#include <math.h>
#include <stdio.h>

int main() {
  int n;
  int an[30];
  int i, ans;

  scanf("%d", &n);
  for (i = 0; i < n; ++i) {
    scanf("%d", an + i);
  }

  for (i = 0; i < n; ++i) {
    an[i] = an[i] - 1;
  }

  ans = 0;
  for (i = 0; i < n; ++i) {
    if (an[i] > i) {
      ans += ((an[an[i]] == i) ? 1 : 0);
    }
  }

  printf("%d\n", ans);

  return 0;
}


Fixed submission:
#include <math.h>
#include <stdio.h>

int main() {
  int n;
  int an[100000];
  int i, ans;

  scanf("%d", &n);
  for (i = 0; i < n; ++i) {
    scanf("%d", an + i);
  }

  for (i = 0; i < n; ++i) {
    an[i] = an[i] - 1;
  }

  ans = 0;
  for (i = 0; i < n; ++i) {
    if (an[i] > i) {
      ans += ((an[an[i]] == i) ? 1 : 0);
    }
  }

  printf("%d\n", ans);

  return 0;
}
Problem p03993 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;
const int maxx = 10001;
int main() {
  int n, ans = 0;
  int tab[maxx];
  cin >> n;
  for (auto i = 0; i < n; ++i)
    cin >> tab[i];
  for (auto i = 0; i < n; ++i) {
    if (i + 1 == tab[tab[i] - 1])
      ++ans;
  }
  cout << ans / 2 << endl;
  return 0;
}

Fixed submission:
#include <iostream>
using namespace std;
const int maxx = 100001;
int main() {
  int n, ans = 0;
  int tab[maxx];
  cin >> n;
  for (auto i = 0; i < n; ++i)
    cin >> tab[i];
  for (auto i = 0; i < n; ++i) {
    if (i + 1 == tab[tab[i] - 1])
      ++ans;
  }
  cout << ans / 2 << endl;
  return 0;
}
Problem p03993 (C++)

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

#define _ << " " <<
#define tr(x) cout << #x _ x << endl
#define fi first
#define se second

#ifdef _WIN32
#define LD "%I64d"
#else
#define LD "%ld"
#endif

using namespace std;

typedef long long ll;

const int maxn = 11111;

int n;
int a[maxn];

int read() {
  if (scanf("%d", &n) < 1) {
    return 0;
  }
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  return 1;
}

void solve() {
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    if (i < a[i] && i == a[a[i]])
      ans++;
  }
  printf("%d\n", ans);
}

int main(int argc, char *argv[]) {
  while (read()) {
    solve();
  }
}


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

#define _ << " " <<
#define tr(x) cout << #x _ x << endl
#define fi first
#define se second

#ifdef _WIN32
#define LD "%I64d"
#else
#define LD "%ld"
#endif

using namespace std;

typedef long long ll;

const int maxn = 100100;

int n;
int a[maxn];

int read() {
  if (scanf("%d", &n) < 1) {
    return 0;
  }
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  return 1;
}

void solve() {
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    if (i < a[i] && i == a[a[i]])
      ans++;
  }
  printf("%d\n", ans);
}

int main(int argc, char *argv[]) {
  while (read()) {
    solve();
  }
}
Problem p03993 (C++)

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

int main() {
  int n;
  int a[10002];
  int res = 0;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < n; i++) {
    if (a[i] == 0)
      continue;
    else if (a[a[i]] == i) {
      res++;
      a[i] = a[a[i]] = 0;
    }
  }
  cout << res << endl;
  return 0;
}

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

int main() {
  int n;
  int a[100002];
  int res = 0;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < n; i++) {
    if (a[i] == 0)
      continue;
    else if (a[a[i]] == i) {
      res++;
      a[i] = a[a[i]] = 0;
    }
  }
  cout << res << endl;
  return 0;
}
Problem p03993 (C++)

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

const int MOD = 1000000007;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define copy(from, to) copy(from.begin(), from.end(), back_inserter(to))
#define sort(a) sort(a.begin(), a.end())
#define reverse(s) reverse(s.begin(), s.end())
#define p(s) cout << (s) << endl

typedef long long ll;
using namespace std;

template <class T> void load(vector<T> &v, int n) {
  for (int i = 0; i < n; ++i) {
    T t;
    cin >> t;
    v.push_back(t);
  }
}

template <class T> T max(vector<T> &v) {
  return *max_element(v.begin(), v.end());
}

template <class T> T min(vector<T> &v) {
  return *min_element(v.begin(), v.end());
}

void py(bool isUpper = false) {
  if (isUpper) {
    p("YES");
  } else {
    p("Yes");
  }
}

void pn(bool isUpper = false) {
  if (isUpper) {
    p("NO");
  } else {
    p("No");
  }
}

int main() {
  int n;
  cin >> n;
  int a[n + 1];

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

  int c = 0;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= n; ++j) {
      if (i == a[j] && a[i] == j)
        c++;
    }
  }
  // ダブルカウントしているので半分にする
  p(c / 2);
}

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

const int MOD = 1000000007;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define copy(from, to) copy(from.begin(), from.end(), back_inserter(to))
#define sort(a) sort(a.begin(), a.end())
#define reverse(s) reverse(s.begin(), s.end())
#define p(s) cout << (s) << endl

typedef long long ll;
using namespace std;

template <class T> void load(vector<T> &v, int n) {
  for (int i = 0; i < n; ++i) {
    T t;
    cin >> t;
    v.push_back(t);
  }
}

template <class T> T max(vector<T> &v) {
  return *max_element(v.begin(), v.end());
}

template <class T> T min(vector<T> &v) {
  return *min_element(v.begin(), v.end());
}

void py(bool isUpper = false) {
  if (isUpper) {
    p("YES");
  } else {
    p("Yes");
  }
}

void pn(bool isUpper = false) {
  if (isUpper) {
    p("NO");
  } else {
    p("No");
  }
}

int main() {
  int n;
  cin >> n;
  int a[n + 1];

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

  int c = 0;
  for (int i = 1; i <= n; ++i) {
    if (a[a[i]] == i)
      c++;
  }
  // ダブルカウントしているので半分にする
  p(c / 2);
}
Problem p03993 (C++)

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

#ifdef _MSC_VER
#include <Windows.h>
#else
#include <unistd.h>
#endif

using namespace std;

// conversion
//------------------------------------------
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T> inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

// math
//-------------------------------------------
template <class T> inline T sqr(T x) { return x * x; }

// typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
typedef long long LL;
// container util
//------------------------------------------
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(), (c).end())

// repetition
//------------------------------------------
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

// constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);

// clear memory
#define CLR(a) memset((a), 0, sizeof(a))

int main() {
  int N;
  cin >> N;
  int a[10004];
  REP(i, N) {
    cin >> a[i];
    a[i]--;
  }
  int cnt = 0;
  REP(i, N) {
    if (a[a[i]] == i)
      cnt++;
  }
  cout << cnt / 2 << endl;
  return 0;
}

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

#ifdef _MSC_VER
#include <Windows.h>
#else
#include <unistd.h>
#endif

using namespace std;

// conversion
//------------------------------------------
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T> inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

// math
//-------------------------------------------
template <class T> inline T sqr(T x) { return x * x; }

// typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
typedef long long LL;
// container util
//------------------------------------------
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(), (c).end())

// repetition
//------------------------------------------
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

// constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);

// clear memory
#define CLR(a) memset((a), 0, sizeof(a))

int main() {
  int N;
  cin >> N;
  int a[100004];
  REP(i, N) {
    cin >> a[i];
    a[i]--;
  }
  int cnt = 0;
  REP(i, N) {
    if (a[a[i]] == i)
      cnt++;
  }
  cout << cnt / 2 << endl;
  return 0;
}
Problem p03993 (C++)

Buggy submission (status: Runtime Error):
#include <stdio.h>
int main() {
  int N;
  int i = 0;
  int a[10000];
  int sum = 0;
  int temp;
  scanf("%d", &N);
  for (i = 0; i < N; i++) {
    scanf("%d", &a[i]);
  }
  for (i = 0; i < N; i++) {
    temp = a[i];

    if (i + 1 == a[temp - 1])
      sum++;
  }

  printf("%d\n", sum / 2);
  return 0;
}


Fixed submission:
#include <stdio.h>
int main() {
  int N;
  int i = 0;
  int a[100000];
  int sum = 0;
  int temp;
  scanf("%d", &N);
  for (i = 0; i < N; i++) {
    scanf("%d", &a[i]);
  }
  for (i = 0; i < N; i++) {
    temp = a[i];

    if (i + 1 == a[temp - 1])
      sum++;
  }

  printf("%d\n", sum / 2);
  return 0;
}
Problem p03993 (Python)

Buggy submission (status: Time Limit Exceeded):
#!/usr/bin/env python3

n = int(input())
a = [int(x) for x in input().split()]
c = 0
b = [{i + 1, x} for i, x in enumerate(a)]
for i, e in enumerate(sorted(b)):
    if b.count(e) == 2:
        c += 1
print(c // 2)


Fixed submission:
#!/usr/bin/env python3

n = int(input())
a = [int(x) for x in input().split()]
c = 0
for i, ax in enumerate(a):
    if a[ax - 1] == i + 1:
        c += 1
print(c // 2)
Problem p03993 (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)

int R[10001];

int main(void) {
  int N, a;
  cin >> N;
  rep(i, N) {
    cin >> a;
    R[i] = a - 1;
  }
  int ans = 0;
  rep(i, N) {
    if (R[R[i]] == i)
      ans++;
  }
  cout << ans / 2 << endl;
}

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

int R[100001];

int main(void) {
  int N, a;
  cin >> N;
  rep(i, N) {
    cin >> a;
    R[i] = a - 1;
  }
  int ans = 0;
  rep(i, N) {
    if (R[R[i]] == i)
      ans++;
  }
  cout << ans / 2 << endl;
}
Problem p03993 (Python)

Buggy submission (status: Runtime Error):
n = int(input())
a = list(map(int, input().split()))

like = {}
ans = 0

for i, r in enumerate(a):
    like[i] = r
    if like.get(r, default=0) == i:
        ans += 1

print(ans)


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

like = {}
ans = 0

for i, r in enumerate(a):
    like[i + 1] = r
    if r in like and like[r] == i + 1:
        ans += 1

print(ans)
Problem p03993 (C++)

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

using namespace std;

int n, k;
int a[10100];

int main() {
  cin >> n;
  for (int i = 0; i < n; ++i)
    cin >> a[i + 1];
  for (int i = 1; i <= n; ++i)
    if (a[a[i]] == i)
      ++k;
  cout << k / 2;

  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <queue>
#include <string>

using namespace std;

int n, k;
int a[100100];

int main() {
  cin >> n;
  for (int i = 0; i < n; ++i)
    cin >> a[i + 1];
  for (int i = 1; i <= n; ++i)
    if (a[a[i]] == i)
      ++k;
  cout << k / 2;

  return 0;
}
Problem p03993 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>

using namespace std;

int a[10001];

int main() {
  int N, n = 0;
  cin >> N;
  for (int i = 1; i <= N; i++) {
    cin >> a[i];
    if (a[a[i]] == i)
      n++;
  }
  cout << n << endl;
}

Fixed submission:
#include <iostream>

using namespace std;

int a[1000000];

int main() {
  int N, n = 0;
  cin >> N;
  for (int i = 1; i <= N; i++) {
    cin >> a[i];
    if (a[a[i]] == i)
      n++;
  }
  cout << n << endl;
}
Problem p03993 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>

using namespace std;
int main() {

  int n;
  cin >> n;
  int a[10001];
  int p = 0;
  for (int i = 1; i < n + 1; i++) {
    cin >> a[i];
  }
  for (int i = 1; i < n + 1; i++) {
    if (a[a[i]] == i) {
      p++;
    }
  }

  cout << p / 2 << endl;
  return 0;
}


Fixed submission:
#include <iostream>

using namespace std;
int main() {

  int n;
  cin >> n;
  int a[100001];
  int p = 0;
  for (int i = 1; i < n + 1; i++) {
    cin >> a[i];
  }
  for (int i = 1; i < n + 1; i++) {
    if (a[a[i]] == i) {
      p++;
    }
  }

  cout << p / 2 << endl;
  return 0;
}
Problem p03993 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;

#define rep(i, x) for (int i = 0; i < (int)(x); ++i)
#define reps(i, x) for (int i = 1; i <= (int)(x); ++i)
#define rrep(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define pb push_back

int n;

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

  cin >> n;
  int a[100];

  rep(i, n) {
    cin >> a[i];
    --a[i];
  }

  int sum = 0;
  rep(i, n) {
    int j = a[i];
    if (a[j] == i)
      ++sum;
  }

  cout << (sum / 2) << endl;

  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;

#define rep(i, x) for (int i = 0; i < (int)(x); ++i)
#define reps(i, x) for (int i = 1; i <= (int)(x); ++i)
#define rrep(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define pb push_back

int n;

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

  cin >> n;
  int a[100000];

  rep(i, n) {
    cin >> a[i];
    --a[i];
  }

  int sum = 0;
  rep(i, n) {
    int j = a[i];
    if (a[j] == i)
      ++sum;
  }

  cout << (sum / 2) << endl;

  return 0;
}
Problem p03993 (C++)

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

int main() {
  int n = 0, cnt = 0;
  int a[100000] = {0};
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < n - 1; i++) {
    for (int j = i; j < n; j++) {
      if (((i + 1) == a[j] && (j + 1) == a[i]) && i != j) {
        cnt++;
        break;
      }
    }
  }
  cout << cnt << endl;

  return 0;
}

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

int main() {
  int n = 0, cnt = 0;
  int a[100000] = {0};
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < n; i++) {
    if (a[a[i] - 1] == i + 1 && i < a[i]) {
      cnt++;
    }
  }
  cout << cnt << endl;

  return 0;
}
Problem p03993 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <chrono>
#include <cmath>
#include <deque>
#include <functional>
#include <iostream>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <tuple>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long int llint;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
const llint mod = 1000000007;
const llint big = 1e9 + 10;
const long double pai = 3.141592653589793238462643383279;
template <class T, class U> void mineq(T &a, U b) {
  if (a > b) {
    a = b;
  }
}
template <class T, class U> void maxeq(T &a, U b) {
  if (a < b) {
    a = b;
  }
}
llint gcd(llint a, llint b) {
  if (b == 0) {
    return a;
  }
  return gcd(b, a % b);
} // a>b
llint lcm(llint a, llint b) { return (a / gcd(max(a, b), min(a, b))) * b; }
int main(void) {
  int i, n, ans = 0;
  cin >> n;
  vector<int> a;
  for (i = 0; i < n; i++) {
    cin >> a[i];
    a[i]--;
  }
  for (i = 0; i < n; i++) {
    if (i == a[a[i]]) {
      ans++;
    }
  }
  ans /= 2;
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <chrono>
#include <cmath>
#include <deque>
#include <functional>
#include <iostream>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <tuple>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long int llint;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
const llint mod = 1000000007;
const llint big = 1e9 + 10;
const long double pai = 3.141592653589793238462643383279;
template <class T, class U> void mineq(T &a, U b) {
  if (a > b) {
    a = b;
  }
}
template <class T, class U> void maxeq(T &a, U b) {
  if (a < b) {
    a = b;
  }
}
llint gcd(llint a, llint b) {
  if (b == 0) {
    return a;
  }
  return gcd(b, a % b);
} // a>b
llint lcm(llint a, llint b) { return (a / gcd(max(a, b), min(a, b))) * b; }
int main(void) {
  int i, n, ans = 0;
  cin >> n;
  vector<int> a(n);
  for (i = 0; i < n; i++) {
    cin >> a[i];
    a[i]--;
  }
  for (i = 0; i < n; i++) {
    if (i == a[a[i]]) {
      ans++;
    }
  }
  ans /= 2;
  cout << ans << endl;
  return 0;
}
Problem p03993 (C++)

Buggy submission (status: Runtime Error):
#include <cstdio>

int main() {
  int n;
  int a[10000], f[10000] = {};

  scanf("%d", &n);
  for (int i = 0; i < n; i++)
    scanf("%d", &a[i]);

  int res = 0;
  for (int i = 0; i < n; i++) {
    if (f[i] == 0 && i == a[a[i] - 1] - 1) {
      res++;
      f[i] = 1;
      f[a[i] - 1] = 1;
    }
  }
  printf("%d\n", res);

  return 0;
}


Fixed submission:
#include <cstdio>

int main() {
  int n;
  int a[100000], f[100000] = {};

  scanf("%d", &n);
  for (int i = 0; i < n; i++)
    scanf("%d", &a[i]);

  int res = 0;
  for (int i = 0; i < n; i++) {
    if (f[i] == 0 && i == a[a[i] - 1] - 1) {
      res++;
      f[i] = 1;
      f[a[i] - 1] = 1;
    }
  }
  printf("%d\n", res);

  return 0;
}
Problem p03993 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>

using namespace std;

int main() {
  int n;
  cin >> n;
  int a[10010];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    a[i]--;
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] > i && a[a[i]] == i)
      ans++;
  }
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <iostream>

using namespace std;

int main() {
  int n;
  cin >> n;
  int a[100010];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    a[i]--;
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] > i && a[a[i]] == i)
      ans++;
  }
  cout << ans << endl;
  return 0;
}
Problem p03993 (C++)

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

int main() {
  int N;
  int a[10000] = {0};
  int result2 = 0;
  int result = 0;

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

  for (int i = 0; i < N; i++) {
    if (a[a[i]] == i) {
      result2++;
    }
  }
  result = result2 / 2;

  cout << result << endl;
  return 0;
}


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

int main() {
  int N;
  int a[100000] = {0};
  int result2 = 0;
  int result = 0;

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

  for (int i = 0; i < N; i++) {
    if (a[a[i]] == i) {
      result2++;
    }
  }
  result = result2 / 2;

  cout << result << endl;
  return 0;
}
Problem p03993 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cstring>
#include <iostream>
#include <map>
#include <math.h>
#include <memory.h>
#include <queue>
#include <stack>
#include <stdio.h>
#include <string>

#define INFI 0x7fffffff
#define MAXN 100010

using namespace std;

#define MAXN 40010

int ma[MAXN];

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i)
    scanf("%d", &ma[i]);
  int ans = 0;
  for (int i = 1; i <= n; ++i) {
    if (ma[i] <= i && ma[ma[i]] == i)
      ++ans;
  }
  printf("%d\n", ans);
  return 0;
}


Fixed submission:
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cstring>
#include <iostream>
#include <map>
#include <math.h>
#include <memory.h>
#include <queue>
#include <stack>
#include <stdio.h>
#include <string>

#define INFI 0x7fffffff
#define MAXN 100010

using namespace std;

int ma[MAXN];

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i)
    scanf("%d", &ma[i]);
  int ans = 0;
  for (int i = 1; i <= n; ++i) {
    if (ma[i] <= i && ma[ma[i]] == i)
      ++ans;
  }
  printf("%d\n", ans);
  return 0;
}
Problem p03993 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define pii pair<int, int>
#define piii pair<int, pii>
#define mp make_pair
#define pb push_back
#define ALL(a) (a).begin(), (a).end()
#define FST first
#define SEC second
const int INF = (INT_MAX / 2);
const ll LLINF = (LLONG_MAX / 2);
const double eps = 1e-5;
const double PI = M_PI;
#define DEB cerr << "!" << endl
#define SHOW(a, b) cerr << (a) << " " << (b) << endl
#define SHOWARRAY(ar, i, j)                                                    \
  REP(a, i)                                                                    \
      REP(b, j) cerr << ar[a][b]                                               \
                     << ((b == j - 1) ? ((a == i - 1) ? ("\n\n") : ("\n"))     \
                                      : (" "))

#define DIV 1000000007
typedef vector<ll> Array;
typedef vector<Array> matrix;
typedef tuple<int, int, int> tiii;
#define mt make_tuple

vector<set<int>> vs(10001);
int main() {
  int n;
  cin >> n;
  int ans = 0;
  rep(i, n) {
    int t;
    cin >> t;
    vs[t].insert(i + 1);
    if (vs[i + 1].find(t) != vs[i + 1].end())
      ans++;
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define pii pair<int, int>
#define piii pair<int, pii>
#define mp make_pair
#define pb push_back
#define ALL(a) (a).begin(), (a).end()
#define FST first
#define SEC second
const int INF = (INT_MAX / 2);
const ll LLINF = (LLONG_MAX / 2);
const double eps = 1e-5;
const double PI = M_PI;
#define DEB cerr << "!" << endl
#define SHOW(a, b) cerr << (a) << " " << (b) << endl
#define SHOWARRAY(ar, i, j)                                                    \
  REP(a, i)                                                                    \
      REP(b, j) cerr << ar[a][b]                                               \
                     << ((b == j - 1) ? ((a == i - 1) ? ("\n\n") : ("\n"))     \
                                      : (" "))

#define DIV 1000000007
typedef vector<ll> Array;
typedef vector<Array> matrix;
typedef tuple<int, int, int> tiii;
#define mt make_tuple

vector<set<int>> vs(100001);
int main() {
  int n;
  cin >> n;
  int ans = 0;
  rep(i, n) {
    int t;
    cin >> t;
    vs[t].insert(i + 1);
    if (vs[i + 1].find(t) != vs[i + 1].end())
      ans++;
  }
  cout << ans << endl;
  return 0;
}
Problem p03993 (C++)

Buggy submission (status: Runtime Error):

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define INF 1050000000
#define MOD 1000000007

using namespace std;

int main() {
  int n;
  cin >> n;
  int a[100 + 1];
  for (int i = 1; i < n + 1; i++) {
    cin >> a[i];
  }
  int ans = 0;
  for (int i = 1; i < n + 1; i++) {
    if (i == a[a[i]]) {
      ans++;
    }
  }

  cout << ans / 2 << endl;
}

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define INF 1050000000
#define MOD 1000000007

using namespace std;

int main() {
  int n;
  cin >> n;
  int a[n + 1];
  for (int i = 1; i < n + 1; i++) {
    cin >> a[i];
  }
  int ans = 0;
  for (int i = 1; i < n + 1; i++) {
    if (i == a[a[i]]) {
      ans++;
    }
  }

  cout << ans / 2 << endl;
}
Problem p03993 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <complex>
#include <cstdio>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;

#define rep(i, n) for (int i = 0; i < n; i++)
#define FOR(i, a, n) for (int i = a = ; i <= n; i++)

int main() {
  int n;
  map<int, int> a;
  while (cin >> n) {
    int cnt = 0;
    for (int i = 1; i <= n; i++) {
      cin >> a[i];
    }
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= n; j++) {
        if (a[i] == j && a[j] == i)
          cnt++;
      }
    }
    cout << cnt / 2 << endl;
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <complex>
#include <cstdio>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;

#define rep(i, n) for (int i = 0; i < n; i++)
#define FOR(i, a, n) for (int i = a = ; i <= n; i++)

int main() {
  int n;
  map<int, int> a;
  while (cin >> n) {
    int cnt = 0;
    for (int i = 1; i <= n; i++) {
      cin >> a[i];
    }
    for (int i = 1; i <= n; i++) {
      if (i == a[a[i]])
        cnt++;
    }
    cout << cnt / 2 << endl;
  }
  return 0;
}
Problem p03993 (C++)

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

using namespace std;

int main() {
  int n = 0;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
  }
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    if (a.at(a.at(i)) == i) {
      cnt++;
    }
  }
  cout << cnt / 2 << endl;
  return 0;
}


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

using namespace std;

int main() {
  int n = 0;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
  }
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    if (a.at(a.at(i) - 1) == i + 1) {
      cnt++;
    }
  }
  cout << cnt / 2 << endl;
  return 0;
}
Problem p03993 (C++)

Buggy submission (status: Runtime Error):
#include <stdio.h>

int n;
int d[10100], t;

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

  for (int i = 1; i <= n; i++)
    scanf("%d", &d[i]);

  for (int i = 1; i <= n; i++)
    if (d[d[i]] == i)
      t++;

  printf("%d\n", t / 2);
}

Fixed submission:
#include <stdio.h>

int n;
int d[100100], t;

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

  for (int i = 1; i <= n; i++)
    scanf("%d", &d[i]);

  for (int i = 1; i <= n; i++)
    if (d[d[i]] == i)
      t++;

  printf("%d\n", t / 2);
}
Problem p03993 (C++)

Buggy submission (status: Runtime Error):
#include <cmath>
#include <fstream>
#include <iostream>
#include <string>
using namespace std;
int a[10 ^ 5];

int main() {
  int N, j, num;
  num = 0;
  cin >> N;
  for (int i = 0; i < N; i++) {
    scanf("%d", &a[i]);
  }
  for (int i = 0; i < N; i++) {
    j = a[i];
    if (a[j - 1] == i + 1)
      num = num + 1;
  }
  cout << num / 2 << endl;
  return 0;
};

Fixed submission:
#include <cmath>
#include <fstream>
#include <iostream>
#include <string>
using namespace std;
int a[100000];

int main() {
  int N, j, num;
  num = 0;
  cin >> N;
  for (int i = 0; i < N; i++) {
    scanf("%d", &a[i]);
  }
  for (int i = 0; i < N; i++) {
    j = a[i];
    if (a[j - 1] == i + 1)
      num = num + 1;
  }
  cout << num / 2 << endl;
  return 0;
};
Problem p03993 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
int friends[10000];
int N;
int ans = 0;
int main(void) {
  std::cin >> N;
  for (int i = 0; i < N; i++) {
    std::cin >> friends[i];
  }
  for (int i = 0; i < N; i++) {
    if (friends[friends[i] - 1] == i + 1)
      ans++;
  }
  ans /= 2;
  std::cout << ans << std::endl;
  return 0;
}

Fixed submission:
#include <iostream>
int friends[100000];
int N;
int ans = 0;
int main(void) {
  std::cin >> N;
  for (int i = 0; i < N; i++) {
    std::cin >> friends[i];
  }
  for (int i = 0; i < N; i++) {
    if (friends[friends[i] - 1] == i + 1)
      ans++;
  }
  ans /= 2;
  std::cout << ans << std::endl;
  return 0;
}
Problem p03993 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdlib.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define loop(i, l, r) for (int(i) = (int)(l); (i) < (int)(r); (i)++)
#define rloop(i, l, r) for (int(i) = (int)(l); (i) > (int)(r); (i)--)
#define rep(i, n) loop(i, 0, n)
#define rrep(i, n) rloop(i, n - 1, -1)
#define INF 0x3f3f3f3f
#define mod 1000000007LL
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef complex<double> C;

int main() {
  int n, d, a[10001] = {}, res = 0;
  cin >> n;
  rep(i, n) {
    cin >> d;
    a[i + 1] = d;
    if (a[d] == i + 1)
      res++;
  }
  cout << res << endl;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdlib.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define loop(i, l, r) for (int(i) = (int)(l); (i) < (int)(r); (i)++)
#define rloop(i, l, r) for (int(i) = (int)(l); (i) > (int)(r); (i)--)
#define rep(i, n) loop(i, 0, n)
#define rrep(i, n) rloop(i, n - 1, -1)
#define INF 0x3f3f3f3f
#define mod 1000000007LL
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef complex<double> C;

int main() {
  int n, d, a[100001] = {}, res = 0;
  cin >> n;
  rep(i, n) {
    cin >> d;
    a[i + 1] = d;
    if (a[d] == i + 1)
      res++;
  }
  cout << res << endl;
}
Problem p03993 (C++)

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

int main() {
  int i, n;
  int arr[10001];
  cin >> n;
  for (i = 1; i <= n; i++) {
    cin >> arr[i];
  }

  int cnt = 0;
  for (i = 1; i <= n; i++) {
    if (i == arr[arr[i]])
      cnt++;
  }
  cout << cnt / 2 << endl;
  return 0;
}


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

int main() {
  int i, n;
  int arr[100001];
  cin >> n;
  for (i = 1; i <= n; i++) {
    cin >> arr[i];
  }

  int cnt = 0;
  for (i = 1; i <= n; i++) {
    if (i == arr[arr[i]])
      cnt++;
  }
  cout << cnt / 2 << endl;
  return 0;
}
Problem p03993 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
constexpr int MOD = 1000000000 + 7;
constexpr int INF = 2000000000;
using namespace std;

int main() {
  int n;
  cin >> n;
  int ans = 0;
  int f[10001] = {};
  int a;
  for (int i = 0; i < n; i++) {
    cin >> a;
    f[i + 1] = a;
    if (f[a] == i + 1)
      ans++;
  }
  cout << ans << endl;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
constexpr int MOD = 1000000000 + 7;
constexpr int INF = 2000000000;
using namespace std;

int main() {
  int n;
  cin >> n;
  int ans = 0;
  int f[100001] = {};
  int a;
  for (int i = 0; i < n; i++) {
    cin >> a;
    f[i + 1] = a;
    if (f[a] == i + 1)
      ans++;
  }
  cout << ans << endl;
}
Problem p03993 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using pll = pair<ll, ll>;
using vb = vector<bool>;
const ll oo = 0x3f3f3f3f3f3f3f3fLL;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define has(c, i) ((c).find(i) != end(c))
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define FORD(i, a, b) for (int i = int(b) - 1; i >= (a); i--)
#define DB(X)                                                                  \
  ({                                                                           \
    if (1)                                                                     \
      cerr << "DB: " << (#X) << " = " << (X) << endl;                          \
  })

int main() {
  ios::sync_with_stdio(false);
  ll n;
  cin >> n;
  ll a[n];
  FOR(i, 0, n) {
    cin >> a[i];
    a[i]--;
  }
  ll res = 0;
  FOR(i, 0, n) {
    FOR(j, i + 1, n) {
      if (a[i] == j && a[j] == i)
        res++;
    }
  }
  cout << res << endl;
}

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

int main() {
  ios::sync_with_stdio(false);
  ll n;
  cin >> n;
  ll a[n];
  FOR(i, 0, n) {
    cin >> a[i];
    a[i]--;
  }
  ll res = 0;
  FOR(i, 0, n) {
    if (a[i] > i && a[a[i]] == i)
      res++;
  }
  cout << res << endl;
}
Problem p03993 (Python)

Buggy submission (status: Runtime Error):
N = map(int, input().split())
a = list(map(int, input().split()))
ans = 0
for i in range(N):
    j = a[i] - 1
    if i < j and a[j] - 1 == i:
        ans += 1
print(ans)


Fixed submission:
N = int(input())
a = list(map(int, input().split()))
ans = 0
for i in range(N):
    j = a[i] - 1
    if i < j and a[j] - 1 == i:
        ans += 1
print(ans)
Problem p03993 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
#include <list>
#include <queue>
#include <string>
#include <vector>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> v(n);
  vector<bool> f(n);

  for (int i = 0; i < n; i++) {
    cin >> v[i];
    f[i] = false;
  }
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      if (v[i] == j + 1 && v[j] == i + 1 && f[i] == false && f[j] == false) {
        cnt++;
        f[i] = f[j] = true;
        break;
      }
    }
  }
  cout << cnt << endl;

  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <list>
#include <queue>
#include <string>
#include <vector>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> v(n);
  vector<bool> f(n);

  for (int i = 0; i < n; i++) {
    cin >> v[i];
    f[i] = false;
  }
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    if (v[v[i] - 1] == i + 1 && f[i] == false && f[v[i] - 1] == false) {
      cnt++;
      f[i] = f[v[i] - 1] = true;
    }
  }
  cout << cnt << endl;

  return 0;
}
Problem p03993 (C++)

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

#define FOR(a, b, c) for (int a = b; a < c; a++)

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;

int main() {
  int n;
  cin >> n;
  int a[50];

  FOR(i, 0, n) { cin >> a[i]; }
  int ans = 0;
  FOR(i, 0, n) {
    if (i == a[(a[i] - 1)] - 1) {
      ans++;
    }
  }
  ans /= 2;
  cout << ans << endl;
}

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

#define FOR(a, b, c) for (int a = b; a < c; a++)

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;

int main() {
  int n;
  cin >> n;
  int a[n];

  FOR(i, 0, n) { cin >> a[i]; }
  int ans = 0;
  FOR(i, 0, n) {
    if (i == a[(a[i] - 1)] - 1) {
      ans++;
    }
  }
  ans /= 2;
  cout << ans << endl;
}
Problem p03994 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <vector>
using namespace std;
#define FOR(I, A, B) for (int I = (A); I < (B); ++I)
typedef long long ll;

int main() {
  string s;
  ll K;
  cin >> s >> K;
  FOR(i, 0, s.length()) {
    if (s[i] == 'a')
      continue;
    if (K >= 'z' - s[i] + 1) {
      K -= 'z' - s[i] + 1;
      s[i] = 'a';
    }
  }
  FOR(i, 0, K) {
    if (s[s.length() - 1] == 'z')
      s[s.length() - 1] = 'a';
    else
      s[s.length() - 1] = char(s[s.length() - 1] + 1);
  }

  cout << s << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <vector>
using namespace std;
#define FOR(I, A, B) for (int I = (A); I < (B); ++I)
typedef long long ll;

int main() {
  string s;
  ll K;
  cin >> s >> K;
  FOR(i, 0, s.length()) {
    if (s[i] == 'a')
      continue;
    if (K >= 'z' - s[i] + 1) {
      K -= 'z' - s[i] + 1;
      s[i] = 'a';
    }
  }
  K %= 26;
  FOR(i, 0, K) {
    if (s[s.length() - 1] == 'z')
      s[s.length() - 1] = 'a';
    else
      s[s.length() - 1] = char(s[s.length() - 1] + 1);
  }

  cout << s << endl;
  return 0;
}
Problem p03994 (C++)

Buggy submission (status: Time Limit Exceeded):
// ### In The Name Of GOD ###

//%% Remember; (((He))) is The (((Accepter))) %%

// GOD IS GREATER ...

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;

// #define int ll
#define pb push_back
#define bp pop_back
#define pf push_front
#define fp pop_front
#define X first
#define Y second
#define sz(a) (int)(a.size())
#define sg(a, b) (a + b - 1) / b

const int MOD = 1000 * 1000 * 1000 + 7;
const ll INF = 2000ll * 1000 * 1000 * 1000 * 1000 * 1000;
const int MAXN = 1000000 + 2;
const int MLOG = 22;
const int NMAX = 350; // ios_base :: sync_with_stdio(false);

int main() {
  ios_base ::sync_with_stdio(false);
  string s;
  cin >> s;
  int k;
  cin >> k;
  for (int i = 0; i < sz(s); i++) {
    if (s[i] == 'a')
      continue;
    if ('z' + 1 - s[i] <= k)
      k -= 'z' + 1 - s[i], s[i] = 'a';
  }
  while (k--) {
    s[sz(s) - 1]++;
    if (s[sz(s) - 1] == 'z' + 1)
      s[sz(s) - 1] = 'a';
  }
  cout << s;
}

Fixed submission:
// ### In The Name Of GOD ###

//%% Remember; (((He))) is The (((Accepter))) %%

// GOD IS GREATER ...

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;

// #define int ll
#define pb push_back
#define bp pop_back
#define pf push_front
#define fp pop_front
#define X first
#define Y second
#define sz(a) (int)(a.size())
#define sg(a, b) (a + b - 1) / b

const int MOD = 1000 * 1000 * 1000 + 7;
const ll INF = 2000ll * 1000 * 1000 * 1000 * 1000 * 1000;
const int MAXN = 1000000 + 2;
const int MLOG = 22;
const int NMAX = 350; // ios_base :: sync_with_stdio(false);

int main() {
  ios_base ::sync_with_stdio(false);
  string s;
  cin >> s;
  int k;
  cin >> k;
  for (int i = 0; i < sz(s); i++) {
    if (s[i] == 'a')
      continue;
    if ('z' + 1 - s[i] <= k)
      k -= 'z' + 1 - s[i], s[i] = 'a';
  }
  k %= 26;
  while (k--) {
    s[sz(s) - 1]++;
    if (s[sz(s) - 1] == 'z' + 1)
      s[sz(s) - 1] = 'a';
  }
  cout << s;
}