dhyuti-n/xlcost-variable-roles huggingface dataset:
C# program:
using System ; class GFG { static int N = 4 ; static void printSolution ( int [ , ] sol ) { for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < N ; j ++ ) { Console . Write ( " ▁ { 0 } ▁ " , sol [ i , j ] ) ; } Console . Write ( " STRNEWLINE " ) ; } } static Boolean isSafe ( int [ , ] maze , int x , int y ) { if ( x >= 0 && x < N && y >= 0 && y < N && maze [ x , y ] != 0 ) { return true ; } return false ; } static Boolean solveMaze ( int [ , ] maze ) { int [ , ] sol = { { 0 , 0 , 0 , 0 } , { 0 , 0 , 0 , 0 } , { 0 , 0 , 0 , 0 } , { 0 , 0 , 0 , 0 } } ; if ( solveMazeUtil ( maze , 0 , 0 , sol ) == false ) { Console . Write ( " Solution ▁ doesn ' t ▁ exist " ) ; return false ; } printSolution ( sol ) ; return true ; } static Boolean solveMazeUtil ( int [ , ] maze , int x , int y , int [ , ] sol ) { if ( x == N - 1 && y == N - 1 ) { sol [ x , y ] = 1 ; return true ; } if ( isSafe ( maze , x , y ) == true ) { sol [ x , y ] = 1 ; for ( int i = 1 ; i <= maze [ x , y ] && i < N ; i ++ ) { if ( solveMazeUtil ( maze , x + i , y , sol ) == true ) { return true ; } if ( solveMazeUtil ( maze , x , y + i , sol ) == true ) { return true ; } } sol [ x , y ] = 0 ; return false ; } return false ; } public static void Main ( String [ ] args ) { int [ , ] maze = { { 2 , 1 , 0 , 0 } , { 3 , 0 , 0 , 1 } , { 0 , 1 , 0 , 1 } , { 0 , 0 , 0 , 1 } } ; solveMaze ( maze ) ; } }

Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; using System . Collections . Generic ; class GFG { static List < int > set = new List < int > ( ) ; static List < int > prime = new List < int > ( ) ; static bool isPrime ( int x ) { int sqroot = ( int ) Math . Sqrt ( x ) ; if ( x == 1 ) return false ; for ( int i = 2 ; i <= sqroot ; i ++ ) if ( x % i == 0 ) return false ; return true ; } static void display ( ) { int length = set . Count ; for ( int i = 0 ; i < length ; i ++ ) Console . Write ( set [ i ] + " ▁ " ) ; Console . WriteLine ( ) ; } static void primeSum ( int total , int N , int S , int index ) { if ( total == S && set . Count == N ) { display ( ) ; return ; } if ( total > S index == prime . Count ) return ; set . Add ( prime [ index ] ) ; primeSum ( total + prime [ index ] , N , S , index + 1 ) ; set . RemoveAt ( set . Count - 1 ) ; primeSum ( total , N , S , index + 1 ) ; } static void allPrime ( int N , int S , int P ) { for ( int i = P + 1 ; i <= S ; i ++ ) { if ( isPrime ( i ) ) prime . Add ( i ) ; } if ( prime . Count < N ) return ; primeSum ( 0 , N , S , 0 ) ; } static void Main ( ) { int S = 54 , N = 2 , P = 3 ; allPrime ( N , S , P ) ; } }

Index/key variables: i, index
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; using System . Collections . Generic ; class GFG { static int num ; static void grayCodeUtil ( List < int > res , int n ) { if ( n == 0 ) { res . Add ( num ) ; return ; } grayCodeUtil ( res , n - 1 ) ; num = num ^ ( 1 << ( n - 1 ) ) ; grayCodeUtil ( res , n - 1 ) ; } static List < int > grayCodes ( int n ) { List < int > res = new List < int > ( ) ; num = 0 ; grayCodeUtil ( res , n ) ; return res ; } public static void Main ( String [ ] args ) { int n = 3 ; List < int > code = grayCodes ( n ) ; for ( int i = 0 ; i < code . Count ; i ++ ) Console . Write ( code [ i ] + " STRNEWLINE " ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static bool isKPartitionPossibleRec ( int [ ] arr , int [ ] subsetSum , bool [ ] taken , int subset , int K , int N , int curIdx , int limitIdx ) { if ( subsetSum [ curIdx ] == subset ) { if ( curIdx == K - 2 ) return true ; return isKPartitionPossibleRec ( arr , subsetSum , taken , subset , K , N , curIdx + 1 , N - 1 ) ; } for ( int i = limitIdx ; i >= 0 ; i -- ) { if ( taken [ i ] ) continue ; int tmp = subsetSum [ curIdx ] + arr [ i ] ; if ( tmp <= subset ) { taken [ i ] = true ; subsetSum [ curIdx ] += arr [ i ] ; bool nxt = isKPartitionPossibleRec ( arr , subsetSum , taken , subset , K , N , curIdx , i - 1 ) ; taken [ i ] = false ; subsetSum [ curIdx ] -= arr [ i ] ; if ( nxt ) return true ; } } return false ; } static bool isKPartitionPossible ( int [ ] arr , int N , int K ) { if ( K == 1 ) return true ; if ( N < K ) return false ; int sum = 0 ; for ( int i = 0 ; i < N ; i ++ ) sum += arr [ i ] ; if ( sum % K != 0 ) return false ; int subset = sum / K ; int [ ] subsetSum = new int [ K ] ; bool [ ] taken = new bool [ N ] ; for ( int i = 0 ; i < K ; i ++ ) subsetSum [ i ] = 0 ; for ( int i = 0 ; i < N ; i ++ ) taken [ i ] = false ; subsetSum [ 0 ] = arr [ N - 1 ] ; taken [ N - 1 ] = true ; return isKPartitionPossibleRec ( arr , subsetSum , taken , subset , K , N , 0 , N - 1 ) ; } static public void Main ( ) { int [ ] arr = { 2 , 1 , 4 , 5 , 3 , 3 } ; int N = arr . Length ; int K = 3 ; if ( isKPartitionPossible ( arr , N , K ) ) Console . WriteLine ( " Partitions ▁ into ▁ equal ▁ sum ▁ is ▁ possible . " ) ; else Console . WriteLine ( " Partitions ▁ into ▁ equal ▁ sum ▁ is ▁ not ▁ possible . " ) ; } }

Index/key variables: K, N, curIdx, i
Accumulator variables: i, sum
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; using System . Collections . Generic ; class GFG { static bool isParenthesis ( char c ) { return ( ( c == ' ( ' ) || ( c == ' ) ' ) ) ; } static bool isValidString ( String str ) { int cnt = 0 ; for ( int i = 0 ; i < str . Length ; i ++ ) { if ( str [ i ] == ' ( ' ) cnt ++ ; else if ( str [ i ] == ' ) ' ) cnt -- ; if ( cnt < 0 ) return false ; } return ( cnt == 0 ) ; } static void removeInvalidParenthesis ( String str ) { if ( str == null str == " " ) return ; HashSet < String > visit = new HashSet < String > ( ) ; Queue < String > q = new Queue < String > ( ) ; String temp ; bool level = false ; q . Enqueue ( str ) ; visit . Add ( str ) ; while ( q . Count != 0 ) { str = q . Peek ( ) ; q . Dequeue ( ) ; if ( isValidString ( str ) ) { Console . WriteLine ( str ) ; level = true ; } if ( level ) continue ; for ( int i = 0 ; i < str . Length ; i ++ ) { if ( ! isParenthesis ( str [ i ] ) ) continue ; temp = str . Substring ( 0 , i ) + str . Substring ( i + 1 ) ; if ( ! visit . Contains ( temp ) ) { q . Enqueue ( temp ) ; visit . Add ( temp ) ; } } } } public static void Main ( String [ ] args ) { String expression = " ( ) ( ) ) ( ) " ; removeInvalidParenthesis ( expression ) ; expression = " ( ) v ) " ; removeInvalidParenthesis ( expression ) ; } }

Index/key variables: i
Accumulator variables: cnt, i
Iterator variables: i
Boolean variables: level
Class/struct names: GFG
C# program:
using System ; class GFG { static int N = 4 ; static int [ ] ld = new int [ 30 ] ; static int [ ] rd = new int [ 30 ] ; static int [ ] cl = new int [ 30 ] ; static void printSolution ( int [ , ] board ) { for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < N ; j ++ ) Console . Write ( " ▁ { 0 } ▁ " , board [ i , j ] ) ; Console . Write ( " STRNEWLINE " ) ; } } static bool solveNQUtil ( int [ , ] board , int col ) { if ( col >= N ) return true ; for ( int i = 0 ; i < N ; i ++ ) { if ( ( ld [ i - col + N - 1 ] != 1 && rd [ i + col ] != 1 ) && cl [ i ] != 1 ) { board [ i , col ] = 1 ; ld [ i - col + N - 1 ] = rd [ i + col ] = cl [ i ] = 1 ; if ( solveNQUtil ( board , col + 1 ) ) return true ; ld [ i - col + N - 1 ] = rd [ i + col ] = cl [ i ] = 0 ; } } return false ; } static bool solveNQ ( ) { int [ , ] board = { { 0 , 0 , 0 , 0 } , { 0 , 0 , 0 , 0 } , { 0 , 0 , 0 , 0 } , { 0 , 0 , 0 , 0 } } ; if ( solveNQUtil ( board , 0 ) == false ) { Console . Write ( " Solution ▁ does ▁ not ▁ exist " ) ; return false ; } printSolution ( board ) ; return true ; } public static void Main ( String [ ] args ) { solveNQ ( ) ; } }

Index/key variables: i
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; class GFG { static void printPairs ( int [ ] a , int n , int x ) { int i ; int [ ] rem = new int [ x ] ; for ( i = 0 ; i < x ; i ++ ) { rem [ i ] = 0 ; } for ( i = 0 ; i < n ; i ++ ) { if ( a [ i ] < x ) { rem [ a [ i ] % x ] ++ ; } } for ( i = 1 ; i < x / 2 ; i ++ ) { if ( rem [ i ] > 0 && rem [ x - i ] > 0 ) { Console . Write ( " Yes " + " STRNEWLINE " ) ; break ; } } if ( i >= x / 2 ) { if ( x % 2 == 0 ) { if ( rem [ x / 2 ] > 1 ) { Console . Write ( " Yes " + " STRNEWLINE " ) ; } else { Console . Write ( " No " + " STRNEWLINE " ) ; } } else { if ( rem [ x / 2 ] > 0 && rem [ x - x / 2 ] > 0 ) { Console . Write ( " Yes " + " STRNEWLINE " ) ; } else { Console . WriteLine ( " No " + " STRNEWLINE " ) ; } } } } public static void Main ( string [ ] args ) { int [ ] A = { 1 , 4 , 45 , 6 , 10 , 8 } ; int n = 16 ; int arr_size = A . Length ; printPairs ( A , arr_size , n ) ; } }

Index/key variables: i, x
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; public class GFG { static int fact ( int n ) { int ans = 1 ; for ( int i = 2 ; i <= n ; i ++ ) ans *= i ; return ans ; } static int remainder ( int n , int a , int p ) { int len = fact ( n ) ; int ans = 1 ; for ( int i = 1 ; i <= len ; i ++ ) ans = ( ans * a ) % p ; return ans ; } public static void Main ( string [ ] args ) { int A = 2 , N = 1 , P = 2 ; Console . WriteLine ( remainder ( N , A , P ) ) ; } }

Accumulator variables: ans, i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static bool check ( int n , int w ) { int [ ] a = new int [ 105 ] ; int p = 0 ; while ( n > 0 ) { a [ p ++ ] = n % w ; n /= w ; } bool flag = true ; for ( int i = 0 ; i <= 100 ; i ++ ) { if ( a [ i ] == 0 a [ i ] == 1 ) continue ; else if ( a [ i ] == w a [ i ] == w - 1 ) a [ i + 1 ] ++ ; else flag = false ; } return flag ; } public static void Main ( String [ ] args ) { int B = 3 , N = 7 ; if ( check ( N , B ) ) Console . Write ( " Yes " ) ; else Console . Write ( " No " ) ; } }

Index/key variables: i
Accumulator variables: i, n, p
Iterator variables: i
Boolean variables: flag
Class/struct names: GFG
C# program:
using System ; class GFG { static long mod = 1000000007 ; static int exponentMod ( int A , int B ) { if ( A == 0 ) return 0 ; if ( B == 0 ) return 1 ; long y ; if ( B % 2 == 0 ) { y = exponentMod ( A , B / 2 ) ; y = ( y * y ) % mod ; } else { y = A % mod ; y = ( y * exponentMod ( A , B - 1 ) % mod ) % mod ; } return ( int ) ( ( y + mod ) % mod ) ; } static void countWays ( int N ) { long select = exponentMod ( 2 , N - 1 ) ; long ways = ( ( N % mod ) * ( select % mod ) ) ; ways %= mod ; Console . Write ( ways ) ; } public static void Main ( String [ ] args ) { int N = 5 ; countWays ( N ) ; } }

Class/struct names: GFG
C# program:
using System ; class GFG { static readonly int MAX = 1000 ; static bool isPerfectSquare ( int x ) { double sr = Math . Sqrt ( x ) ; return ( ( sr - Math . Floor ( sr ) ) == 0 ) ? true : false ; } static int getMid ( int s , int e ) { return s + ( e - s ) / 2 ; } static int queryUtil ( int [ ] st , int ss , int se , int qs , int qe , int index ) { if ( qs <= ss && qe >= se ) return st [ index ] ; if ( se < qs ss > qe ) return 0 ; int mid = getMid ( ss , se ) ; return queryUtil ( st , ss , mid , qs , qe , 2 * index + 1 ) + queryUtil ( st , mid + 1 , se , qs , qe , 2 * index + 2 ) ; } static void updateValueUtil ( int [ ] st , int ss , int se , int i , int diff , int si ) { if ( i < ss i > se ) return ; st [ si ] = st [ si ] + diff ; if ( se != ss ) { int mid = getMid ( ss , se ) ; updateValueUtil ( st , ss , mid , i , diff , 2 * si + 1 ) ; updateValueUtil ( st , mid + 1 , se , i , diff , 2 * si + 2 ) ; } } static void updateValue ( int [ ] arr , int [ ] st , int n , int i , int new_val ) { if ( i < 0 i > n - 1 ) { Console . Write ( " Invalid ▁ Input " ) ; return ; } int diff = 0 , oldValue ; oldValue = arr [ i ] ; arr [ i ] = new_val ; if ( isPerfectSquare ( oldValue ) && isPerfectSquare ( new_val ) ) return ; if ( ! isPerfectSquare ( oldValue ) && ! isPerfectSquare ( new_val ) ) return ; if ( isPerfectSquare ( oldValue ) && ! isPerfectSquare ( new_val ) ) { diff = - 1 ; } if ( ! isPerfectSquare ( oldValue ) && ! isPerfectSquare ( new_val ) ) { diff = 1 ; } updateValueUtil ( st , 0 , n - 1 , i , diff , 0 ) ; } static void query ( int [ ] st , int n , int qs , int qe ) { int perfectSquareInRange = queryUtil ( st , 0 , n - 1 , qs , qe , 0 ) ; Console . Write ( perfectSquareInRange + " STRNEWLINE " ) ; } static int constructSTUtil ( int [ ] arr , int ss , int se , int [ ] st , int si ) { if ( ss == se ) { if ( isPerfectSquare ( arr [ ss ] ) ) st [ si ] = 1 ; else st [ si ] = 0 ; return st [ si ] ; } int mid = getMid ( ss , se ) ; st [ si ] = constructSTUtil ( arr , ss , mid , st , si * 2 + 1 ) + constructSTUtil ( arr , mid + 1 , se , st , si * 2 + 2 ) ; return st [ si ] ; } static int [ ] constructST ( int [ ] arr , int n ) { int x = ( int ) ( Math . Ceiling ( Math . Log ( n ) ) ) ; int max_size = 4 * ( int ) Math . Pow ( 2 , x ) + 1 ; int [ ] st = new int [ max_size ] ; constructSTUtil ( arr , 0 , n - 1 , st , 0 ) ; return st ; } public static void Main ( String [ ] args ) { int [ ] arr = { 16 , 15 , 8 , 9 , 14 , 25 } ; int n = arr . Length ; int [ ] st = constructST ( arr , n ) ; int start = 0 ; int end = 4 ; query ( st , n , start , end ) ; int i = 3 ; int x = 11 ; updateValue ( arr , st , n , i , x ) ; start = 0 ; end = 4 ; query ( st , n , start , end ) ; } }

Index/key variables: i, index, max_size, si, ss
Class/struct names: GFG
C# program:
using System ; class GFG { class Node { public int value ; public int max_set_bits ; } ; static Node [ ] tree = new Node [ 4 * 10000 ] ; static int setBits ( int x ) { int parity = 0 ; while ( x != 0 ) { if ( x % 2 == 1 ) parity ++ ; x = x >> 1 ; } return parity ; } static void buildSegmentTree ( int [ ] a , int index , int beg , int end ) { if ( beg == end ) { tree [ index ] . value = a [ beg ] ; tree [ index ] . max_set_bits = setBits ( a [ beg ] ) ; } else { int mid = ( beg + end ) / 2 ; buildSegmentTree ( a , 2 * index + 1 , beg , mid ) ; buildSegmentTree ( a , 2 * index + 2 , mid + 1 , end ) ; if ( tree [ 2 * index + 1 ] . max_set_bits > tree [ 2 * index + 2 ] . max_set_bits ) { tree [ index ] . max_set_bits = tree [ 2 * index + 1 ] . max_set_bits ; tree [ index ] . value = tree [ 2 * index + 1 ] . value ; } else if ( tree [ 2 * index + 2 ] . max_set_bits > tree [ 2 * index + 1 ] . max_set_bits ) { tree [ index ] . max_set_bits = tree [ 2 * index + 2 ] . max_set_bits ; tree [ index ] . value = tree [ 2 * index + 2 ] . value ; } else { tree [ index ] . max_set_bits = tree [ 2 * index + 2 ] . max_set_bits ; tree [ index ] . value = Math . Max ( tree [ 2 * index + 2 ] . value , tree [ 2 * index + 1 ] . value ) ; } } } static Node query ( int index , int beg , int end , int l , int r ) { Node result = new Node ( ) ; result . value = result . max_set_bits = - 1 ; if ( beg > r end < l ) return result ; if ( beg >= l && end <= r ) return tree [ index ] ; int mid = ( beg + end ) / 2 ; if ( l > mid ) return query ( 2 * index + 2 , mid + 1 , end , l , r ) ; if ( r <= mid ) return query ( 2 * index + 1 , beg , mid , l , r ) ; Node left = query ( 2 * index + 1 , beg , mid , l , r ) ; Node right = query ( 2 * index + 2 , mid + 1 , end , l , r ) ; if ( left . max_set_bits > right . max_set_bits ) { result . max_set_bits = left . max_set_bits ; result . value = left . value ; } else if ( right . max_set_bits > left . max_set_bits ) { result . max_set_bits = right . max_set_bits ; result . value = right . value ; } else { result . max_set_bits = left . max_set_bits ; result . value = Math . Max ( right . value , left . value ) ; } return result ; } public static void Main ( String [ ] args ) { int [ ] a = { 18 , 9 , 8 , 15 , 14 , 5 } ; int N = a . Length ; for ( int i = 0 ; i < tree . Length ; i ++ ) tree [ i ] = new Node ( ) ; buildSegmentTree ( a , 0 , 0 , N - 1 ) ; Console . Write ( query ( 0 , 0 , N - 1 , 1 , 4 ) . value + " STRNEWLINE " ) ; Console . Write ( query ( 0 , 0 , N - 1 , 0 , 2 ) . value + " STRNEWLINE " ) ; } }

Index/key variables: beg, i, index
Accumulator variables: i, parity
Iterator variables: i
Class/struct names: GFG, Node
C# program:
using System ; class GFG { static readonly int maxSize = 50 ; static double [ , ] matrix_product ( double [ , ] a , double [ , ] b ) { double [ , ] c = new double [ 7 , 7 ] ; for ( int i = 0 ; i < 7 ; i ++ ) for ( int j = 0 ; j < 7 ; j ++ ) for ( int k = 0 ; k < 7 ; k ++ ) c [ i , j ] += a [ i , k ] * b [ k , j ] ; return c ; } static double [ , ] mul_expo ( double [ , ] mul , int p ) { double [ , ] s = { { 1 , 0 , 0 , 0 , 0 , 0 , 0 } , { 0 , 1 , 0 , 0 , 0 , 0 , 0 } , { 0 , 0 , 1 , 0 , 0 , 0 , 0 } , { 0 , 0 , 0 , 1 , 0 , 0 , 0 } , { 0 , 0 , 0 , 0 , 1 , 0 , 0 } , { 0 , 0 , 0 , 0 , 0 , 1 , 0 } , { 0 , 0 , 0 , 0 , 0 , 0 , 1 } } ; while ( p != 1 ) { if ( p % 2 == 1 ) s = matrix_product ( s , mul ) ; mul = matrix_product ( mul , mul ) ; p /= 2 ; } return matrix_product ( mul , s ) ; } static double expectedSteps ( int x ) { if ( x == 0 ) return 0 ; if ( x <= 6 ) return 6 ; double [ , ] mul = { { ( double ) 7 / 6 , 1 , 0 , 0 , 0 , 0 , 0 } , { 0 , 0 , 1 , 0 , 0 , 0 , 0 } , { 0 , 0 , 0 , 1 , 0 , 0 , 0 } , { 0 , 0 , 0 , 0 , 1 , 0 , 0 } , { 0 , 0 , 0 , 0 , 0 , 1 , 0 } , { 0 , 0 , 0 , 0 , 0 , 0 , 1 } , { ( double ) - 1 / 6 , 0 , 0 , 0 , 0 , 0 , 0 } } ; mul = mul_expo ( mul , x - 6 ) ; return ( mul [ 0 , 0 ] + mul [ 1 , 0 ] + mul [ 2 , 0 ] + mul [ 3 , 0 ] + mul [ 4 , 0 ] + mul [ 5 , 0 ] ) * 6 ; } public static void Main ( String [ ] args ) { int n = 10 ; Console . Write ( " { 0 : f5 } " , expectedSteps ( n - 1 ) ) ; } }

Accumulator variables: i, j, k, p
Iterator variables: i, j, k
Class/struct names: GFG
C# program:
using System ; using System . Collections ; class GFG { static bool canPlace ( int [ ] a , int n , int p , int sep ) { int prisoners_placed = 1 ; int last_prisoner_placed = a [ 0 ] ; for ( int i = 1 ; i < n ; i ++ ) { int current_cell = a [ i ] ; if ( current_cell - last_prisoner_placed >= sep ) { prisoners_placed ++ ; last_prisoner_placed = current_cell ; if ( prisoners_placed == p ) { return true ; } } } return false ; } static int maxDistance ( int [ ] cell , int n , int p ) { Array . Sort ( cell ) ; int start = 0 ; int end = cell [ n - 1 ] - cell [ 0 ] ; int ans = 0 ; while ( start <= end ) { int mid = start + ( ( end - start ) / 2 ) ; if ( canPlace ( cell , n , p , mid ) ) { ans = mid ; start = mid + 1 ; } else { end = mid - 1 ; } } return ans ; } public static void Main ( ) { int [ ] cell = { 1 , 2 , 8 , 4 , 9 } ; int n = cell . Length ; int p = 3 ; Console . WriteLine ( maxDistance ( cell , n , p ) ) ; } }

Index/key variables: i
Accumulator variables: i, prisoners_placed
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static int [ ] solve ( int n ) { int low = 1 , high = ( int ) 1e4 , x = n , p = 0 ; while ( low <= high ) { int mid = ( low + high ) / 2 ; int sum = ( mid * ( mid + 1 ) ) / 2 ; if ( x - sum >= 1 ) { p = mid ; low = mid + 1 ; } else { high = mid - 1 ; } } int start = 1 , end = ( int ) 1e4 , y = 1 , q = 0 ; while ( start <= end ) { int mid = ( start + end ) / 2 ; int sum = ( mid * ( mid + 1 ) ) / 2 ; if ( y + sum <= n ) { q = mid ; start = mid + 1 ; } else { end = mid - 1 ; } } x = x - ( p * ( p + 1 ) ) / 2 ; y = y + ( q * ( q + 1 ) ) / 2 ; int r = x ; int c = q + 1 - n + y ; int [ ] ans = { r , c } ; return ans ; } public static void main ( String [ ] args ) { int n = 5 ; int [ ] p = solve ( n ) ; Console . WriteLine ( p [ 0 ] + " ▁ " + p [ 1 ] ) ; } }

Class/struct names: GFG
C# program:
using System ; class GFG { static long query ( int start , int end , int left , int right , int node , long [ ] seg ) { if ( end < left start > right ) { return 0 ; } else if ( start >= left && end <= right ) { return seg [ node ] ; } else { int mid = ( start + end ) / 2 ; long leftChild = query ( start , mid , left , right , 2 * node , seg ) ; long rightChild = query ( mid + 1 , end , left , right , 2 * node + 1 , seg ) ; return ( leftChild rightChild ) ; } } static void update ( int left , int right , int index , int Value , int node , int [ ] ar , long [ ] seg ) { if ( left == right ) { ar [ index ] = Value ; seg [ node ] = ( 1L << Value ) ; return ; } int mid = ( left + right ) / 2 ; if ( index > mid ) { update ( mid + 1 , right , index , Value , 2 * node + 1 , ar , seg ) ; } else { update ( left , mid , index , Value , 2 * node , ar , seg ) ; } seg [ node ] = ( seg [ 2 * node ] seg [ 2 * node + 1 ] ) ; } static void build ( int left , int right , int node , int [ ] ar , long [ ] seg ) { if ( left == right ) { seg [ node ] = ( 1L << ar [ left ] ) ; return ; } int mid = ( left + right ) / 2 ; build ( left , mid , 2 * node , ar , seg ) ; build ( mid + 1 , right , 2 * node + 1 , ar , seg ) ; seg [ node ] = ( seg [ 2 * node ] seg [ 2 * node + 1 ] ) ; } static void getDistinctCount ( int [ , ] queries , int [ ] ar , long [ ] seg , int n ) { for ( int i = 0 ; i < queries . GetLength ( 0 ) ; i ++ ) { int op = queries [ i , 0 ] ; if ( op == 2 ) { int l = queries [ i , 1 ] , r = queries [ i , 2 ] ; long tempMask = query ( 0 , n - 1 , l - 1 , r - 1 , 1 , seg ) ; int countOfBits = 0 ; for ( int s = 63 ; s >= 0 ; s -- ) { if ( ( tempMask & ( 1L << s ) ) > 0 ) { countOfBits ++ ; } } Console . WriteLine ( countOfBits ) ; } else { int index = queries [ i , 1 ] ; int val = queries [ i , 2 ] ; update ( 0 , n - 1 , index - 1 , val , 1 , ar , seg ) ; } } } public static void Main ( String [ ] args ) { int n = 7 ; int [ ] ar = { 1 , 2 , 1 , 3 , 1 , 2 , 1 } ; long [ ] seg = new long [ 4 * n ] ; build ( 0 , n - 1 , 1 , ar , seg ) ; int [ , ] queries = { { 2 , 1 , 4 } , { 1 , 4 , 2 } , { 1 , 5 , 2 } , { 2 , 4 , 6 } , { 2 , 1 , 7 } } ; getDistinctCount ( queries , ar , seg , n ) ; } }

Index/key variables: index, left, node
Accumulator variables: countOfBits, i, s
Iterator variables: i, s
Class/struct names: GFG
C# program:
using System ; class GFG { static int maxLen = 30 ; static int [ ] seg = new int [ 3 * maxLen ] ; static int build ( int l , int r , int ind , int [ ] arr ) { if ( l == r ) return seg [ ind ] = arr [ l ] ; int mid = ( l + r ) / 2 ; return seg [ ind ] = __gcd ( build ( l , mid , 2 * ind + 1 , arr ) , build ( mid + 1 , r , 2 * ind + 2 , arr ) ) ; } static int query ( int l , int r , int l1 , int r1 , int ind ) { if ( l1 <= l && r <= r1 ) return seg [ ind ] ; if ( l > r1 r < l1 ) return 0 ; int mid = ( l + r ) / 2 ; return __gcd ( query ( l , mid , l1 , r1 , 2 * ind + 1 ) , query ( mid + 1 , r , l1 , r1 , 2 * ind + 2 ) ) ; } static int findLen ( int [ ] arr , int n ) { build ( 0 , n - 1 , 0 , arr ) ; int i = 0 , j = 0 ; int ans = int . MaxValue ; while ( i < n ) { while ( j < n && query ( 0 , n - 1 , i , j , 0 ) != 1 ) j ++ ; if ( j == n ) break ; ans = Math . Min ( ( j - i + 1 ) , ans ) ; i ++ ; j = Math . Max ( j , i ) ; } if ( ans == int . MaxValue ) return - 1 ; else return ans ; } static int __gcd ( int a , int b ) { return b == 0 ? a : __gcd ( b , a % b ) ; } public static void Main ( ) { int [ ] arr = { 2 , 2 , 2 } ; int n = arr . Length ; Console . WriteLine ( findLen ( arr , n ) ) ; } }

Index/key variables: ind, l
Accumulator variables: i, j
Class/struct names: GFG
C# program:
using System ; class GFG { static void findGrid ( int n ) { int [ , ] arr = new int [ n , n ] ; int x = 0 ; for ( int i = 0 ; i < n / 4 ; i ++ ) { for ( int j = 0 ; j < n / 4 ; j ++ ) { for ( int k = 0 ; k < 4 ; k ++ ) { for ( int l = 0 ; l < 4 ; l ++ ) { arr [ i * 4 + k , j * 4 + l ] = x ; x ++ ; } } } } for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < n ; j ++ ) { Console . Write ( arr [ i , j ] + " ▁ " ) ; } Console . WriteLine ( " ▁ " ) ; } } public static void Main ( String [ ] args ) { int n = 4 ; findGrid ( n ) ; } }

Accumulator variables: i, j, k, l, x
Iterator variables: i, j, k, l
Class/struct names: GFG