dhyuti-n/xlcost-variable-roles huggingface dataset:
C# program:
using System ; class GFG { static void IfExists ( int [ ] arr , int n ) { int [ ] sum = new int [ n ] ; Array . Sort ( arr ) ; sum [ 0 ] = arr [ 0 ] ; for ( int i = 1 ; i < n ; i ++ ) sum [ i ] = sum [ i - 1 ] + arr [ i ] ; int max = arr [ n - 1 ] ; bool flag = false ; for ( int i = 1 ; i <= max ; i ++ ) { int findex = 0 ; int lindex = 0 ; int l = 0 ; int r = n - 1 ; while ( l <= r ) { int m = ( l + r ) / 2 ; if ( arr [ m ] < i ) { findex = m ; l = m + 1 ; } else r = m - 1 ; } l = 1 ; r = n ; flag = false ; while ( l <= r ) { int m = ( r + l ) / 2 ; if ( arr [ m ] > i ) { lindex = m ; r = m - 1 ; } else l = m + 1 ; } if ( sum [ findex ] == sum [ n - 1 ] - sum [ lindex - 1 ] ) { flag = true ; break ; } } if ( flag ) Console . WriteLine ( " Yes " ) ; else Console . WriteLine ( " No " ) ; } public static void Main ( ) { int [ ] arr = { 1 , 2 , 2 , 5 } ; int n = arr . Length ; IfExists ( arr , n ) ; } }

Index/key variables: findex, i, m, n
Accumulator variables: i
Iterator variables: i
Boolean variables: flag
Class/struct names: GFG
C# program:
using System ; class GFG { public static int findMissing ( int [ ] arr , int n ) { int l = 0 , h = n - 1 ; int mid ; while ( h > l ) { mid = l + ( h - l ) / 2 ; if ( arr [ mid ] - mid == arr [ 0 ] ) { if ( arr [ mid + 1 ] - arr [ mid ] > 1 ) return arr [ mid ] + 1 ; else { l = mid + 1 ; } } else { if ( arr [ mid ] - arr [ mid - 1 ] > 1 ) return arr [ mid ] - 1 ; else { h = mid - 1 ; } } } return - 1 ; } public static void Main ( ) { int [ ] arr = { - 9 , - 8 , - 7 , - 5 , - 4 , - 3 , - 2 , - 1 , 0 } ; int n = arr . Length ; Console . WriteLine ( findMissing ( arr , n ) ) ; } }

Index/key variables: mid
Class/struct names: GFG
C# program:
using System ; class GFG { static int maxSum ( int [ ] arr , int n , int K ) { int maximum = int . MinValue ; for ( int i = 0 ; i < n ; i ++ ) { int sumk = 0 ; for ( int j = i ; j < n ; j += K ) sumk = sumk + arr [ j ] ; maximum = Math . Max ( maximum , sumk ) ; } return maximum ; } public static void Main ( ) { int [ ] arr = { 3 , 6 , 4 , 7 , 2 } ; int n = arr . Length ; int K = 2 ; Console . WriteLine ( maxSum ( arr , n , K ) ) ; } }

Index/key variables: j
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; class GFG { static int countGreater ( int [ ] arr , int n , int k ) { int l = 0 ; int r = n - 1 ; int leftGreater = n ; while ( l <= r ) { int m = l + ( r - l ) / 2 ; if ( arr [ m ] > k ) { leftGreater = m ; r = m - 1 ; } else l = m + 1 ; } return ( n - leftGreater ) ; } public static void Main ( ) { int [ ] arr = { 3 , 3 , 4 , 7 , 7 , 7 , 11 , 13 , 13 } ; int n = arr . Length ; int k = 7 ; Console . WriteLine ( countGreater ( arr , n , k ) ) ; } }

Index/key variables: m
Class/struct names: GFG
C# program:
using System ; class GFG { static int operations ( int [ ] op , int n , int k ) { int i , count = 0 ; int nVal = 0 ; int min = int . MaxValue ; for ( i = 0 ; i < n ; i ++ ) { nVal += op [ i ] ; min = Math . Min ( min , nVal ) ; if ( ( k + nVal ) <= 0 ) return ( i + 1 ) ; } if ( nVal >= 0 ) return - 1 ; int times = ( k - Math . Abs ( min ) ) / Math . Abs ( nVal ) ; k = ( k - ( times * Math . Abs ( nVal ) ) ) ; count = ( times * n ) ; while ( k > 0 ) { for ( i = 0 ; i < n ; i ++ ) { k = k + op [ i ] ; count ++ ; if ( k <= 0 ) break ; } } return count ; } static void Main ( ) { int [ ] op = { - 60 , 65 , - 1 , 14 , - 25 } ; int n = op . Length ; int k = 100000 ; Console . WriteLine ( operations ( op , n , k ) ) ; } }

Index/key variables: i
Accumulator variables: count, i, nVal
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static int MAX_SIZE = 1000 ; static int [ ] lookup_table = new int [ MAX_SIZE ] ; static void create_table ( int n ) { int pow = 1 ; int co = 0 ; do { pow <<= 1 ; lookup_table [ co ] = ( n + ( pow >> 1 ) ) / pow ; } while ( lookup_table [ co ++ ] != 0 ) ; } static int binary ( int [ ] arr , int v ) { int index = lookup_table [ 0 ] - 1 ; int co = 0 ; while ( lookup_table [ co ] != 0 ) { if ( v == arr [ index ] ) return index ; else if ( v < arr [ index ] ) { index -= lookup_table [ ++ co ] ; return index ; } else { index += lookup_table [ ++ co ] ; return index ; } } return index ; } public static void Main ( ) { int [ ] arr = { 1 , 3 , 5 , 6 , 7 , 8 , 9 } ; int n = arr . GetLength ( 0 ) ; create_table ( n ) ; Console . WriteLine ( " Position ▁ of ▁ 3 ▁ in ▁ array ▁ = ▁ " + binary ( arr , 3 ) ) ; } }

Index/key variables: MAX_SIZE, co, index
Accumulator variables: co, index
Class/struct names: GFG
C# program:
class GFG { static int countFactor ( int P , int X ) { if ( X < P ) return 0 ; return ( X / P + countFactor ( P , X / P ) ) ; } static int findSmallestX ( int Y ) { int low = 0 , high = 5 * Y ; int N = 0 ; while ( low <= high ) { int mid = ( high + low ) / 2 ; if ( countFactor ( 5 , mid ) < Y ) { low = mid + 1 ; } else { N = mid ; high = mid - 1 ; } } return N ; } static void Main ( ) { int Y = 10 ; System . Console . WriteLine ( findSmallestX ( Y ) ) ; } }

Class/struct names: GFG
C# program:
using System ; class GFG { static long squareSum ( long N ) { long sum = ( long ) ( N * ( N + 1 ) * ( 2 * N + 1 ) ) / 6 ; return sum ; } static long findMaxN ( long X ) { long low = 1 , high = 100000 ; int N = 0 ; while ( low <= high ) { long mid = ( high + low ) / 2 ; if ( squareSum ( mid ) <= X ) { N = ( int ) mid ; low = mid + 1 ; } else high = mid - 1 ; } return N ; } static public void Main ( ) { long X = 25 ; Console . WriteLine ( findMaxN ( X ) ) ; } }

Class/struct names: GFG
C# program:
using System ; class GFG { class pair { public int first , second ; public pair ( int first , int second ) { this . first = first ; this . second = second ; } } static int findNumber ( pair [ ] a , int n , int K ) { for ( int i = 0 ; i < n ; i ++ ) { if ( K >= a [ i ] . first && K <= a [ i ] . second ) return i ; } return - 1 ; } public static void Main ( String [ ] args ) { pair [ ] a = { new pair ( 1 , 3 ) , new pair ( 4 , 7 ) , new pair ( 8 , 11 ) } ; int n = a . Length ; int k = 6 ; int index = findNumber ( a , n , k ) ; if ( index != - 1 ) Console . WriteLine ( index ) ; else Console . WriteLine ( - 1 ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG, pair
C# program:
using System ; class GFG { public class pair { public int first , second ; public pair ( int first , int second ) { this . first = first ; this . second = second ; } } static int findNumber ( pair [ ] a , int n , int K ) { int low = 0 , high = n - 1 ; while ( low <= high ) { int mid = ( low + high ) >> 1 ; if ( K >= a [ mid ] . first && K <= a [ mid ] . second ) return mid ; else if ( K < a [ mid ] . first ) high = mid - 1 ; else low = mid + 1 ; } return - 1 ; } public static void Main ( String [ ] args ) { pair [ ] a = { new pair ( 1 , 3 ) , new pair ( 4 , 7 ) , new pair ( 8 , 11 ) } ; int n = a . Length ; int k = 6 ; int index = findNumber ( a , n , k ) ; if ( index != - 1 ) Console . WriteLine ( index ) ; else Console . WriteLine ( - 1 ) ; } }

Index/key variables: mid
Class/struct names: GFG, pair
C# program:
using System ; using System . Collections . Generic ; class GFG { static void prefixSum ( int [ ] p_arr , int [ ] arr , int n ) { p_arr [ 0 ] = arr [ 0 ] ; for ( int i = 1 ; i < n ; i ++ ) p_arr [ i ] = arr [ i ] + p_arr [ i - 1 ] ; } static void qPrefixSum ( int [ ] p_arr , int n , HashSet < int > q ) { for ( int i = 0 ; i < n ; i ++ ) q . Add ( p_arr [ i ] ) ; } static void canDivide ( int [ ] p_arr , int n , HashSet < int > q , int l , int r ) { int sum ; if ( l == 0 ) sum = p_arr [ r ] ; else sum = p_arr [ r ] - p_arr [ l - 1 ] ; if ( sum % 2 == 1 ) { Console . WriteLine ( " No " ) ; return ; } int beg = 0 ; if ( l != 0 ) beg = p_arr [ l - 1 ] ; if ( q . Contains ( beg + sum / 2 ) ) Console . WriteLine ( " Yes " ) ; else Console . WriteLine ( " No " ) ; } public static void Main ( String [ ] args ) { int [ ] arr = { 1 , 1 , 2 , 3 } ; int n = arr . Length ; int [ ] p_arr = new int [ n ] ; prefixSum ( p_arr , arr , n ) ; HashSet < int > q = new HashSet < int > ( ) ; qPrefixSum ( p_arr , n , q ) ; canDivide ( p_arr , n , q , 0 , 1 ) ; canDivide ( p_arr , n , q , 1 , 3 ) ; canDivide ( p_arr , n , q , 1 , 2 ) ; } }

Index/key variables: i, n, r
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static int n = 4 ; static int findRing ( int [ , ] arr , int x ) { if ( arr [ 0 , 0 ] > x ) return - 1 ; int l = 0 , r = ( n + 1 ) / 2 - 1 ; if ( n % 2 == 1 && arr [ r , r ] < x ) return - 1 ; if ( n % 2 == 0 && arr [ r + 1 , r ] < x ) return - 1 ; while ( l < r ) { int mid = ( l + r ) / 2 ; if ( arr [ mid , mid ] <= x ) if ( mid == ( n + 1 ) / 2 - 1 arr [ mid + 1 , mid + 1 ] > x ) return mid ; else l = mid + 1 ; else r = mid - 1 ; } return r ; } static int binarySearchRowInc ( int [ , ] arr , int row , int l , int r , int x ) { while ( l <= r ) { int mid = ( l + r ) / 2 ; if ( arr [ row , mid ] == x ) return mid ; if ( arr [ row , mid ] < x ) l = mid + 1 ; else r = mid - 1 ; } return - 1 ; } static int binarySearchColumnInc ( int [ , ] arr , int col , int t , int b , int x ) { while ( t <= b ) { int mid = ( t + b ) / 2 ; if ( arr [ mid , col ] == x ) return mid ; if ( arr [ mid , col ] < x ) t = mid + 1 ; else b = mid - 1 ; } return - 1 ; } static int binarySearchRowDec ( int [ , ] arr , int row , int l , int r , int x ) { while ( l <= r ) { int mid = ( l + r ) / 2 ; if ( arr [ row , mid ] == x ) return mid ; if ( arr [ row , mid ] < x ) r = mid - 1 ; else l = mid + 1 ; } return - 1 ; } static int binarySearchColumnDec ( int [ , ] arr , int col , int t , int b , int x ) { while ( t <= b ) { int mid = ( t + b ) / 2 ; if ( arr [ mid , col ] == x ) return mid ; if ( arr [ mid , col ] < x ) b = mid - 1 ; else t = mid + 1 ; } return - 1 ; } static void spiralBinary ( int [ , ] arr , int x ) { int f1 = findRing ( arr , x ) ; int r , c ; if ( f1 == - 1 ) { Console . Write ( " - 1" ) ; return ; } if ( n % 2 == 1 && f1 == ( n + 1 ) / 2 - 1 ) { Console . WriteLine ( f1 + " ▁ " + f1 ) ; return ; } if ( x < arr [ f1 , n - f1 - 1 ] ) { c = binarySearchRowInc ( arr , f1 , f1 , n - f1 - 2 , x ) ; r = f1 ; } else if ( x < arr [ n - f1 - 1 , n - f1 - 1 ] ) { c = n - f1 - 1 ; r = binarySearchColumnInc ( arr , n - f1 - 1 , f1 , n - f1 - 2 , x ) ; } else if ( x < arr [ n - f1 - 1 , f1 ] ) { c = binarySearchRowDec ( arr , n - f1 - 1 , f1 + 1 , n - f1 - 1 , x ) ; r = n - f1 - 1 ; } else { r = binarySearchColumnDec ( arr , f1 , f1 + 1 , n - f1 - 1 , x ) ; c = f1 ; } if ( c == - 1 r == - 1 ) Console . Write ( " - 1" ) ; else Console . Write ( r + " ▁ " + c ) ; return ; } public static void Main ( String [ ] args ) { int [ , ] arr = { { 1 , 2 , 3 , 4 } , { 12 , 13 , 14 , 5 } , { 11 , 16 , 15 , 6 } , { 10 , 9 , 8 , 7 } } ; spiralBinary ( arr , 7 ) ; } }

Class/struct names: GFG
C# program:
using System ; class GFG { static int costToPanagram ( string str , int [ ] cost ) { int i , n = str . Length ; int [ ] occurrences = new int [ 26 ] ; for ( i = 0 ; i < n ; i ++ ) occurrences [ str [ i ] - ' a ' ] ++ ; int gain = 0 ; for ( i = 0 ; i < 26 ; i ++ ) { if ( occurrences [ i ] == 0 ) gain -= ( 2 * cost [ i ] ) ; else if ( occurrences [ i ] > 1 ) gain += ( cost [ i ] * ( occurrences [ i ] - 1 ) ) ; } if ( gain >= 0 ) return 0 ; return ( gain * - 1 ) ; } public static void Main ( ) { int [ ] cost = { 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 } ; string str = " geeksforgeeks " ; Console . WriteLine ( costToPanagram ( str , cost ) ) ; } }

Index/key variables: i
Accumulator variables: gain, i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; using System . Collections . Generic ; class GfG { static int strScore ( string [ ] str , string s , int n ) { Dictionary < string , int > m = new Dictionary < string , int > ( ) ; for ( int i = 0 ; i < n ; i ++ ) m [ str [ i ] ] = i + 1 ; if ( ! m . ContainsKey ( s ) ) return 0 ; int score = 0 ; for ( int i = 0 ; i < s . Length ; i ++ ) score += s [ i ] - ' a ' + 1 ; score = score * m [ s ] ; return score ; } public static void Main ( ) { string [ ] str = { " geeksforgeeks " , " algorithms " , " stack " } ; string s = " algorithms " ; int n = str . Length ; Console . WriteLine ( strScore ( str , s , n ) ) ; } }

Index/key variables: i, s
Accumulator variables: i, score
Iterator variables: i
Class/struct names: GfG
C# program:
using System ; class GFG { static int countSubArrays ( int [ ] arr , int n , int K ) { int count = 0 ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = i ; j < n ; j ++ ) { int bitwise_or = 0 ; for ( int k = i ; k <= j ; k ++ ) { bitwise_or = bitwise_or | arr [ k ] ; } if ( bitwise_or >= K ) count ++ ; } } return count ; } public static void Main ( ) { int [ ] arr = { 3 , 4 , 5 } ; int n = arr . Length ; int k = 6 ; Console . WriteLine ( countSubArrays ( arr , n , k ) ) ; } }

Index/key variables: k
Accumulator variables: count, i, j, k
Iterator variables: i, j, k
Class/struct names: GFG
C# program:
using System ; class GFG { static int N = 100002 ; static int [ ] tree = new int [ 4 * N ] ; static void build ( int [ ] arr , int node , int start , int end ) { if ( start == end ) { tree [ node ] = arr [ start ] ; return ; } int mid = ( start + end ) >> 1 ; build ( arr , 2 * node , start , mid ) ; build ( arr , 2 * node + 1 , mid + 1 , end ) ; tree [ node ] = tree [ 2 * node ] | tree [ 2 * node + 1 ] ; } static int query ( int node , int start , int end , int l , int r ) { if ( start > end start > r end < l ) { return 0 ; } if ( start >= l && end <= r ) { return tree [ node ] ; } int mid = ( start + end ) >> 1 ; int q1 = query ( 2 * node , start , mid , l , r ) ; int q2 = query ( 2 * node + 1 , mid + 1 , end , l , r ) ; return q1 | q2 ; } static int countSubArrays ( int [ ] arr , int n , int K ) { build ( arr , 1 , 0 , n - 1 ) ; int count = 0 ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = i ; j < n ; j ++ ) { int bitwise_or = query ( 1 , 0 , n - 1 , i , j ) ; if ( bitwise_or >= K ) count ++ ; } } return count ; } static void Main ( ) { int [ ] arr = { 3 , 4 , 5 } ; int n = arr . Length ; int k = 6 ; Console . WriteLine ( countSubArrays ( arr , n , k ) ) ; } }

Index/key variables: node, start
Accumulator variables: count, i, j
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; class GFG { static int N = 100002 ; static int [ ] tree = new int [ 4 * N ] ; static void build ( int [ ] arr , int node , int start , int end ) { if ( start == end ) { tree [ node ] = arr [ start ] ; return ; } int mid = ( start + end ) >> 1 ; build ( arr , 2 * node , start , mid ) ; build ( arr , 2 * node + 1 , mid + 1 , end ) ; tree [ node ] = tree [ 2 * node ] | tree [ 2 * node + 1 ] ; } static int query ( int node , int start , int end , int l , int r ) { if ( start > end start > r end < l ) { return 0 ; } if ( start >= l && end <= r ) { return tree [ node ] ; } int mid = ( start + end ) >> 1 ; int q1 = query ( 2 * node , start , mid , l , r ) ; int q2 = query ( 2 * node + 1 , mid + 1 , end , l , r ) ; return q1 | q2 ; } static int countSubArrays ( int [ ] arr , int n , int K ) { int count = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int low = i , high = n - 1 , index = int . MaxValue ; while ( low <= high ) { int mid = ( low + high ) >> 1 ; if ( query ( 1 , 0 , n - 1 , i , mid ) >= K ) { index = Math . Min ( index , mid ) ; high = mid - 1 ; } else { low = mid + 1 ; } } if ( index != int . MaxValue ) { count += n - index ; } } return count ; } public static void Main ( String [ ] args ) { int [ ] arr = { 3 , 4 , 5 } ; int n = arr . Length ; build ( arr , 1 , 0 , n - 1 ) ; int k = 6 ; Console . WriteLine ( countSubArrays ( arr , n , k ) ) ; } }

Index/key variables: node, start
Accumulator variables: count, i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static int countPattern ( int n , string pat ) { int pattern_int = 0 ; int power_two = 1 ; int all_ones = 0 ; for ( int i = pat . Length - 1 ; i >= 0 ; i -- ) { int current_bit = pat [ i ] - '0' ; pattern_int += ( power_two * current_bit ) ; all_ones = all_ones + power_two ; power_two = power_two * 2 ; } int count = 0 ; while ( n != 0 && n >= pattern_int ) { if ( ( n & all_ones ) == pattern_int ) { count ++ ; } n = n >> 1 ; } return count ; } public static void Main ( ) { int n = 500 ; string pat = "10" ; Console . WriteLine ( countPattern ( n , pat ) ) ; } }

Index/key variables: i
Accumulator variables: count, i, pattern_int
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static int max_min ( int [ ] a , int n ) { Array . Sort ( a ) ; return Math . Min ( a [ n - 2 ] - a [ 0 ] , a [ n - 1 ] - a [ 1 ] ) ; } public static void Main ( ) { int [ ] a = { 1 , 3 , 3 , 7 } ; int n = a . Length ; Console . WriteLine ( max_min ( a , n ) ) ; } }

Class/struct names: GFG
C# program:
using System ; public class GFG { static int MAX = 1000001 ; static int [ ] primeUpto = new int [ MAX ] ; static void SieveOfEratosthenes ( ) { int [ ] isPrime = new int [ MAX ] ; for ( int i = 0 ; i < MAX ; i ++ ) isPrime [ i ] = 1 ; isPrime [ 0 ] = isPrime [ 1 ] = 0 ; for ( int i = 2 ; i * i < MAX ; i ++ ) { if ( isPrime [ i ] == 1 ) { for ( int j = i * 2 ; j < MAX ; j += i ) isPrime [ j ] = 0 ; } } for ( int i = 1 ; i < MAX ; i ++ ) { primeUpto [ i ] = primeUpto [ i - 1 ] ; if ( isPrime [ i ] == 1 ) primeUpto [ i ] ++ ; } } static int countOfNumbers ( int N , int K ) { SieveOfEratosthenes ( ) ; int low = 1 , high = N , ans = 0 ; while ( low <= high ) { int mid = ( low + high ) >> 1 ; if ( mid - primeUpto [ mid ] >= K ) { ans = mid ; high = mid - 1 ; } else low = mid + 1 ; } ans = ans != 0 ? N - ans + 1 : 0 ; return ans ; } public static void Main ( ) { int N = 10 , K = 3 ; Console . WriteLine ( countOfNumbers ( N , K ) ) ; } }

Index/key variables: MAX, i, j, mid
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; class GFG { static int minIndex ( int [ ] arr , int n ) { int sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) sum += arr [ i ] ; for ( int i = 0 ; i < n ; i ++ ) { if ( 2 * arr [ i ] == sum ) return ( i + 1 ) ; } return - 1 ; } public static void Main ( ) { int [ ] arr = { 1 , 3 , - 5 , 3 , 4 } ; int n = arr . Length ; Console . Write ( minIndex ( arr , n ) ) ; } }

Index/key variables: i
Accumulator variables: i, sum
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static void printPrevGreater ( int [ ] arr , int n ) { if ( n == 1 ) { Console . Write ( " - 1" ) ; return ; } int [ ] v = new int [ arr . GetLength ( 0 ) ] ; Array . Copy ( arr , v , arr . GetLength ( 0 ) ) ; Array . Sort ( v ) ; for ( int i = 0 ; i < n ; i ++ ) { int it = Array . BinarySearch ( v , arr [ i ] ) ; it ++ ; if ( ( it - 1 ) != 0 && v [ it - 2 ] == arr [ i ] ) { Console . Write ( arr [ i ] + " ▁ " ) ; } else if ( it != v . Length ) Console . Write ( v [ it ] + " ▁ " ) ; else Console . Write ( - 1 + " ▁ " ) ; } } public static void Main ( String [ ] args ) { int [ ] arr = { 10 , 5 , 11 , 10 , 20 , 12 } ; int n = arr . Length ; printPrevGreater ( arr , n ) ; } }

Index/key variables: i, it
Accumulator variables: i, it
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; public class GFG { static void diagonalsMinMax ( int [ , ] mat ) { int n = mat . GetLength ( 0 ) ; if ( n == 0 ) return ; int principalMin = mat [ 0 , 0 ] , principalMax = mat [ 0 , 0 ] ; int secondaryMin = mat [ n - 1 , 0 ] , secondaryMax = mat [ n - 1 , 0 ] ; for ( int i = 0 ; i < n ; i ++ ) { if ( mat [ i , i ] < principalMin ) { principalMin = mat [ i , i ] ; } if ( mat [ i , i ] > principalMax ) { principalMax = mat [ i , i ] ; } if ( mat [ n - 1 - i , i ] < secondaryMin ) { secondaryMin = mat [ n - 1 - i , i ] ; } if ( mat [ n - 1 - i , i ] > secondaryMax ) { secondaryMax = mat [ n - 1 - i , i ] ; } } Console . WriteLine ( " Principal ▁ Diagonal ▁ Smallest ▁ Element : ▁ " + principalMin ) ; Console . WriteLine ( " Principal ▁ Diagonal ▁ Greatest ▁ Element ▁ : ▁ " + principalMax ) ; Console . WriteLine ( " Secondary ▁ Diagonal ▁ Smallest ▁ Element : ▁ " + secondaryMin ) ; Console . WriteLine ( " Secondary ▁ Diagonal ▁ Greatest ▁ Element : ▁ " + secondaryMax ) ; } public static void Main ( ) { int [ , ] matrix = { { 1 , 2 , 3 , 4 , - 10 } , { 5 , 6 , 7 , 8 , 6 } , { 1 , 2 , 11 , 3 , 4 } , { 5 , 6 , 70 , 5 , 8 } , { 4 , 9 , 7 , 1 , - 5 } } ; diagonalsMinMax ( matrix ) ; } }

Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static bool checkSorted ( int n , int [ ] arr ) { int first = 0 , second = 0 ; int count = 0 ; for ( int i = 1 ; i < n ; i ++ ) { if ( arr [ i ] < arr [ i - 1 ] ) { count ++ ; if ( first == 0 ) first = i ; else second = i ; } } if ( count > 2 ) return false ; if ( count == 0 ) return true ; if ( count == 2 ) swap ( arr , first - 1 , second ) ; else if ( count == 1 ) swap ( arr , first - 1 , first ) ; for ( int i = 1 ; i < n ; i ++ ) if ( arr [ i ] < arr [ i - 1 ] ) return false ; return true ; } static int [ ] swap ( int [ ] arr , int i , int j ) { int temp = arr [ i ] ; arr [ i ] = arr [ j ] ; arr [ j ] = temp ; return arr ; } public static void Main ( String [ ] args ) { int [ ] arr = { 1 , 4 , 3 , 2 } ; int n = arr . Length ; if ( checkSorted ( n , arr ) ) Console . WriteLine ( " Yes " ) ; else Console . WriteLine ( " No " ) ; } }

Index/key variables: i, j
Accumulator variables: count, i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static int N = 4 ; static int M = 4 ; static void printIntersection ( int [ , ] A , int [ , ] B ) { for ( int i = 0 ; i < M ; i ++ ) { for ( int j = 0 ; j < N ; j ++ ) { if ( A [ i , j ] == B [ i , j ] ) Console . Write ( A [ i , j ] + " ▁ " ) ; else Console . Write ( " * ▁ " ) ; } Console . WriteLine ( " ▁ " ) ; } } public static void Main ( ) { int [ , ] A = { { 2 , 4 , 6 , 8 } , { 1 , 3 , 5 , 7 } , { 8 , 6 , 4 , 2 } , { 7 , 5 , 3 , 1 } } ; int [ , ] B = { { 2 , 3 , 6 , 8 } , { 1 , 3 , 5 , 2 } , { 8 , 1 , 4 , 2 } , { 3 , 5 , 4 , 1 } } ; printIntersection ( A , B ) ; } }

Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; class GFG { static int countWays ( int [ ] arr , int n ) { int max_val = 0 ; for ( int i = 0 ; i < n ; i ++ ) max_val = Math . Max ( max_val , arr [ i ] ) ; int [ ] freq = new int [ max_val + 1 ] ; for ( int i = 0 ; i < n ; i ++ ) freq [ arr [ i ] ] ++ ; ans += freq [ 0 ] * ( freq [ 0 ] - 1 ) * ( freq [ 0 ] - 2 ) / 6 ; for ( int i = 1 ; i <= max_val ; i ++ ) ans += freq [ 0 ] * freq [ i ] * ( freq [ i ] - 1 ) / 2 ; for ( int i = 1 ; 2 * i <= max_val ; i ++ ) ans += freq [ i ] * ( freq [ i ] - 1 ) / 2 * freq [ 2 * i ] ; for ( int i = 1 ; i <= max_val ; i ++ ) { for ( int j = i + 1 ; i + j <= max_val ; j ++ ) ans += freq [ i ] * freq [ j ] * freq [ i + j ] ; } return ans ; } public static void Main ( ) { int [ ] arr = { 1 , 2 , 3 , 4 , 5 } ; int n = arr . Length ; Console . WriteLine ( countWays ( arr , n ) ) ; } }

Index/key variables: i, j
Accumulator variables: ans, i, j
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; using System . Collections . Generic ; class GfG { static int countPairs ( int [ ] A1 , int [ ] A2 , int n1 , int n2 , int K ) { int res = 0 ; Dictionary < int , int > m = new Dictionary < int , int > ( ) ; for ( int i = 0 ; i < n1 ; ++ i ) { int a ; if ( m . ContainsKey ( A1 [ i ] ) ) { a = m [ A1 [ i ] ] + 1 ; m . Remove ( A1 [ i ] ) ; m . Add ( A1 [ i ] , a ) ; } else m . Add ( A1 [ i ] , 1 ) ; } for ( int i = 0 ; i < n2 ; ++ i ) { int temp = K - A2 [ i ] ; if ( m . ContainsKey ( temp ) && m [ temp ] != 0 ) { res ++ ; m . Remove ( temp ) ; m . Add ( temp , m [ A1 [ i ] ] - 1 ) ; } } return res ; } public static void Main ( ) { int [ ] A1 = { 1 , 1 , 3 , 4 , 5 , 6 , 6 } ; int [ ] A2 = { 1 , 4 , 4 , 5 , 7 } ; int K = 10 ; int n1 = A1 . Length ; int n2 = A2 . Length ; Console . WriteLine ( countPairs ( A1 , A2 , n1 , n2 , K ) ) ; } }

Index/key variables: i, temp
Accumulator variables: res
Iterator variables: i
Class/struct names: GfG