import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Arrays; import java.util.Scanner; import java.util.logging.Level; import java.util.logging.Logger; /* * 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); BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); try { Scanner sc = new Scanner(System.in); while (sc.hasNext()) { n = sc.nextInt(); //t = new int[n]; c = new int[n]; String line = br.readLine(); for (int i = 0; i < n-1; i++) { int spaceindex = line.indexOf(" "); c[i] = Integer.parseInt(line.substring(0,spaceindex))-1; line = line.substring(spaceindex+1); } c[n-1]=Integer.parseInt(line.trim())-1; //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; } } catch (IOException ex) { Logger.getLogger(Monsters.class.getName()).log(Level.SEVERE, null, ex); } } /*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(); } }