import java.util.Arrays; import java.util.Scanner; /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ /** * * @author cteam037 */ public class Monsters { int counter = 0; //int[] t; int[] c; int n = 0; void run() { Scanner sc = new Scanner(System.in); while (sc.hasNext()) { n = sc.nextInt(); //t = new int[n]; c = new int[n]; for (int i = 0; i < n; i++) { c[i] = sc.nextInt() - 1; } //inicialize(); //System.out.println(n+" b"); //9 8 10 5 3 2 4 7 6 1 for (int index = 0; index < n; index++) { while (c[index] != index) { //int where = get(index, index); int where = c[index]; int here = c[index]; c[index] = c[where]; c[where] = here; counter++; } } System.out.println(counter); counter = 0; } } /*int get(int ch, int what) { for (int i = ch; i < n; i++) { if (c[i] == what) { return i; } } System.out.println("chyba"); return -7; }*/ /*void inicialize() { //parent t[] /*t[0] = c[0]; for (int i = 1; i < n; i++) { int now = c[i]; if(t[i/2]>now){ t[i]=now; }else{ t[i+1]=now; } }*/ /*for (int i = 0; i < n; i++) { t[i] = c[i]; } Arrays.sort(t); }*/ public static void main(String[] args) { new Monsters().run(); } }