dhyuti-n/xlcost-variable-roles huggingface dataset:
C# program:
using System ; public class ParallelogramPoints { public static void Main ( ) { int ax = 5 , ay = 0 ; int bx = 1 , by = 1 ; int cx = 2 , cy = 5 ; Console . WriteLine ( ax + bx - cx + " , ▁ " + ( ay + by - cy ) ) ; Console . WriteLine ( ax + cx - bx + " , ▁ " + ( ay + cy - by ) ) ; Console . WriteLine ( cx + bx - ax + " , ▁ " + ( cy + by - ax ) ) ; } }

Class/struct names: ParallelogramPoints
C# program:
using System ; class GFG { static float area ( int x1 , int y1 , int x2 , int y2 , int x3 , int y3 ) { return ( float ) Math . Abs ( ( x1 * ( y2 - y3 ) + x2 * ( y3 - y1 ) + x3 * ( y1 - y2 ) ) / 2.0 ) ; } static bool check ( int x1 , int y1 , int x2 , int y2 , int x3 , int y3 , int x4 , int y4 , int x , int y ) { float A = area ( x1 , y1 , x2 , y2 , x3 , y3 ) + area ( x1 , y1 , x4 , y4 , x3 , y3 ) ; float A1 = area ( x , y , x1 , y1 , x2 , y2 ) ; float A2 = area ( x , y , x2 , y2 , x3 , y3 ) ; float A3 = area ( x , y , x3 , y3 , x4 , y4 ) ; float A4 = area ( x , y , x1 , y1 , x4 , y4 ) ; return ( A == A1 + A2 + A3 + A4 ) ; } public static void Main ( ) { if ( check ( 0 , 10 , 10 , 0 , 0 , - 10 , - 10 , 0 , 10 , 15 ) ) Console . Write ( " yes " ) ; else Console . Write ( " no " ) ; } }

Class/struct names: GFG
C# program:
using System ; class GfG { class Node { public int data ; public Node left , right ; } static int maxOfLeftElement ( Node root ) { int res = int . MinValue ; if ( root == null ) return res ; if ( root . left != null ) res = root . left . data ; return Math . Max ( maxOfLeftElement ( root . left ) , Math . Max ( res , maxOfLeftElement ( root . right ) ) ) ; } static Node newNode ( int data ) { Node temp = new Node ( ) ; temp . data = data ; temp . left = null ; temp . right = null ; return temp ; } public static void Main ( String [ ] args ) { Node root = newNode ( 7 ) ; root . left = newNode ( 6 ) ; root . right = newNode ( 5 ) ; root . left . left = newNode ( 4 ) ; root . left . right = newNode ( 3 ) ; root . right . left = newNode ( 2 ) ; root . right . right = newNode ( 1 ) ; Console . WriteLine ( maxOfLeftElement ( root ) ) ; } }

Class/struct names: GfG, Node
C# program:
using System ; class GFG { static int findMaximumPieces ( int n ) { return 1 + n * ( n + 1 ) / 2 ; } public static void Main ( ) { Console . Write ( findMaximumPieces ( 3 ) ) ; } }

Class/struct names: GFG
C# program:
using System ; class GFG { static double sq ( double x ) { return ( ( x ) * ( x ) ) ; } static int EPS = ( int ) ( 1e-6 ) + 1 ; static int N = 5 ; public class point { public int x , y ; public point ( ) { } public point ( int x , int y ) { this . x = x ; this . y = y ; } } ; public class line { public int a , b , c ; public line ( int a , int b , int c ) { this . a = a ; this . b = b ; this . c = c ; } } ; static double dist ( double x , double y , point p ) { return Math . Sqrt ( sq ( x - p . x ) + sq ( y - p . y ) ) ; } static double compute ( point [ ] p , int n , line l , double X ) { double res = 0 ; double Y = - 1 * ( l . c + l . a * X ) / l . b ; for ( int i = 0 ; i < n ; i ++ ) res += dist ( X , Y , p [ i ] ) ; return res ; } static double findOptimumCostUtil ( point [ ] p , int n , line l ) { double low = - 1e6 ; double high = 1e6 ; while ( ( high - low ) > EPS ) { double mid1 = low + ( high - low ) / 3 ; double mid2 = high - ( high - low ) / 3 ; double dist1 = compute ( p , n , l , mid1 ) ; double dist2 = compute ( p , n , l , mid2 ) ; if ( dist1 < dist2 ) high = mid2 ; else low = mid1 ; } return compute ( p , n , l , ( low + high ) / 2 ) ; } static double findOptimumCost ( int [ , ] points , line l ) { point [ ] p = new point [ N ] ; for ( int i = 0 ; i < N ; i ++ ) p [ i ] = new point ( points [ i , 0 ] , points [ i , 1 ] ) ; return findOptimumCostUtil ( p , N , l ) ; } public static void Main ( String [ ] args ) { line l = new line ( 1 , - 1 , - 3 ) ; int [ , ] points = { { - 3 , - 2 } , { - 1 , 0 } , { - 1 , 2 } , { 1 , 2 } , { 3 , 4 } } ; Console . WriteLine ( findOptimumCost ( points , l ) ) ; } }

Index/key variables: N, i
Accumulator variables: i, res
Iterator variables: i
Class/struct names: GFG, line, point
C# program:
using System ; class GFG { static int factorTree ( int N ) { int height = 0 ; while ( N > 1 ) { bool flag = false ; for ( int i = 2 ; i <= Math . Sqrt ( N ) ; i ++ ) { if ( N % i == 0 ) { N = N / i ; flag = true ; break ; } } height ++ ; if ( ! flag ) { break ; } } return height ; } static void Main ( ) { int N = 48 ; Console . Write ( factorTree ( N ) ) ; } }

Accumulator variables: height, i
Iterator variables: i
Boolean variables: flag
Class/struct names: GFG
C# program:
using System ; class GFG { static int findMaxK ( int N ) { int p = ( int ) ( Math . Log ( N ) / Math . Log ( 2 ) ) ; return ( int ) Math . Pow ( 2 , p ) ; } public static void Main ( String [ ] args ) { int N = 5 ; Console . Write ( findMaxK ( N ) - 1 ) ; } }

Class/struct names: GFG
C# program:
using System ; class GFG { static int [ ] a ; static int [ ] seg_tree ; static int [ , ] query ; static void build_tree ( int v , int tl , int tr ) { if ( tl != tr ) { if ( a [ tl ] == 0 ) seg_tree [ v ] = 1 ; else seg_tree [ v ] = 0 ; } else { int tm = ( tl + tr ) / 2 ; build_tree ( v * 2 , tl , tm ) ; build_tree ( v * 2 + 1 , tm + 1 , tr ) ; seg_tree [ v ] = seg_tree [ v * 2 ] + seg_tree [ v * 2 + 1 ] ; } } static int frequency_zero ( int v , int tl , int tr , int l , int r ) { if ( l > r ) return 0 ; if ( l == tl && r == tr ) { return seg_tree [ v ] ; } int tm = ( tl + tr ) / 2 ; return frequency_zero ( v * 2 , tl , tm , l , Math . Min ( r , tm ) ) + frequency_zero ( v * 2 + 1 , tm + 1 , tr , Math . Max ( l , tm + 1 ) , r ) ; } static void update ( int v , int tl , int tr , int pos , int new_val ) { if ( tl == tr ) { if ( new_val == 0 ) seg_tree [ v ] = 1 ; else seg_tree [ v ] = 0 ; } else { int tm = ( tl + tr ) / 2 ; if ( pos <= tm ) update ( v * 2 , tl , tm , pos , new_val ) ; else update ( v * 2 + 1 , tm + 1 , tr , pos , new_val ) ; seg_tree [ v ] = seg_tree [ v * 2 ] + seg_tree [ v * 2 + 1 ] ; } } static void solve ( int n , int q ) { int [ ] qu = { 5 , 3 , 6 } ; seg_tree = new int [ 4 * n + 1 ] ; Array . Fill ( seg_tree , 0 ) ; build_tree ( 1 , 0 , n - 1 ) ; for ( int i = 0 ; i < qu . Length ; i ++ ) { Console . WriteLine ( qu [ i ] ) ; } for ( int i = q ; i < q ; i ++ ) { if ( query [ i - 1 , 0 ] == 1 ) { int l = query [ i - 1 , 1 ] ; int r = query [ i - 1 , 2 ] ; Console . WriteLine ( frequency_zero ( 1 , 0 , n - 1 , l , r ) ) ; } else { a [ query [ i - 1 , 1 ] ] = query [ i - 1 , 2 ] ; int pos = query [ i - 1 , 1 ] ; int new_val = query [ i - 1 , 2 ] ; update ( 1 , 0 , n - 1 , pos , new_val ) ; } } } static void Main ( ) { a = new int [ ] { 9 , 5 , 7 , 6 , 9 , 0 , 0 , 0 , 0 , 5 , 6 , 7 , 3 , 9 , 0 , 7 , 0 , 9 , 0 } ; int Q = 5 ; query = new int [ , ] { { 1 , 5 , 14 } , { 2 , 6 , 1 } , { 1 , 0 , 8 } , { 2 , 13 , 0 } , { 1 , 6 , 18 } } ; int N = a . Length ; solve ( N , Q ) ; } }

Index/key variables: i, tl, v
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; using System . Collections . Generic ; public class GFG { static readonly int InF = 99999 ; public class number { public int no ; public int level ; public number ( ) { } public number ( int n , int l ) { this . no = n ; this . level = l ; } } ; static void findnthnumber ( int n ) { Queue < number > q = new Queue < number > ( ) ; number r = new number ( 0 , 1 ) ; q . Enqueue ( r ) ; while ( q . Count != 0 ) { number temp = q . Peek ( ) ; q . Dequeue ( ) ; if ( temp . no >= InF temp . no <= - InF ) break ; if ( temp . no == n ) { Console . Write ( " Found ▁ number ▁ n ▁ at ▁ level ▁ " + ( temp . level - 1 ) ) ; break ; } q . Enqueue ( new number ( temp . no + temp . level , temp . level + 1 ) ) ; q . Enqueue ( new number ( temp . no - temp . level , temp . level + 1 ) ) ; } } public static void Main ( String [ ] args ) { findnthnumber ( 13 ) ; } }

Class/struct names: GFG, number
C# program:
using System ; public class GFG { static bool can_empty ( int a , int b , int c ) { if ( ( a + b + c ) % 4 != 0 ) return false ; else { int m = Math . Min ( a , Math . Min ( b , c ) ) ; if ( m < ( ( a + b + c ) / 4 ) ) return false ; } return true ; } static public void Main ( ) { int a = 4 , b = 2 , c = 2 ; Console . WriteLine ( can_empty ( a , b , c ) ? " true " : " false " ) ; a = 3 ; b = 4 ; c = 2 ; Console . WriteLine ( can_empty ( a , b , c ) ? " true " : " false " ) ; } }

Class/struct names: GFG
C# program:
using System ; class GFG { static double Avgdifference ( double [ ] arr , int N , int K ) { double min = 1000000 , max = - 1 ; for ( int i = 0 ; i <= N - K ; i ++ ) { double sum = 0 ; for ( int j = 0 ; j < K ; j ++ ) { sum += arr [ i + j ] ; } if ( min > sum ) min = sum ; if ( max < sum ) max = sum ; } return ( max - min ) / K ; } public static void Main ( String [ ] args ) { double [ ] arr = { 3 , 8 , 9 , 15 } ; int N = arr . Length ; int K = 2 ; Console . Write ( Avgdifference ( arr , N , K ) ) ; } }

Accumulator variables: i, j, sum
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; using System . Collections . Generic ; public class GFG { static List < int > find ( int n ) { List < int > ans = new List < int > ( ) ; int sum = 0 ; int i = 1 ; int sign = ( n >= 0 ? 1 : - 1 ) ; n = Math . Abs ( n ) ; for ( ; sum < n ; ) { ans . Add ( sign * i ) ; sum += i ; i ++ ; } if ( sum > sign * n ) { if ( i % 2 != 0 ) { sum -= n ; if ( sum % 2 != 0 ) { ans . Add ( sign * i ) ; sum += i ; i ++ ; } int a = ans [ ( ( sum / 2 ) - 1 ) ] ; ans . RemoveAt ( ( sum / 2 ) - 1 ) ; ans . Insert ( ( ( sum / 2 ) - 1 ) , a * ( - 1 ) ) ; } else { sum -= n ; if ( sum % 2 != 0 ) { sum -- ; ans . Add ( sign * i ) ; ans . Add ( sign * - 1 * ( i + 1 ) ) ; } ans . Insert ( ( sum / 2 ) - 1 , ans [ ( sum / 2 ) - 1 ] * - 1 ) ; } } return ans ; } public static void Main ( String [ ] args ) { int n = 20 ; if ( n == 0 ) Console . Write ( " Minimum ▁ number ▁ of ▁ Steps : ▁ 0 STRNEWLINE Step ▁ sequence : STRNEWLINE 0" ) ; else { List < int > a = find ( n ) ; Console . Write ( " Minimum ▁ number ▁ of ▁ Steps : ▁ " + a . Count + " STRNEWLINE Step ▁ sequence : STRNEWLINE " ) ; foreach ( int i in a ) Console . Write ( i + " ▁ " ) ; } } }

Accumulator variables: i, sum
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; using System . Collections ; using System . Collections . Generic ; class GFG { static void MaxRange ( List < int > A , int n ) { int [ ] left = new int [ n ] ; int [ ] right = new int [ n ] ; Stack s = new Stack ( ) ; s . Push ( new Tuple < int , int > ( Int32 . MaxValue , - 1 ) ) ; for ( int i = 0 ; i < n ; i ++ ) { while ( ( ( Tuple < int , int > ) s . Peek ( ) ) . Item1 < A [ i ] ) s . Pop ( ) ; left [ i ] = ( ( Tuple < int , int > ) s . Peek ( ) ) . Item2 ; s . Push ( new Tuple < int , int > ( A [ i ] , i ) ) ; } while ( s . Count > 0 ) s . Pop ( ) ; s . Push ( new Tuple < int , int > ( Int32 . MaxValue , n ) ) ; for ( int i = n - 1 ; i >= 0 ; i -- ) { while ( ( ( Tuple < int , int > ) s . Peek ( ) ) . Item1 < A [ i ] ) s . Pop ( ) ; right [ i ] = ( ( Tuple < int , int > ) s . Peek ( ) ) . Item2 ; s . Push ( new Tuple < int , int > ( A [ i ] , i ) ) ; } for ( int i = 0 ; i < n ; i ++ ) { Console . WriteLine ( ( left [ i ] + 1 ) + " ▁ " + ( right [ i ] - 1 ) ) ; } } static void Main ( ) { List < int > arr = new List < int > ( ) ; arr . Add ( 1 ) ; arr . Add ( 3 ) ; arr . Add ( 2 ) ; int n = arr . Count ; MaxRange ( arr , n ) ; } }

Index/key variables: i, n
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static int nthNumber ( int n ) { int [ ] divs = new int [ 1000000 ] ; int [ ] vis = new int [ 1000000 ] ; int cnt = 0 ; for ( int i = 2 ; cnt < n ; i ++ ) { if ( divs [ i ] == 0 ) { for ( int j = 2 * i ; j < 1000000 ; j += i ) { if ( vis [ j ] != 0 ) { continue ; } vis [ j ] = 1 ; int currNum = j ; int count = 0 ; while ( currNum % i == 0 ) { divs [ j ] ++ ; currNum = currNum / i ; count ++ ; } if ( currNum == 1 && count == 3 && divs [ j ] == 3 ) { cnt ++ ; } else if ( currNum != 1 && divs [ currNum ] == 0 && count == 1 && divs [ j ] == 1 ) { cnt ++ ; } if ( cnt == n ) { return j ; } } } } return - 1 ; } static public void Main ( ) { int N = 24 ; Console . Write ( nthNumber ( N ) ) ; } }

Index/key variables: currNum, i, j
Accumulator variables: cnt, count, i, j
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; class GFG { static int findkey ( int A , int B , int C ) { int ans = 0 ; int cur = 1 ; while ( A > 0 ) { int a = A % 10 ; int b = B % 10 ; int c = C % 10 ; A = A / 10 ; B = B / 10 ; C = C / 10 ; int m = Math . Max ( a , Math . Max ( c , b ) ) ; ans += cur * m ; cur = cur * 10 ; } return ans ; } static public void Main ( ) { int A = 3521 , B = 2452 , C = 1352 ; Console . Write ( findkey ( A , B , C ) ) ; } }

Accumulator variables: ans
Class/struct names: GFG
C# program:
using System ; using System . Collections . Generic ; class GFG { static int gcd ( int a , int b ) { return b == 0 ? a : gcd ( b , a % b ) ; } static int distinctGCDs ( int [ ] arr , int N ) { int M = - 1 , ans = 0 ; Dictionary < int , int > Mp = new Dictionary < int , int > ( ) ; for ( int i = 0 ; i < N ; i ++ ) { M = Math . Max ( M , arr [ i ] ) ; if ( Mp . ContainsKey ( arr [ i ] ) ) Mp [ arr [ i ] ] = 1 ; else Mp . Add ( arr [ i ] , 1 ) ; } for ( int i = 1 ; i <= M ; i ++ ) { int currGcd = 0 ; for ( int j = i ; j <= M ; j += i ) { if ( Mp . ContainsKey ( j ) ) { currGcd = gcd ( currGcd , j ) ; if ( currGcd == i ) { ans ++ ; break ; } } } } return ans ; } public static void Main ( ) { int [ ] arr = { 3 , 11 , 14 , 6 , 12 } ; int N = arr . Length ; Console . Write ( distinctGCDs ( arr , N ) ) ; } }

Index/key variables: i
Accumulator variables: ans, i, j
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; class GFG { static int eggDrop ( int n , int k ) { if ( k == 1 k == 0 ) return k ; if ( n == 1 ) return k ; int min = int . MaxValue ; int x , res ; for ( x = 1 ; x <= k ; x ++ ) { res = Math . Max ( eggDrop ( n - 1 , x - 1 ) , eggDrop ( n , k - x ) ) ; if ( res < min ) min = res ; } return min + 1 ; } static void Main ( ) { int n = 2 , k = 10 ; Console . Write ( " Minimum ▁ number ▁ of ▁ " + " trials ▁ in ▁ worst ▁ case ▁ with ▁ " + n + " ▁ eggs ▁ and ▁ " + k + " ▁ floors ▁ is ▁ " + eggDrop ( n , k ) ) ; } }

Accumulator variables: x
Iterator variables: x
Class/struct names: GFG
C# program:
using System ; class GFG { public static void kthDigitFromLast ( int n , int k ) { if ( k <= 0 ) { Console . Write ( - 1 ) ; return ; } while ( ( k - 1 ) > 0 && n > 0 ) { n = n / 10 ; k -- ; } if ( n == 0 ) { Console . Write ( - 1 ) ; } else { Console . Write ( n % 10 ) ; } } public static void Main ( String [ ] args ) { int n = 2354 ; int k = 2 ; kthDigitFromLast ( n , k ) ; } }

Accumulator variables: k
Class/struct names: GFG
C# program:
using System ; class GFG { static void EditDistDP ( String str1 , String str2 ) { int len1 = str1 . Length ; int len2 = str2 . Length ; int [ , ] DP = new int [ 2 , len1 + 1 ] ; for ( int i = 0 ; i <= len1 ; i ++ ) DP [ 0 , i ] = i ; for ( int i = 1 ; i <= len2 ; i ++ ) { for ( int j = 0 ; j <= len1 ; j ++ ) { if ( j == 0 ) DP [ i % 2 , j ] = i ; else if ( str1 [ j - 1 ] == str2 [ i - 1 ] ) { DP [ i % 2 , j ] = DP [ ( i - 1 ) % 2 , j - 1 ] ; } else { DP [ i % 2 , j ] = 1 + Math . Min ( DP [ ( i - 1 ) % 2 , j ] , Math . Min ( DP [ i % 2 , j - 1 ] , DP [ ( i - 1 ) % 2 , j - 1 ] ) ) ; } } } Console . Write ( DP [ len2 % 2 , len1 ] + " STRNEWLINE " ) ; } public static void Main ( String [ ] args ) { String str1 = " food " ; String str2 = " money " ; EditDistDP ( str1 , str2 ) ; } }

Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; public class GFG { static int xorSumOfArray ( int [ ] arr , int n , int k , int [ ] count ) { int sum = 0 ; int p = 1 ; for ( int i = 0 ; i < 31 ; i ++ ) { int val = 0 ; if ( ( k & ( 1 << i ) ) != 0 ) { int not_set = n - count [ i ] ; val = ( ( not_set ) * p ) ; } else { val = ( count [ i ] * p ) ; } sum += val ; p = ( p * 2 ) ; } return sum ; } static void sumOfXors ( int [ ] arr , int n , int [ ] queries , int q ) { int [ ] count = new int [ 32 ] ; for ( int i = 0 ; i < 32 ; i ++ ) count [ i ] = 0 ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < 31 ; j ++ ) { if ( ( arr [ i ] & ( 1 << j ) ) != 0 ) count [ j ] ++ ; } } for ( int i = 0 ; i < q ; i ++ ) { int k = queries [ i ] ; Console . Write ( xorSumOfArray ( arr , n , k , count ) + " ▁ " ) ; } } static public void Main ( ) { int [ ] arr = { 5 , 2 , 3 } ; int [ ] queries = { 3 , 8 , 7 } ; int n = arr . Length ; int q = queries . Length ; sumOfXors ( arr , n , queries , q ) ; } }

Index/key variables: i, j
Accumulator variables: i, j, sum
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; using System . Collections . Generic ; public class GFG { public class Node { public Node left , right ; public int key ; } ; static Node root ; static Node newNode ( int key ) { Node temp = new Node ( ) ; temp . key = key ; temp . left = temp . right = null ; return temp ; } static Node createFactorTree ( Node node_ref , int v ) { ( node_ref ) = newNode ( v ) ; for ( int i = 2 ; i < v / 2 ; i ++ ) { if ( v % i != 0 ) continue ; node_ref . left = createFactorTree ( ( ( node_ref ) . left ) , i ) ; node_ref . right = createFactorTree ( ( ( node_ref ) . right ) , v / i ) ; return node_ref ; } return node_ref ; } static void printLevelOrder ( Node root ) { if ( root == null ) return ; Queue < Node > q = new Queue < Node > ( ) ; q . Enqueue ( root ) ; while ( q . Count != 0 ) { Node node = q . Peek ( ) ; Console . Write ( node . key + " ▁ " ) ; q . Dequeue ( ) ; if ( node . left != null ) q . Enqueue ( node . left ) ; if ( node . right != null ) q . Enqueue ( node . right ) ; } } public static void Main ( String [ ] args ) { root = null ; root = createFactorTree ( root , val ) ; Console . WriteLine ( " Level ▁ order ▁ traversal ▁ of ▁ " + " constructed ▁ factor ▁ tree " ) ; printLevelOrder ( root ) ; } }

Accumulator variables: i
Iterator variables: i
Class/struct names: GFG, Node
C# program:
using System ; using System . Collections . Generic ; public class GFG { static readonly int M = 3 ; static readonly int N = 3 ; class pair { public int first , second ; public pair ( int first , int second ) { this . first = first ; this . second = second ; } } static void findHeightMatrixUtil ( int [ , ] mat , int [ , ] height ) { Queue < pair > q = new Queue < pair > ( ) ; int [ , ] vis = new int [ M , N ] ; for ( int i = 0 ; i < M ; i ++ ) { for ( int j = 0 ; j < N ; j ++ ) { if ( mat [ i , j ] == 1 ) { q . Enqueue ( new pair ( i , j ) ) ; height [ i , j ] = 0 ; vis [ i , j ] = 1 ; } } } while ( q . Count != 0 ) { pair k = q . Peek ( ) ; q . Dequeue ( ) ; int x = k . first , y = k . second ; if ( x > 0 && vis [ x - 1 , y ] == 0 ) { height [ x - 1 , y ] = height [ x , y ] + 1 ; vis [ x - 1 , y ] = 1 ; q . Enqueue ( new pair ( x - 1 , y ) ) ; } if ( y > 0 && vis [ x , y - 1 ] == 0 ) { height [ x , y - 1 ] = height [ x , y ] + 1 ; vis [ x , y - 1 ] = 1 ; q . Enqueue ( new pair ( x , y - 1 ) ) ; } if ( x < M - 1 && vis [ x + 1 , y ] == 0 ) { height [ x + 1 , y ] = height [ x , y ] + 1 ; vis [ x + 1 , y ] = 1 ; q . Enqueue ( new pair ( x + 1 , y ) ) ; } if ( y < N - 1 && vis [ x , y + 1 ] == 0 ) { height [ x , y + 1 ] = height [ x , y ] + 1 ; vis [ x , y + 1 ] = 1 ; q . Enqueue ( new pair ( x , y + 1 ) ) ; } } } static void findHeightMatrix ( int [ , ] mat ) { int [ , ] height = new int [ M , N ] ; findHeightMatrixUtil ( mat , height ) ; for ( int i = 0 ; i < M ; i ++ ) { for ( int j = 0 ; j < N ; j ++ ) Console . Write ( height [ i , j ] + " ▁ " ) ; Console . WriteLine ( ) ; } } public static void Main ( String [ ] args ) { int [ , ] mat = { { 0 , 0 , 0 } , { 0 , 1 , 0 } , { 0 , 0 , 0 } } ; findHeightMatrix ( mat ) ; } }

Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG, pair
C# program:
using System ; using System . Collections . Generic ; public class GFG { class Node { public Node left , right ; public int key ; } ; static List < int > interNodes = new List < int > ( ) ; static Node newNode ( int key ) { Node temp = new Node ( ) ; temp . key = key ; temp . left = temp . right = null ; return temp ; } static Node insertNode ( Node node , int key ) { if ( node == null ) return newNode ( key ) ; if ( key < node . key ) node . left = insertNode ( node . left , key ) ; else if ( key > node . key ) node . right = insertNode ( node . right , key ) ; return node ; } static void getIntermediateNodes ( Node root , int node1 , int node2 ) { if ( root == null ) return ; getIntermediateNodes ( root . left , node1 , node2 ) ; if ( root . key <= node2 && root . key >= node1 ) { interNodes . Add ( root . key ) ; } getIntermediateNodes ( root . right , node1 , node2 ) ; } static float findMedian ( Node root , int node1 , int node2 ) { getIntermediateNodes ( root , node1 , node2 ) ; int nSize = interNodes . Count ; return ( nSize % 2 == 1 ) ? ( float ) interNodes [ nSize / 2 ] : ( float ) ( interNodes [ ( nSize - 1 ) / 2 ] + interNodes [ nSize / 2 ] ) / 2 ; } public static void Main ( String [ ] args ) { Node root = null ; root = insertNode ( root , 8 ) ; insertNode ( root , 3 ) ; insertNode ( root , 1 ) ; insertNode ( root , 6 ) ; insertNode ( root , 4 ) ; insertNode ( root , 11 ) ; insertNode ( root , 15 ) ; Console . Write ( findMedian ( root , 3 , 11 ) ) ; } }

Class/struct names: GFG, Node
C# program:
using System ; class GFG { static void computeTotient ( int N , int [ ] phi ) { for ( int p = 2 ; p <= N ; p ++ ) { if ( phi [ p ] == p ) { phi [ p ] = p - 1 ; for ( int i = 2 * p ; i <= N ; i += p ) { phi [ i ] = ( phi [ i ] / p ) * ( p - 1 ) ; } } } } static void countPairs ( int N ) { int cnt_type1 = 0 , cnt_type2 = 0 ; int half_N = N / 2 ; cnt_type1 = ( half_N * ( half_N - 1 ) ) / 2 ; int [ ] phi = new int [ N + 1 ] ; for ( int i = 1 ; i <= N ; i ++ ) { phi [ i ] = i ; } computeTotient ( N , phi ) ; for ( int i = ( N / 2 ) + 1 ; i <= N ; i ++ ) cnt_type2 += ( i - phi [ i ] - 1 ) ; Console . Write ( cnt_type1 + cnt_type2 ) ; } public static void Main ( ) { int N = 6 ; countPairs ( N ) ; } }

Index/key variables: i, p
Accumulator variables: cnt_type2, i, p
Iterator variables: i, p
Class/struct names: GFG
C# program:
using System ; class GFG { static int ans = Int32 . MaxValue ; static int mini = Int32 . MaxValue ; static void findClosestTarget ( int i , int curr , int [ ] B , int M , int K ) { if ( Math . Abs ( curr - K ) < mini ) { mini = Math . Abs ( curr - K ) ; ans = curr ; } if ( Math . Abs ( curr - K ) == mini ) { ans = Math . Min ( ans , curr ) ; } if ( i >= M ) return ; findClosestTarget ( i + 1 , curr + B [ i ] , B , M , K ) ; findClosestTarget ( i + 1 , curr + 2 * B [ i ] , B , M , K ) ; findClosestTarget ( i + 1 , curr , B , M , K ) ; } static int findClosest ( int [ ] A , int [ ] B , int N , int M , int K ) { for ( int i = 0 ; i < N ; i ++ ) { findClosestTarget ( 0 , A [ i ] , B , M , K ) ; } return ans ; } public static void Main ( ) { int [ ] A = { 2 , 3 } ; int [ ] B = { 4 , 5 , 30 } ; int N = A . Length ; int M = B . Length ; int K = 18 ; Console . WriteLine ( findClosest ( A , B , N , M , K ) ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; using System . Collections . Generic ; public class GFG { public static void findNode ( Dictionary < int , int > map , int n ) { int [ ] a = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { if ( map . ContainsKey ( i + 1 ) ) a [ i ] = map [ i + 1 ] ; else a [ i ] = 0 ; } int count0 = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( a [ i ] == 0 ) { count0 ++ ; } } count0 -= 1 ; if ( count0 <= Math . Floor ( ( ( double ) n ) / ( ( double ) 2 ) ) ) { Console . WriteLine ( " Yes " ) ; } else Console . WriteLine ( " No ▁ " ) ; } static public void Main ( ) { int N = 3 ; Dictionary < int , int > map = new Dictionary < int , int > ( ) ; map [ 1 ] = 0 ; map [ 2 ] = 2 ; map [ 3 ] = 0 ; findNode ( map , N ) ; } }

Index/key variables: i, n
Accumulator variables: count0, i
Iterator variables: i
Class/struct names: GFG