import java.util.*; import java.io.*; import java.math.*; import java.math.BigInteger; import java.text.DecimalFormat; public class Tester { //static long sum=0,sum1=Long.MAX_VALUE; //DecimalFormat df = new DecimalFormat("#.#####"); static int visited[] = new int[100005]; //Stack s=new Stack(); public static final long MOD = (long) (1e9 + 7); static long h[]; static long j; // Driver program to test above function public static void main(String args[]) { Scanner sc=new Scanner(System.in); InputReader in = new InputReader(System.in); OutputStream outputStream = System.out; PrintWriter out = new PrintWriter(outputStream); int n=in.nextInt(); int arr[]=new int[n]; arr=nextIntArray(in,n); Arrays.sort(arr); int i=0,r=n-1; while(i<=r) { int temp=arr[i]; arr[i]=arr[r]; arr[r]=temp; i++;r--; } long ans=0; for(i=0;i arr[j]) inv_count++; return inv_count; } static int dfs(char arr[][],int i,int j,int n,int m,int p,int q) { if(i<0||i>=n||j<0||j>=m||arr[i][j]=='X') { return 0; } if(i==p&&j==q) { for(int g=0;g=0&&i=0&&j-1=0&&i=0&&j+11) { System.out.println("AAYAYAYA"); return 1+dfs(arr,i,j-1,n,m,p,q)+dfs(arr,i,j+1,n,m,p,q)+dfs(arr,i-1,j,n,m,p,q)+dfs(arr,i+1,j,n,m,p,q); } else return dfs(arr,i,j-1,n,m,p,q)+dfs(arr,i,j+1,n,m,p,q)+dfs(arr,i-1,j,n,m,p,q)+dfs(arr,i+1,j,n,m,p,q); } } static int BFS(ArrayList> adj, int root) { Queue q=new LinkedList(); visited[1]=1; visited[root]=1; //dis[root]=0; q.add(root); int count=1; while(!q.isEmpty()) { int element=q.remove(); System.out.println("element is "+element); for (int i : adj.get(element)) { if (visited[i] == 0) { { System.out.println("i is "+i); visited[i]=1; q.add(i); //dis[i]=dis[element]+6; count++; } } } } return count; } public static long power(long base, long exp) { long res=1; while(exp>0) { if(exp%2==1) res=(res*base)%MOD; base=(base*base)%MOD; exp/=2; } return res%MOD; } public static long power(long i) { long c=1; while(i>1) { c=((c%MOD)*(2%MOD))%MOD; i--; } return c; } public static long gcd(long p, long q) { if (q == 0) { return p; } return gcd(q, p % q); } private static int[] nextIntArray(InputReader in,int n) { int[] a=new int[n]; for(int i=0;i { public int compare(String arg0, String arg1) { // Use Integer.compare to compare the two Strings' lengths. return (arg0+arg1).compareTo(arg1+arg0); } } /*static class Graph { private static Deque stack = new ArrayDeque(); private int least,count,v; Set[] cities; private int[] risk; Graph(int n,String[] risk){ cities = new HashSet[n]; this.risk = new int[n]; for(int i =0;i(); } for(int i =0;i { private long first; private long index; public Pair(long i, long j) { this.first = i; this.index = j; } public Pair() { // TODO Auto-generated constructor stub } public long getFirst() { return first; } //public long getSecond() { return second; } public long getIndex() { return index ;} public void setFirst(long k) { this.first=k ; } public void setIndex(long k) { this.index=k ;} //public void setSecond(long k) { this.second=k ;} @Override public int compareTo(Pair o) { return Long.compare(o.first,this.first); } } static class InputReader { public BufferedReader reader; public StringTokenizer tokenizer; public InputReader(InputStream inputstream) { reader = new BufferedReader(new InputStreamReader(inputstream)); tokenizer = null; } public String nextLine(){ String fullLine=null; while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { fullLine=reader.readLine(); } catch (IOException e) { throw new RuntimeException(e); } return fullLine; } return fullLine; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public long nextLong() { return Long.parseLong(next()); } public int nextInt() { return Integer.parseInt(next()); } } } class Graph { static int ans=0; private int V; private static ArrayList adj[]; Graph(int v) { V=v; adj=new ArrayList[V]; for(int i=0;i q=new LinkedList(); q.add(s); color[s]=1; int baap=1; while(!q.isEmpty()) { int k=q.poll(); Iterator i=adj[k].listIterator(); if(color[k]==1) baap=1; else baap=2; while(i.hasNext()) { int j=i.next(); if(visited[j]==false) { visited[j]=true; q.add(j); } if(baap==1) { if(color[j]==1) return false; color[j]=2; } else { if(color[j]==2) return false; color[j]=1; } //q.add(j); } } return true; } void topologicalSortUtil(int v, boolean visited[], Stack s) { // Mark the current node as visited. visited[v] = true; Integer i; // Recur for all the vertices adjacent to this // vertex Iterator it = adj[v].iterator(); while (it.hasNext()) { i = it.next(); if (!visited[i]) topologicalSortUtil(i, visited, s); } // Push current vertex to stack which stores result s.push(new Integer(v)); } void BFS(int s) { Queue q=new LinkedList(); boolean visited[]=new boolean[V]; q.add(s); int r=0; while(!q.isEmpty()) { r=q.poll(); visited[r]=true; System.out.println("queue me nikla "+r); Iterator i=adj[r].listIterator(); while(i.hasNext()) { int n=i.next(); if(visited[n]==false) { q.add(n); visited[n]=true; } } } } static void DFS(int v,boolean visited[],HashMaph) { visited[v]=true; Iterator i = adj[v].listIterator(); while (i.hasNext()) { int n = i.next(); System.out.println(n); if(visited[n]==false) { if(n<=v) ans+=h.get(n+" "+v); else ans+=h.get(v+" "+n); //System.out.println("AYAYA "+ans); visited[n]=true; DFS(n,visited,h); } } //return ans; } }