//config = { input: 'tmp', newline: '\r\n' }; // win
config = { input: '/dev/stdin', newline: '\n' }; // linux

line = require('fs').readFileSync(config.input, 'ascii')
  .split(config.newline, 2);

A = line[1].split(' ').map(Number);

sorted = [].concat(A);
sorted.sort(function(a, b) { return a - b; });

cnt = 0;
for (i in sorted) {
  idx = A.indexOf(sorted[i]);
  cnt += idx;
  A.splice(idx, 1);
}

console.log(cnt);