#include <stdio.h>

int main(){
  int n, i, j, sum = 0, temp;
  int w[1001];

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

  for(i=1; i<=n; i++){
    if(w[i] != i){
      for(j=i+1; j<=n; j++){
	if(w[j] == i){
	  temp = w[i];
	  w[i] = w[j];
	  w[j] = temp;
	  sum += w[i] + w[j];
	}
      }
    }
  }

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