import * as fs from "fs" class BinaryIndexedTree { data: number[] size: number constructor(size: number) { this.size = size this.data = Array(size).fill(0) } public add(p: number, x: number): void { p++; while (p <= this.size) { this.data[p - 1] += x; p += p & -p } } public range_sum(l: number, r: number): number { return this.sum(r) - this.sum(l) } private sum(p: number): number { let res = 0 while (p > 0) { res += this.data[p - 1] p -= p & -p } return res } } type Input = (args: string) => void const main: Input = args => { const input = args.trim().split("\n"); const n = +input.shift() const p = input.shift().split(" ").map(x => +x) const bit = new BinaryIndexedTree(n + 1); let ans = 0 p.forEach(x => { ans += bit.range_sum(x + 1, n + 1) bit.add(x, 1) }) console.log(ans) } main(fs.readFileSync('/dev/stdin', 'utf8'));