
import scala.annotation.tailrec

object Main extends App {

  import scala.io.StdIn._

  solve
  @tailrec
  def solve: Unit = {
    val n = readLine.trim.toInt
    if (n == 0) return
    val numbers = Array.tabulate(n){_ ⇒ readLine.trim.toInt}
    var count = 0
    for (limit ← (1 until n).reverse) {
      for (i ← 0 until limit){
        if (numbers(i) > numbers(i + 1)){
          count += 1
          val temp = numbers(i)
          numbers(i) = numbers(i + 1)
          numbers(i + 1) = temp
        }
      }
    }
    println(count)
    solve
  }
  implicit class Extension[T](value :T){
    @inline
    def let[A](@inline func: T ⇒ A): A = func(value)
    @inline
    def also(@inline func: T ⇒ Unit): T = {func(value); value}
  }
}
