#include<stdio.h>
#include<stdlib.h>

int arm(int [], int);
void swap(int *, int *);

int main(){
  int *A;
  int n, cost=0;
  int i;

  scanf("%d",&n);

  A = (int *)malloc(n * sizeof(int));

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

  cost = arm(A, n);
  
  printf("%d\n",cost);

  free(A);
  return 0;
}

int arm(int A[], int n){
  int cost = 0;
  int i;
  
  for(i=0; i<n; i++){
    if((i+1) != A[i]){
      cost += A[i] + A[A[i]-1];
      swap(&A[i], &A[A[i]-1]);
    }
  }
  
  return cost;
}

void swap(int *a, int *b){
  int tmp;

  tmp = *a;
  *a = *b;
  *b = tmp;
}

