package no121; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.InputMismatchException; import java.util.NoSuchElementException; public class Main { public static void main(String[] args) { IO io = new IO(); int n = io.nextInt(); int[] a = io.arrayInt(n); long ans = 0; ans += count(n,a); for(int i=0;i Integer.compare(x.v, y.v)); BIT bit = new BIT(n); int used = 0; long sum = 0; for(int i=0;i used) { used = p[i].v; for(int j=i;j used) { break; } bit.accumlate(p[j].i, 1); } } int j = p[i].i; long left = j - bit.sum(0, j); long right = n - 1 - j - bit.sum(j + 1, n); sum += left * right; } return sum; } static long count2(int n,int[] a) { long sum = 0; Pair[] p = new Pair[n]; for(int i=0;i Integer.compare(x.v, y.v)); for(int i=0;i index = new ArrayList<>(); int f = i; for(;i0) { s+=bit[i]; i-=i&-i; } return s; } public long get(int index) { return sum(index,index+1); } public void set(int index,long num) { accumlate(index,num-(sum(index)-sum(index-1))); } public String toString() { long[] value = new long[n]; for(int i=0;i Integer.MAX_VALUE) { throw new NumberFormatException(); } return (int) nl; } public char nextChar() { if (!hasNext()) { throw new NoSuchElementException(); } return (char) readByte(); } public double nextDouble() { return Double.parseDouble(next());} public int[] arrayInt(int n) { int[] a = new int[n]; for(int i=0;i