C# program:
using System ; using System . Collections . Generic ; class GFG { public class Node { public int key ; public Node left ; public Node right ; public int height ; public int size ; public Node ( int key ) { this . key = key ; this . left = this . right = null ; this . size = this . height = 1 ; } } ; public class Refint { public int value ; public Refint ( int value ) { this . value = value ; } } static int height ( Node N ) { if ( N == null ) return 0 ; return N . height ; } static int size ( Node N ) { if ( N == null ) return 0 ; return N . size ; } static int max ( int a , int b ) { return ( a > b ) ? a : b ; } static Node rightRotate ( Node y ) { Node x = y . left ; Node T2 = x . right ; x . right = y ; y . left = T2 ; y . height = max ( height ( y . left ) , height ( y . right ) ) + 1 ; x . height = max ( height ( x . left ) , height ( x . right ) ) + 1 ; y . size = size ( y . left ) + size ( y . right ) + 1 ; x . size = size ( x . left ) + size ( x . right ) + 1 ; return x ; } static Node leftRotate ( Node x ) { Node y = x . right ; Node T2 = y . left ; y . left = x ; x . right = T2 ; x . height = max ( height ( x . left ) , height ( x . right ) ) + 1 ; y . height = max ( height ( y . left ) , height ( y . right ) ) + 1 ; x . size = size ( x . left ) + size ( x . right ) + 1 ; y . size = size ( y . left ) + size ( y . right ) + 1 ; return y ; } static int getBalance ( Node N ) { if ( N == null ) return 0 ; return height ( N . left ) - height ( N . right ) ; } static Node insert ( Node Node , int key , Refint count ) { if ( Node == null ) return ( new Node ( key ) ) ; if ( key < Node . key ) Node . left = insert ( Node . left , key , count ) ; else { Node . right = insert ( Node . right , key , count ) ; count . value = count . value + size ( Node . left ) + 1 ; } Node . height = max ( height ( Node . left ) , height ( Node . right ) ) + 1 ; Node . size = size ( Node . left ) + size ( Node . right ) + 1 ; int balance = getBalance ( Node ) ; if ( balance > 1 && key < Node . left . key ) return rightRotate ( Node ) ; if ( balance < - 1 && key > Node . right . key ) return leftRotate ( Node ) ; if ( balance > 1 && key > Node . left . key ) { Node . left = leftRotate ( Node . left ) ; return rightRotate ( Node ) ; } if ( balance < - 1 && key < Node . right . key ) { Node . right = rightRotate ( Node . right ) ; return leftRotate ( Node ) ; } return Node ; } static void constructLowerArray ( int [ ] arr , Refint [ ] countSmaller , int n ) { int i ; Node root = null ; for ( i = 0 ; i < n ; i ++ ) countSmaller [ i ] = new Refint ( 0 ) ; for ( i = n - 1 ; i >= 0 ; i -- ) { root = insert ( root , arr [ i ] , countSmaller [ i ] ) ; } } static int countElements ( int [ ] A , int n , int K ) { int count = 0 ; Refint [ ] countSmaller = new Refint [ n ] ; constructLowerArray ( A , countSmaller , n ) ; int maxi = int . MinValue ; for ( int i = 0 ; i <= ( n - K - 1 ) ; i ++ ) { if ( A [ i ] > maxi && countSmaller [ i ] . value >= K ) { count ++ ; maxi = A [ i ] ; } } return count ; } public static void Main ( String [ ] args ) { int [ ] A = { 2 , 5 , 1 , 7 , 3 , 4 , 0 } ; int n = A . Length ; int K = 3 ; Console . WriteLine ( countElements ( A , n , K ) ) ; } }

Index/key variables: i, n
Accumulator variables: count, i
Iterator variables: i
Class/struct names: GFG, Node, Refint