<?php
while($n = trim(fgets(STDIN))) {
    $ary = array();
    while($n--) {
        $ary[] = trim(fgets(STDIN));
    }
    echo bubbleCount($ary), PHP_EOL;
}

function bubbleCount($ary) {
    $cnt = 0;
    for($i = ~-count($ary); $i > 0; $i--) {
        for($j = 0; $j < $i; $j++) {
            if($ary[$j] > $ary[-~$j]) {
                $ary[$j] ^= $ary[-~$j];
                $ary[-~$j] ^= $ary[$j];
                $ary[$j] ^= $ary[-~$j];
                $cnt++;
            }
        }
    }
    return $cnt;
}