import java.util.Arrays; import java.util.Comparator; import java.util.Scanner; class BIT { int n; long[] v; public BIT(int n) { this.n=n; v=new long[n+1]; } void add(int k,int val) { for (k++;k<=n;k+=k&-k) v[k]+=val; } long sum(int k) { long ret=0; for (;k>0;k-=k&-k) { ret+=v[k]; } return ret; } long sum(int l,int r) { ++l;++r; return sum(r-1)-sum(l-1); } } public class Main { public static void main(String[] args) { new Main().run(); } void run() { Scanner sc=new Scanner(System.in); int N=sc.nextInt(); int[][] A=new int[N][2]; for (int i=0;ia[0]).thenComparing(a->a[1])); long ans=0; for (int i=0;i-a[0]).thenComparing(a->a[1])); bit=new BIT(N); for (int i=0;i