dhyuti-n/xlcost-variable-roles huggingface dataset:
C# program:
using System ; class GFG { static void printUnion ( int [ ] arr1 , int [ ] arr2 , int m , int n ) { if ( m > n ) { int [ ] tempp = arr1 ; arr1 = arr2 ; arr2 = tempp ; int temp = m ; m = n ; n = temp ; } Array . Sort ( arr1 ) ; for ( int i = 0 ; i < m ; i ++ ) Console . Write ( arr1 [ i ] + " ▁ " ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( binarySearch ( arr1 , 0 , m - 1 , arr2 [ i ] ) == - 1 ) Console . Write ( arr2 [ i ] + " ▁ " ) ; } } static void printIntersection ( int [ ] arr1 , int [ ] arr2 , int m , int n ) { if ( m > n ) { int [ ] tempp = arr1 ; arr1 = arr2 ; arr2 = tempp ; int temp = m ; m = n ; n = temp ; } Array . Sort ( arr1 ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( binarySearch ( arr1 , 0 , m - 1 , arr2 [ i ] ) != - 1 ) Console . Write ( arr2 [ i ] + " ▁ " ) ; } } static int binarySearch ( int [ ] arr , int l , int r , int x ) { if ( r >= l ) { int mid = l + ( r - l ) / 2 ; if ( arr [ mid ] == x ) return mid ; if ( arr [ mid ] > x ) return binarySearch ( arr , l , mid - 1 , x ) ; return binarySearch ( arr , mid + 1 , r , x ) ; } return - 1 ; } static public void Main ( ) { int [ ] arr1 = { 7 , 1 , 5 , 2 , 3 , 6 } ; int [ ] arr2 = { 3 , 8 , 6 , 20 , 7 } ; int m = arr1 . Length ; int n = arr2 . Length ; Console . WriteLine ( " Union ▁ of ▁ two ▁ arrays ▁ is ▁ " ) ; printUnion ( arr1 , arr2 , m , n ) ; Console . WriteLine ( " " ) ; Console . WriteLine ( " Intersection ▁ of ▁ two ▁ arrays ▁ is ▁ " ) ; printIntersection ( arr1 , arr2 , m , n ) ; } }

Index/key variables: i, mid
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; public class Node { public int data ; public Node left , right ; public Node ( int item ) { data = item ; left = right = null ; } } public class Maximum { public int max_no = int . MinValue ; } public class BinaryTree { public Node root ; public Maximum max = new Maximum ( ) ; public Node target_leaf = null ; public virtual bool printPath ( Node node , Node target_leaf ) { if ( node == null ) { return false ; } if ( node == target_leaf || printPath ( node . left , target_leaf ) || printPath ( node . right , target_leaf ) ) { Console . Write ( node . data + " ▁ " ) ; return true ; } return false ; } public virtual void getTargetLeaf ( Node node , Maximum max_sum_ref , int curr_sum ) { if ( node == null ) { return ; } curr_sum = curr_sum + node . data ; if ( node . left == null && node . right == null ) { if ( curr_sum > max_sum_ref . max_no ) { max_sum_ref . max_no = curr_sum ; target_leaf = node ; } } getTargetLeaf ( node . left , max_sum_ref , curr_sum ) ; getTargetLeaf ( node . right , max_sum_ref , curr_sum ) ; } public virtual int maxSumPath ( ) { if ( root == null ) { return 0 ; } getTargetLeaf ( root , max , 0 ) ; printPath ( root , target_leaf ) ; return max . max_no ; } public static void Main ( string [ ] args ) { BinaryTree tree = new BinaryTree ( ) ; tree . root = new Node ( 10 ) ; tree . root . left = new Node ( - 2 ) ; tree . root . right = new Node ( 7 ) ; tree . root . left . left = new Node ( 8 ) ; tree . root . left . right = new Node ( - 4 ) ; Console . WriteLine ( " Following ▁ are ▁ the ▁ nodes ▁ " + " on ▁ maximum ▁ sum ▁ path " ) ; int sum = tree . maxSumPath ( ) ; Console . WriteLine ( " " ) ; Console . WriteLine ( " Sum ▁ of ▁ nodes ▁ is ▁ : ▁ " + sum ) ; } }

Class/struct names: BinaryTree, Maximum, Node
C# program:
using System ; class GFG { static void intersection ( int [ ] a , int [ ] b , int n , int m ) { int i = 0 , j = 0 ; while ( i < n && j < m ) { if ( a [ i ] > b [ j ] ) { j ++ ; } else if ( b [ j ] > a [ i ] ) { i ++ ; } else { Console . Write ( a [ i ] + " ▁ " ) ; i ++ ; j ++ ; } } } public static void Main ( ) { int [ ] a = { 1 , 3 , 2 , 3 , 4 , 5 , 5 , 6 } ; int [ ] b = { 3 , 3 , 5 } ; int n = a . Length ; int m = b . Length ; Array . Sort ( a ) ; Array . Sort ( b ) ; intersection ( a , b , n , m ) ; } }

Index/key variables: i, j
Accumulator variables: i, j
Class/struct names: GFG
C# program:
using System ; class GFG { class Node { public int data ; public Node left , right ; } ; static int res ; static Node newNode ( int data ) { Node newNode = new Node ( ) ; newNode . data = data ; newNode . left = newNode . right = null ; return ( newNode ) ; } static int countUntil ( Node root ) { if ( root == null ) return 0 ; int l = countUntil ( root . left ) ; int r = countUntil ( root . right ) ; int maxCount ; if ( root . data == 1 ) maxCount = l + r + 1 ; else maxCount = l + r ; res = Math . Max ( res , maxCount ) ; if ( root . data == 1 ) return Math . Max ( l , r ) + 1 ; else return Math . Max ( l , r ) ; } static int findMaxCount ( Node root ) { res = int . MinValue ; countUntil ( root ) ; return res ; } public static void Main ( String [ ] args ) { Node root = newNode ( 1 ) ; root . left = newNode ( 0 ) ; root . right = newNode ( 1 ) ; root . left . left = newNode ( 1 ) ; root . left . right = newNode ( 1 ) ; root . left . right . left = newNode ( 1 ) ; root . left . right . right = newNode ( 0 ) ; Console . Write ( findMaxCount ( root ) ) ; } }

Class/struct names: GFG, Node
C# program:
using System ; using System . Linq ; using System . Collections . Generic ; class GFG { static void printUnion ( int [ ] arr1 , int [ ] arr2 ) { HashSet < int > hs = new HashSet < int > ( ) ; for ( int i = 0 ; i < arr1 . Length ; i ++ ) hs . Add ( arr1 [ i ] ) ; for ( int i = 0 ; i < arr2 . Length ; i ++ ) hs . Add ( arr2 [ i ] ) ; Console . WriteLine ( string . Join ( " , ▁ " , hs ) ) ; } static void printIntersection ( int [ ] arr1 , int [ ] arr2 ) { HashSet < int > hs = new HashSet < int > ( ) ; for ( int i = 0 ; i < arr1 . Length ; i ++ ) hs . Add ( arr1 [ i ] ) ; for ( int i = 0 ; i < arr2 . Length ; i ++ ) if ( hs . Contains ( arr2 [ i ] ) ) Console . Write ( arr2 [ i ] + " ▁ " ) ; } static void Main ( ) { int [ ] arr1 = { 7 , 1 , 5 , 2 , 3 , 6 } ; int [ ] arr2 = { 3 , 8 , 6 , 20 , 7 } ; Console . WriteLine ( " Union ▁ of ▁ two ▁ arrays ▁ is ▁ : ▁ " ) ; printUnion ( arr1 , arr2 ) ; Console . WriteLine ( " STRNEWLINE Intersection ▁ of ▁ two ▁ arrays ▁ is ▁ : ▁ " ) ; printIntersection ( arr1 , arr2 ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class UnsortedIntersectionUnion { public void findPosition ( int [ ] a , int [ ] b ) { int v = ( a . Length + b . Length ) ; int [ ] ans = new int [ v ] ; int zero1 = 0 ; int zero2 = 0 ; Console . Write ( " Intersection ▁ : ▁ " ) ; for ( int i = 0 ; i < a . Length ; i ++ ) zero1 = iterateArray ( a , v , ans , i ) ; for ( int j = 0 ; j < b . Length ; j ++ ) zero2 = iterateArray ( b , v , ans , j ) ; int zero = zero1 + zero2 ; placeZeros ( v , ans , zero ) ; printUnion ( v , ans , zero ) ; } private void printUnion ( int v , int [ ] ans , int zero ) { int zero1 = 0 ; Console . Write ( " Union : " for ( int i = 0 ; < ; i ++ ) { if ( ( zero == 0 && ans [ i ] == 0 ) || ( ans [ i ] == 0 && zero1 > 0 ) ) continue ; if ( ans [ i ] == 0 ) zero1 ++ ; . Write ( ans [ i ] + " , " ) ; } } private void ( int v , int [ ] ans , int zero ) { if ( zero == 2 ) { Console . WriteLine ( "0" ) ; int [ ] d = { 0 } ; placeValue ( d , ans , 0 , 0 , v ) ; } if ( zero == 1 ) { int [ ] d = { 0 } ; placeValue ( d , ans , 0 , 0 , v ) ; } } private int ( int [ ] a , int v , int [ ] ans , int i ) { if ( a [ i ] != 0 ) { int p = a [ i ] % v ; placeValue ( a , ans , i , p , v ) ; } else return 1 ; return 0 ; } private void ( int [ ] a , int [ ] ans , int i , int p , int v ) { p = p % v ; if ( ans [ p ] == 0 ) ans [ p ] = a [ i ] ; else { if ( ans [ p ] == a [ i ] ) Console . Write ( a [ i ] + " , " ) ; else { p = p + 1 ; ( a , ans , i , p , v ) ; } } } public static void ( ) { int [ ] a = { 7 , 1 , 5 , 2 , 3 , 6 } ; int [ ] b = { 3 , 8 , 6 , 20 , 7 } ; UnsortedIntersectionUnion uiu = new UnsortedIntersectionUnion ( ) ; uiu . findPosition ( a , b ) ; } }

Index/key variables: i, p, v
Accumulator variables: i, j, zero1
Iterator variables: i, j
Class/struct names: UnsortedIntersectionUnion
C# program:
using System ; using System . Collections . Generic ; class GFG { static int findCount ( int N ) { List < int > list = new List < int > ( ) ; int sum = 0 ; int i ; for ( i = 0 ; i < 20 ; i ++ ) { sum += ( int ) Math . Pow ( 2 , i ) ; list . Add ( sum ) ; } for ( i = 0 ; i < 20 ; i ++ ) { if ( ( int ) list [ i ] >= N ) return ( i + 1 ) ; } return 0 ; } public static void Main ( String [ ] args ) { int N = 10 ; Console . WriteLine ( findCount ( N ) ) ; } }

Index/key variables: i
Accumulator variables: i, sum
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static void sort012 ( int [ ] a , int arr_size ) { int lo = 0 ; int hi = arr_size - 1 ; int mid = 0 , temp = 0 ; while ( mid <= hi ) { switch ( a [ mid ] ) { case 0 : { temp = a [ lo ] ; a [ lo ] = a [ mid ] ; a [ mid ] = temp ; lo ++ ; mid ++ ; break ; } case 1 : mid ++ ; break ; case 2 : { temp = a [ mid ] ; a [ mid ] = a [ hi ] ; a [ hi ] = temp ; hi -- ; break ; } } } } static void printArray ( int [ ] arr , int arr_size ) { int i ; for ( i = 0 ; i < arr_size ; i ++ ) Console . Write ( arr [ i ] + " ▁ " ) ; Console . WriteLine ( " " ) ; } public static void Main ( ) { int [ ] arr = { 0 , 1 , 1 , 0 , 1 , 2 , 1 , 2 , 0 , 0 , 0 , 1 } ; int arr_size = arr . Length ; sort012 ( arr , arr_size ) ; Console . Write ( " Array ▁ after ▁ seggregation ▁ " ) ; printArray ( arr , arr_size ) ; } }

Index/key variables: hi, i, lo, mid
Accumulator variables: hi, i, lo, mid
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static void findSetBits ( int n ) { int [ ] dp = new int [ n + 1 ] ; Console . Write ( dp [ 0 ] + " ▁ " ) ; for ( int i = 1 ; i <= n ; i ++ ) { if ( i % 2 == 0 ) { dp [ i ] = dp [ i / 2 ] ; } else { dp [ i ] = dp [ i / 2 ] + 1 ; } Console . Write ( dp [ i ] + " ▁ " ) ; } } public static void Main ( String [ ] args ) { int n = 5 ; findSetBits ( n ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static void printArr ( int [ ] arr , int n ) { for ( int i = 0 ; i < n ; i ++ ) Console . Write ( arr [ i ] + " ▁ " ) ; } static void sortArr ( int [ ] arr , int n ) { int i , cnt0 = 0 , cnt1 = 0 , cnt2 = 0 ; for ( i = 0 ; i < n ; i ++ ) { switch ( arr [ i ] ) { case 0 : cnt0 ++ ; break ; case 1 : cnt1 ++ ; break ; case 2 : cnt2 ++ ; break ; } } i = 0 ; while ( cnt0 > 0 ) { arr [ i ++ ] = 0 ; cnt0 -- ; } while ( cnt1 > 0 ) { arr [ i ++ ] = 1 ; cnt1 -- ; } while ( cnt2 > 0 ) { arr [ i ++ ] = 2 ; cnt2 -- ; } printArr ( arr , n ) ; } public static void Main ( ) { int [ ] arr = { 0 , 1 , 1 , 0 , 1 , 2 , 1 , 2 , 0 , 0 , 0 , 1 } ; int n = arr . Length ; sortArr ( arr , n ) ; } }

Index/key variables: i
Accumulator variables: cnt0, cnt1, cnt2, i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static int subsetSum ( int [ ] a , int n , int sum ) { int [ , ] tab = new int [ n + 1 , sum + 1 ] ; tab [ 0 , 0 ] = 1 ; for ( int i = 1 ; i <= sum ; i ++ ) tab [ 0 , i ] = 0 ; for ( int i = 1 ; i <= n ; i ++ ) tab [ i , 0 ] = 1 ; for ( int i = 1 ; i <= n ; i ++ ) { for ( int j = 1 ; j <= sum ; j ++ ) { if ( a [ i - 1 ] > j ) tab [ i , j ] = tab [ i - 1 , j ] ; else { tab [ i , j ] = tab [ i - 1 , j ] + tab [ i - 1 , j - a [ i - 1 ] ] ; } } } return tab [ n , sum ] ; } public static void Main ( String [ ] args ) { int n = 4 ; int [ ] a = { 3 , 3 , 3 , 3 } ; int sum = 6 ; Console . Write ( subsetSum ( a , n , sum ) ) ; } }

Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; using System . Collections . Generic ; class GFG { static int row = 6 ; static int col = 8 ; static int cal ( int [ ] hist , int n ) { Stack < int > s = new Stack < int > ( ) ; int max_area = 0 ; int tp ; int area_with_top ; int i = 0 ; while ( i < n ) { if ( s . Count == 0 || hist [ s . Peek ( ) ] <= hist [ i ] ) s . Push ( i ++ ) ; else { tp = s . Peek ( ) ; s . Pop ( ) ; area_with_top = hist [ tp ] * ( s . Count == 0 ? i : i - s . Peek ( ) - 1 ) ; if ( max_area < area_with_top ) max_area = area_with_top ; } } while ( s . Count == 0 == false ) { tp = s . Peek ( ) ; s . Pop ( ) ; area_with_top = hist [ tp ] * ( s . Count == 0 ? i : i - s . Peek ( ) - 1 ) ; if ( max_area < area_with_top ) max_area = area_with_top ; } return max_area ; } static int largestMatrix ( int [ , ] a ) { int [ , ] dp = new int [ row , col ] ; for ( int i = 0 ; i < col ; i ++ ) { int cnt = 0 ; for ( int j = row - 1 ; j >= 0 ; j -- ) { dp [ j , i ] = 0 ; if ( a [ j , i ] == 1 ) { cnt ++ ; dp [ j , i ] = cnt ; } else { cnt = 0 ; } } } int ans = - 1 ; for ( int i = 0 ; i < row ; i ++ ) { int [ ] hist = new int [ col ] ; for ( int j = 0 ; j < col ; j ++ ) { hist [ j ] = dp [ i , j ] ; } ans = Math . Max ( ans , cal ( hist , col ) ) ; } for ( int i = 0 ; i < col ; i ++ ) { int cnt = 0 ; for ( int j = row - 1 ; j >= 0 ; j -- ) { dp [ j , i ] = 0 ; if ( a [ j , i ] == 0 ) { cnt ++ ; dp [ j , i ] = cnt ; } else { cnt = 0 ; } } } for ( int i = 0 ; i < row ; i ++ ) { int [ ] hist = new int [ col ] ; for ( int j = 0 ; j < col ; j ++ ) { hist [ j ] = dp [ i , j ] ; } ans = Math . Max ( ans , cal ( hist , col ) ) ; } return ans ; } public static void Main ( String [ ] args ) { int [ , ] a = { { 1 , 1 , 0 , 1 , 0 , 0 , 0 , 0 } , { 0 , 1 , 1 , 1 , 1 , 0 , 0 , 1 } , { 1 , 0 , 0 , 1 , 1 , 1 , 0 , 0 } , { 0 , 1 , 1 , 0 , 1 , 1 , 0 , 0 } , { 1 , 0 , 1 , 1 , 1 , 1 , 1 , 0 } , { 0 , 0 , 1 , 1 , 1 , 1 , 1 , 1 } } ; Console . WriteLine ( largestMatrix ( a ) ) ; } }

Index/key variables: col, i, j, tp
Accumulator variables: cnt, i, j
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; class GFG { static void printUnsorted ( int [ ] arr , int n ) { int s = 0 , e = n - 1 , i , max , min ; for ( s = 0 ; s < n - 1 ; s ++ ) { if ( arr [ s ] > arr [ s + 1 ] ) break ; } if ( s == n - 1 ) { Console . Write ( " The ▁ complete ▁ " + " array ▁ is ▁ sorted " ) ; return ; } for ( e = n - 1 ; e > 0 ; e -- ) { if ( arr [ e ] < arr [ e - 1 ] ) break ; } max = arr [ s ] ; min = arr [ s ] ; for ( i = s + 1 ; i <= e ; i ++ ) { if ( arr [ i ] > max ) max = arr [ i ] ; if ( arr [ i ] < min ) min = arr [ i ] ; } for ( i = 0 ; i < s ; i ++ ) { if ( arr [ i ] > min ) { s = i ; break ; } } for ( i = n - 1 ; i >= e + 1 ; i -- ) { if ( arr [ i ] < max ) { e = i ; break ; } } Console . Write ( " ▁ The ▁ unsorted ▁ subarray ▁ which " + " ▁ makes ▁ the ▁ given ▁ array ▁ sorted ▁ lies ▁ STRNEWLINE " + " ▁ between ▁ the ▁ indices ▁ " + s + " ▁ and ▁ " + e ) ; return ; } public static void Main ( ) { int [ ] arr = { 10 , 12 , 20 , 30 , 25 , 40 , 32 , 31 , 35 , 50 , 60 } ; int arr_size = arr . Length ; printUnsorted ( arr , arr_size ) ; } }

Index/key variables: e, i, s
Accumulator variables: e, i, s
Iterator variables: e, i, s
Class/struct names: GFG
C# program:
using System ; class GFG { static int findNumberOfTriangles ( int [ ] arr , int n ) { int count = 0 ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = i + 1 ; j < n ; j ++ ) { for ( int k = j + 1 ; k < n ; k ++ ) if ( arr [ i ] + arr [ j ] > arr [ k ] && arr [ i ] + arr [ k ] > arr [ j ] && arr [ k ] + arr [ j ] > arr [ i ] ) count ++ ; } } return count ; } static public void Main ( ) { int [ ] arr = { 10 , 21 , 22 , 100 , 101 , 200 , 300 } ; int size = arr . Length ; Console . WriteLine ( " Total ▁ number ▁ of ▁ triangles ▁ possible ▁ is ▁ " + findNumberOfTriangles ( arr , size ) ) ; } }

Index/key variables: i, j, k
Accumulator variables: count, i, j, k
Iterator variables: i, j, k
Class/struct names: GFG
C# program:
using System ; class GFG { static int findNumberOfTriangles ( int [ ] arr ) { int n = arr . Length ; Array . Sort ( arr ) ; int count = 0 ; for ( int i = 0 ; i < n - 2 ; ++ i ) { int k = i + 2 ; for ( int j = i + 1 ; j < n ; ++ j ) { while ( k < n && arr [ i ] + arr [ j ] > arr [ k ] ) ++ k ; if ( k > j ) count += k - j - 1 ; } } return count ; } public static void Main ( ) { int [ ] arr = { 10 , 21 , 22 , 100 , 101 , 200 , 300 } ; Console . WriteLine ( " Total ▁ number ▁ of ▁ triangles ▁ is ▁ " + findNumberOfTriangles ( arr ) ) ; } }

Index/key variables: i, j, k
Accumulator variables: count
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; class GFG { static void CountTriangles ( int [ ] A ) { int n = A . Length ; Array . Sort ( A ) ; int count = 0 ; for ( int i = n - 1 ; i >= 1 ; i -- ) { int l = 0 , r = i - 1 ; while ( l < r ) { if ( A [ l ] + A [ r ] > A [ i ] ) { count += r - l ; r -- ; } else { l ++ ; } } } Console . Write ( " No ▁ of ▁ possible ▁ solutions : ▁ " + count ) ; } public static void Main ( String [ ] args ) { int [ ] A = { 4 , 3 , 5 , 7 , 6 } ; CountTriangles ( A ) ; } }

Index/key variables: i, l, r
Accumulator variables: count, i, l, r
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; using System . Collections . Generic ; public class FindSumOfNotAdjacentNodes { public class Node { public int data ; public Node left , right ; public Node ( int data ) { this . data = data ; left = right = null ; } } ; public static int sumOfGrandChildren ( Node node , Dictionary < Node , int > mp ) { int sum = 0 ; if ( node . left != null ) sum += getMaxSumUtil ( node . left . left , mp ) + getMaxSumUtil ( node . left . right , mp ) ; if ( node . right != null ) sum += getMaxSumUtil ( node . right . left , mp ) + getMaxSumUtil ( node . right . right , mp ) ; return sum ; } public static int getMaxSumUtil ( Node node , Dictionary < Node , int > mp ) { if ( node == null ) return 0 ; if ( mp . ContainsKey ( node ) ) return mp [ node ] ; int incl = node . data + sumOfGrandChildren ( node , mp ) ; int excl = getMaxSumUtil ( node . left , mp ) + getMaxSumUtil ( node . right , mp ) ; mp . Add ( node , Math . Max ( incl , excl ) ) ; return mp [ node ] ; } public static int getMaxSum ( Node node ) { if ( node == null ) return 0 ; Dictionary < Node , int > mp = new Dictionary < Node , int > ( ) ; return getMaxSumUtil ( node , mp ) ; } public static void Main ( String [ ] args ) { Node root = new Node ( 1 ) ; root . left = new Node ( 2 ) ; root . right = new Node ( 3 ) ; root . right . left = new Node ( 4 ) ; root . right . right = new Node ( 5 ) ; root . left . left = new Node ( 1 ) ; Console . Write ( getMaxSum ( root ) ) ; } }

Index/key variables: node
Accumulator variables: sum
Class/struct names: FindSumOfNotAdjacentNodes, Node
C# program:
using System ; class GFG { public static int solve ( int [ ] A , int n ) { int [ , ] dp = new int [ 2000 , 2000 ] ; int flag = 1 ; int sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) sum += A [ i ] ; for ( int i = - sum ; i <= sum ; i ++ ) { try { dp [ 0 , i ] = int . MaxValue ; } catch ( Exception e ) { } } dp [ 0 , 0 ] = 0 ; for ( int i = 1 ; i <= n ; i ++ ) { for ( int j = 0 ; j <= sum ; j ++ ) { try { dp [ flag , j ] = int . MaxValue ; if ( j - A [ i - 1 ] <= sum && j - A [ i - 1 ] >= - sum ) dp [ flag , j ] = dp [ flag ^ 1 , j - A [ i - 1 ] ] ; if ( j + A [ i - 1 ] <= sum && j + A [ i - 1 ] >= - sum && dp [ flag ^ 1 , j + A [ i - 1 ] ] != int . MaxValue ) dp [ flag , j ] = Math . Min ( dp [ flag , j ] , dp [ flag ^ 1 , j + A [ i - 1 ] ] + 1 ) ; } catch ( Exception e ) { } } flag = flag ^ 1 ; } for ( int i = 0 ; i <= sum ; i ++ ) { if ( dp [ flag ^ 1 , i ] != int . MaxValue ) return dp [ flag ^ 1 , i ] ; } return n - 1 ; } public static void Main ( String [ ] args ) { int [ ] arr = { 10 , 22 , 9 , 33 , 21 , 50 , 41 , 60 } ; int n = arr . Length ; Console . WriteLine ( solve ( arr , n ) ) ; } }

Index/key variables: i
Accumulator variables: i, j, sum
Iterator variables: i, j
Class/struct names: GFG
C# program:
public static int countPairsBruteForce ( int [ ] X , int [ ] Y , int m , int n ) { int ans = 0 ; for ( int i = 0 ; i < m ; i ++ ) for ( int j = 0 ; j < n ; j ++ ) if ( Math . Pow ( X [ i ] , Y [ j ] ) > Math . Pow ( Y [ j ] , X [ i ] ) ) ans ++ ; return ans ; }

Index/key variables: i, j
Accumulator variables: ans, i, j
Iterator variables: i, j
C# program:
using System ; namespace Permutation { class AllPermutation < T > { private readonly T [ ] Arr ; private int [ ] Indexes ; private int Increase ; public AllPermutation ( T [ ] arr ) { this . Arr = arr ; this . Increase = - 1 ; } public void GetFirst ( ) { this . Indexes = new int [ this . Arr . Length ] ; for ( int i = 0 ; i < Indexes . Length ; ++ i ) { this . Indexes [ i ] = i ; } this . Increase = 0 ; this . Output ( ) ; } public bool HasNext ( ) { return this . Increase != ( this . Indexes . Length - 1 ) ; } public void GetNext ( ) { if ( this . Increase == 0 ) { this . Swap ( this . Increase , this . Increase + 1 ) ; this . Increase += 1 ; while ( this . Increase < this . Indexes . Length - 1 && this . Indexes [ this . Increase ] > this . Indexes [ this . Increase + 1 ] ) { ++ this . Increase ; } } else { if ( this . Indexes [ this . Increase + 1 ] > this . Indexes [ 0 ] ) { this . Swap ( this . Increase + 1 , 0 ) ; } else { int start = 0 ; int end = this . Increase ; int mid = ( start + end ) / 2 ; int tVal = this . Indexes [ this . Increase + 1 ] ; while ( ! ( this . Indexes [ mid ] < tVal && this . Indexes [ mid - 1 ] > tVal ) ) { if ( this . Indexes [ mid ] < tVal ) { end = mid - 1 ; } else { start = mid + 1 ; } mid = ( start + end ) / 2 ; } this . Swap ( this . Increase + 1 , mid ) ; } for ( int i = 0 ; i <= this . Increase / 2 ; ++ i ) { this . Swap ( i , this . Increase - i ) ; } this . Increase = 0 ; } this . Output ( ) ; } private void Output ( ) { for ( int i = 0 ; i < this . Indexes . Length ; ++ i ) { Console . Write ( this . Arr [ this . Indexes [ i ] ] ) ; Console . Write ( " ▁ " ) ; } Console . WriteLine ( ) ; } private void Swap ( int p , int q ) { int tmp = this . Indexes [ p ] ; this . Indexes [ p ] = this . Indexes [ q ] ; this . Indexes [ q ] = tmp ; } } class AppDriver { static void Main ( ) { int [ ] arr = { 0 , 1 , 2 } ; AllPermutation < int > perm = new AllPermutation < int > ( arr ) ; perm . GetFirst ( ) ; while ( perm . HasNext ( ) ) { perm . GetNext ( ) ; } } } }

Index/key variables: i, mid, p, q
Accumulator variables: Increase
Iterator variables: i
Class/struct names: AllPermutation, AppDriver
C# program:
using System ; using System . Collections . Generic ; class GFG { static List < List < bool > > v = new List < List < bool > > ( ) ; static List < List < int > > dp = new List < List < int > > ( ) ; static List < int > exp_c = new List < int > ( ) ; static int FindMax ( int i , int r , int [ ] w , int n , int c , int k ) { if ( i >= n ) { return 0 ; } if ( v [ i ] [ r ] ) { return dp [ i ] [ r ] ; } v [ i ] [ r ] = true ; dp [ i ] [ r ] = FindMax ( i + 1 , r , w , n , c , k ) ; for ( int j = 0 ; j < k ; j ++ ) { int x = ( r / exp_c [ j ] ) % ( c + 1 ) ; if ( x - w [ i ] >= 0 ) { dp [ i ] [ r ] = Math . Max ( dp [ i ] [ r ] , w [ i ] + FindMax ( i + 1 , r - w [ i ] * exp_c [ j ] , w , n , c , k ) ) ; } } return dp [ i ] [ r ] ; } static int PreCompute ( int n , int c , int k ) { for ( int i = 0 ; i < k ; i ++ ) { exp_c . Add ( 0 ) ; } exp_c [ 0 ] = 1 ; for ( int i = 1 ; i < k ; i ++ ) { exp_c [ i ] = ( exp_c [ i - 1 ] * ( c + 1 ) ) ; } for ( int i = 0 ; i < n ; i ++ ) { dp . Add ( new List < int > ( ) ) ; } for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < ( exp_c [ k - 1 ] * ( c + 1 ) ) ; j ++ ) { dp [ i ] . Add ( 0 ) ; } } for ( int i = 0 ; i < n ; i ++ ) { v . Add ( new List < bool > ( ) ) ; } for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < ( exp_c [ k - 1 ] * ( c + 1 ) ) ; j ++ ) { v [ i ] . Add ( false ) ; } } int R = 0 ; for ( int i = 0 ; i < k ; i ++ ) { R += exp_c [ i ] * c ; } return R ; } static public void Main ( ) { int [ ] w = { 3 , 8 , 9 } ; int k = 1 , c = 11 ; int n = w . Length ; int r = PreCompute ( n , c , k ) ; Console . WriteLine ( FindMax ( 0 , r , w , n , c , k ) ) ; } }

Index/key variables: i, j, r
Accumulator variables: R, i, j
Iterator variables: i, j
Class/struct names: GFG