import java.io.PrintWriter import java.util.* import kotlin.math.* fun compress(a: Array): Array { val n = a.count() val b = a.sorted().distinct().toTypedArray() val c = Array(n) { 0 } for (i in 0 until n) { c[i] = Arrays.binarySearch(b, a[i]) } return c } class BIT(private val n: Int) { private val data = LongArray(n) { 0 } fun add(i: Int, x: Long) { var p = i + 1 while (p <= n) { data[p - 1] += x p += p and -p } } fun sum(range: IntRange): Long { val l = range.first val r = range.last + 1 return sum(r) - sum(l) } private fun sum(i: Int): Long { var r = i var s = 0L while(r > 0) { s += data[r - 1] r -= r and -r } return s } } fun inversionNumber(a: Array): Long { val b = a val n = a.count() val bit = BIT(n) var ans = 0L for (i in 0 until n) { ans += i - bit.sum(0..b[i]) bit.add(b[i], 1) } return ans } fun PrintWriter.solve() { val n = nextInt() val _a = Array(n) { nextInt() } val a = compress(_a) var num = inversionNumber(a) val ans = mutableListOf(num) for (i in 0 until n - 1) { num -= a[i] num += n - 1 - a[i] ans.add(num) } println(ans.joinToString("\n")) } fun main() { val writer = PrintWriter(System.out, false) writer.solve() writer.flush() } // region Scanner private var st = StringTokenizer("") private val br = System.`in`.bufferedReader() fun next(): String { while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine()) return st.nextToken() } fun nextInt() = next().toInt() fun nextLong() = next().toLong() fun nextLine() = br.readLine()!! fun nextDouble() = next().toDouble() // endregion