dhyuti-n/xlcost-variable-roles huggingface dataset:
C# program:
using System ; class GFG { static void generateArray ( int n , int k ) { int [ ] array = new int [ k ] ; int remaining = n - ( k * ( k + 1 ) / 2 ) ; if ( remaining < 0 ) Console . Write ( " NO " ) ; int right_most = remaining % k ; int high = ( int ) Math . Ceiling ( remaining / ( k * 1.0 ) ) ; int low = ( int ) Math . Floor ( remaining / ( k * 1.0 ) ) ; for ( int i = k - right_most ; i < k ; i ++ ) array [ i ] = high ; for ( int i = 0 ; i < ( k - right_most ) ; i ++ ) array [ i ] = low ; for ( int i = 0 ; i < k ; i ++ ) array [ i ] += i + 1 ; if ( k - 1 != remaining k == 1 ) { foreach ( int u in array ) Console . Write ( u + " ▁ " ) ; } else if ( k == 2 k == 3 ) Console . Write ( " - 1 STRNEWLINE " ) ; else { array [ 1 ] -= 1 ; array [ k - 1 ] += 1 ; foreach ( int u in array ) Console . Write ( u + " ▁ " ) ; } } public static void Main ( String [ ] args ) { int n = 26 , k = 6 ; generateArray ( n , k ) ; } }

Index/key variables: i, k
Accumulator variables: i
Iterator variables: i, u
Class/struct names: GFG
C# program:
using System ; class GFG { static String get_maximum ( char [ ] s , int [ ] a ) { int n = s . Length ; for ( int i = 0 ; i < n ; i ++ ) { if ( s [ i ] - '0' < a [ s [ i ] - '0' ] ) { int j = i ; while ( j < n && ( s [ j ] - '0' <= a [ s [ j ] - '0' ] ) ) { s [ j ] = ( char ) ( '0' + a [ s [ j ] - '0' ] ) ; j ++ ; } return String . Join ( " " , s ) ; } } return String . Join ( " " , s ) ; } public static void Main ( String [ ] args ) { String s = "1337" ; int [ ] a = { 0 , 1 , 2 , 5 , 4 , 6 , 6 , 3 , 1 , 9 } ; Console . WriteLine ( get_maximum ( s . ToCharArray ( ) , a ) ) ; } }

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GfG { static int countSteps ( int n ) { int steps = 0 ; while ( n > 0 ) { int largest = ( int ) Math . Sqrt ( n ) ; n -= ( largest * largest ) ; steps ++ ; } return steps ; } public static void Main ( ) { int n = 85 ; Console . WriteLine ( countSteps ( n ) ) ; } }

Accumulator variables: n, steps
Class/struct names: GfG
C# program:
using System ; using System . Linq ; class GFG { static int sumArr ( int [ ] arr , int n ) { int sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) sum += arr [ i ] ; return sum ; } static int maxSum ( int [ ] arr , int n , int k ) { Array . Sort ( arr ) ; int i = 0 ; while ( i < n && k > 0 && arr [ i ] < 0 ) { arr [ i ] *= - 1 ; k -- ; i ++ ; } if ( k % 2 == 1 ) { int min = 0 ; for ( i = 1 ; i < n ; i ++ ) if ( arr [ min ] > arr [ i ] ) min = i ; arr [ min ] *= - 1 ; } return sumArr ( arr , n ) ; } static void Main ( ) { int [ ] arr = { - 5 , 4 , 1 , 3 , 2 } ; int n = arr . Length ; int k = 4 ; Console . WriteLine ( maxSum ( arr , n , k ) ) ; } }

Index/key variables: i, min
Accumulator variables: i, k, sum
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; using System . Collections . Generic ; class GFG { static int [ ] par ; static int [ ] rank ; static int find ( int x ) { if ( par [ x ] != x ) par [ x ] = find ( par [ x ] ) ; return par [ x ] ; } static void union ( int u , int v ) { int x = find ( u ) ; int y = find ( v ) ; if ( x == y ) return ; if ( rank [ x ] > rank [ y ] ) par [ y ] = x ; else if ( rank [ x ] < rank [ y ] ) par [ x ] = y ; else { par [ x ] = y ; rank [ y ] ++ ; } } static void findSpanningTree ( int [ ] deg , int n , int m , List < int > [ ] g ) { par = new int [ n + 1 ] ; rank = new int [ n + 1 ] ; for ( int i = 1 ; i <= n ; i ++ ) par [ i ] = i ; int max = 1 ; for ( int i = 2 ; i <= n ; i ++ ) if ( deg [ i ] > deg [ max ] ) max = i ; foreach ( int v in g [ max ] ) { Console . WriteLine ( max + " ▁ " + v ) ; union ( max , v ) ; } for ( int u = 1 ; u <= n ; u ++ ) { foreach ( int v in g [ u ] ) { int x = find ( u ) ; int y = find ( v ) ; if ( x == y ) continue ; union ( x , y ) ; Console . WriteLine ( u + " ▁ " + v ) ; } } } public static void Main ( String [ ] args ) { int n = 5 ; int m = 5 ; List < int > [ ] g = new List < int > [ n + 1 ] ; for ( int i = 1 ; i <= n ; i ++ ) g [ i ] = new List < int > ( ) ; int [ ] deg = new int [ n + 1 ] ; g [ 1 ] . Add ( 2 ) ; g [ 2 ] . Add ( 1 ) ; deg [ 1 ] ++ ; deg [ 2 ] ++ ; g [ 1 ] . Add ( 5 ) ; g [ 5 ] . Add ( 1 ) ; deg [ 1 ] ++ ; deg [ 5 ] ++ ; g [ 2 ] . Add ( 3 ) ; g [ 3 ] . Add ( 2 ) ; deg [ 2 ] ++ ; deg [ 3 ] ++ ; g [ 5 ] . Add ( 3 ) ; g [ 3 ] . Add ( 5 ) ; deg [ 3 ] ++ ; deg [ 5 ] ++ ; g [ 3 ] . Add ( 4 ) ; g [ 4 ] . Add ( 3 ) ; deg [ 3 ] ++ ; deg [ 4 ] ++ ; findSpanningTree ( deg , n , m , g ) ; } }

Index/key variables: i, max, u, x, y
Accumulator variables: i, u
Iterator variables: i, u, v
Class/struct names: GFG
C# program:
using System ; class GFG { static int Maxsum ( int c1 , int c2 , int c3 , int c4 ) { int sum = 0 ; int two34 = Math . Min ( c2 , Math . Min ( c3 , c4 ) ) ; sum = two34 * 234 ; c2 -= two34 ; sum += Math . Min ( c2 , c1 ) * 12 ; return sum ; } public static void Main ( ) { int c1 = 5 , c2 = 2 , c3 = 3 , c4 = 4 ; Console . WriteLine ( Maxsum ( c1 , c2 , c3 , c4 ) ) ; } }

Accumulator variables: c2, sum
Class/struct names: GFG
C# program:
using System ; class GFG { static void printArray ( int N , int [ ] arr ) { for ( int i = 0 ; i < N ; i ++ ) Console . Write ( arr [ i ] + " ▁ " ) ; Console . WriteLine ( ) ; } static void replacedArray ( int N , int [ ] arr ) { int pos_sum , neg_sum , i , diff ; pos_sum = 0 ; neg_sum = 0 ; for ( i = N - 1 ; i >= 0 ; i -- ) { diff = Math . Abs ( pos_sum ) - Math . Abs ( neg_sum ) ; if ( arr [ i ] > 0 ) pos_sum += arr [ i ] ; else neg_sum += arr [ i ] ; arr [ i ] = Math . Abs ( diff ) ; } } public static void Main ( ) { int N = 5 ; int [ ] arr = { 1 , - 1 , 2 , 3 , - 2 } ; replacedArray ( N , arr ) ; printArray ( N , arr ) ; N = 6 ; int [ ] arr1 = { - 3 , - 4 , - 2 , 5 , 1 , - 2 } ; replacedArray ( N , arr1 ) ; printArray ( N , arr1 ) ; } }

Index/key variables: i
Accumulator variables: i, neg_sum, pos_sum
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static int findCountOfPairs ( int a , int b , int n ) { int ans = 0 ; ans += n * ( a / n ) * ( b / n ) ; ans += ( a / n ) * ( b % n ) ; ans += ( a % n ) * ( b / n ) ; ans += ( ( a % n ) + ( b % n ) ) / n ; return ans ; } static public void Main ( ) { int a = 5 , b = 13 , n = 3 ; Console . WriteLine ( findCountOfPairs ( a , b , n ) ) ; } }

Accumulator variables: ans
Class/struct names: GFG
C# program:
using System ; class GFG { static void findArray ( int N , int P ) { int ans = ( P * ( P + 1 ) ) / 2 + ( N - P ) ; int [ ] arr = new int [ N + 1 ] ; for ( int i = 1 ; i <= P ; i ++ ) { arr [ i ] = i ; } for ( int i = P + 1 ; i <= N ; i ++ ) { arr [ i ] = 1 ; } Console . Write ( " The ▁ Minimum ▁ Possible ▁ Sum ▁ is : ▁ " + ans + " STRNEWLINE " ) ; Console . Write ( " The ▁ Array ▁ Elements ▁ are : ▁ STRNEWLINE " ) ; for ( int i = 1 ; i <= N ; i ++ ) { Console . Write ( arr [ i ] + " ▁ " ) ; } } public static void Main ( ) { int N = 5 , P = 3 ; findArray ( N , P ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static void findIntersection ( int [ , ] intervals , int N ) { int l = intervals [ 0 , 0 ] ; int r = intervals [ 0 , 1 ] ; for ( int i = 1 ; i < N ; i ++ ) { if ( intervals [ i , 0 ] > r intervals [ i , 1 ] < l ) { Console . WriteLine ( - 1 ) ; return ; } else { l = Math . Max ( l , intervals [ i , 0 ] ) ; r = Math . Min ( r , intervals [ i , 1 ] ) ; } } Console . WriteLine ( " [ " + l + " , ▁ " + r + " ] " ) ; } public static void Main ( ) { int [ , ] intervals = { { 1 , 6 } , { 2 , 8 } , { 3 , 10 } , { 5 , 8 } } ; int N = intervals . GetLength ( 0 ) ; findIntersection ( intervals , N ) ; } }

Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static int cmp ( int a , int b ) { if ( a > b ) return 1 ; else if ( a == b ) return 0 ; else return - 1 ; } static int maxSubarraySize ( int [ ] arr , int n ) { int ans = 1 ; int anchor = 0 ; for ( int i = 1 ; i < n ; i ++ ) { int c = cmp ( arr [ i - 1 ] , arr [ i ] ) ; if ( c == 0 ) anchor = i ; else if ( i == n - 1 || c * cmp ( arr [ i ] , arr [ i + 1 ] ) != - 1 ) { ans = Math . Max ( ans , i - anchor + 1 ) ; anchor = i ; } } return ans ; } static void Main ( ) { int [ ] arr = { 9 , 4 , 2 , 10 , 7 , 8 , 8 , 1 , 9 } ; int n = arr . Length ; Console . WriteLine ( maxSubarraySize ( arr , n ) ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static int maxSubStrings ( String s , int k ) { int maxSubStr = 0 , n = s . Length ; for ( int c = 0 ; c < 26 ; c ++ ) { char ch = ( char ) ( ( int ) ' a ' + c ) ; int curr = 0 ; for ( int i = 0 ; i <= n - k ; i ++ ) { if ( s [ i ] != ch ) continue ; int cnt = 0 ; while ( i < n && s [ i ] == ch && cnt != k ) { i ++ ; cnt ++ ; } i -- ; if ( cnt == k ) curr ++ ; } maxSubStr = Math . Max ( maxSubStr , curr ) ; } return maxSubStr ; } public static void Main ( ) { string s = " aaacaabbaa " ; int k = 2 ; Console . WriteLine ( maxSubStrings ( s , k ) ) ; } }

Index/key variables: i
Accumulator variables: c, cnt, curr, i
Iterator variables: c, i
Class/struct names: GFG
C# program:
using System ; class GFG { static int ValidPairs ( int [ ] arr , int n ) { int [ ] count = new int [ 121 ] ; for ( int i = 0 ; i < n ; i ++ ) count [ arr [ i ] ] += 1 ; int ans = 0 ; for ( int i = 0 ; i < n ; i ++ ) for ( int j = 0 ; j < n ; j ++ ) { if ( arr [ i ] < arr [ j ] ) continue ; if ( Math . Abs ( arr [ i ] - arr [ j ] ) % 2 == 1 ) continue ; ans += count [ arr [ i ] ] * count [ arr [ j ] ] ; if ( arr [ i ] == arr [ j ] ) ans -= count [ arr [ i ] ] ; } return ans ; } public static void Main ( ) { int [ ] arr = new int [ ] { 16 , 17 , 18 } ; int n = arr . Length ; Console . WriteLine ( ValidPairs ( arr , n ) ) ; } }

Index/key variables: i, j
Accumulator variables: ans, i, j
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System . IO ; using System ; class GFG { static void check_distribution ( int n , int k , int [ ] age , int [ ] candy ) { int mxage = age [ 0 ] ; for ( int i = 0 ; i < age . Length ; i ++ ) { if ( mxage < age [ i ] ) { mxage = age [ i ] ; } } int mxcandy = candy [ 0 ] ; for ( int i = 0 ; i < candy . Length ; i ++ ) { if ( mxcandy < candy [ i ] ) { mxcandy = candy [ i ] ; } } int [ ] fr1 = new int [ mxage + 1 ] ; Array . Fill ( fr1 , 0 ) ; int [ ] fr2 = new int [ mxcandy + 1 ] ; Array . Fill ( fr2 , 0 ) ; for ( int j = 0 ; j < n ; j ++ ) { fr1 [ age [ j ] ] += 1 ; } for ( int j = 0 ; j < k ; j ++ ) { fr2 [ candy [ j ] ] += 1 ; } k = 0 ; bool Tf = true ; for ( int j = 0 ; j < mxage ; j ++ ) { if ( fr1 [ j ] == 0 ) { continue ; } bool flag = false ; while ( k < mxcandy ) { if ( fr1 [ j ] <= fr2 [ k ] ) { flag = true ; break ; } k += 1 ; } k = k + 1 ; if ( flag == false ) { Tf = false ; break ; } } if ( Tf ) { Console . WriteLine ( " Yes " ) ; } else { Console . WriteLine ( " No " ) ; } } static void Main ( ) { int [ ] age = { 5 , 15 , 10 } ; int [ ] candy = { 2 , 2 , 2 , 3 , 3 , 4 } ; int n = age . Length ; int k = candy . Length ; check_distribution ( n , k , age , candy ) ; } }

Index/key variables: i, j, k
Accumulator variables: i, j, k
Iterator variables: i, j
Boolean variables: Tf, flag
Class/struct names: GFG
C# program:
using System ; class GFG { static bool checkPalindrome ( String s ) { String x = reverse ( s ) ; return x . Equals ( s ) ; } static String findStringB ( String A ) { String B = reverse ( A ) ; B = B + A ; if ( checkPalindrome ( A ) ) { return A ; } return B ; } static String reverse ( String input ) { char [ ] temparray = input . ToCharArray ( ) ; int left , right = 0 ; right = temparray . Length - 1 ; for ( left = 0 ; left < right ; left ++ , right -- ) { char temp = temparray [ left ] ; temparray [ left ] = temparray [ right ] ; temparray [ right ] = temp ; } return String . Join ( " " , temparray ) ; } public static void Main ( String [ ] args ) { String A = " ab " ; Console . WriteLine ( findStringB ( A ) ) ; } }

Index/key variables: left, right
Accumulator variables: left, right
Iterator variables: left
Class/struct names: GFG
C# program:
using System ; class GFG { static int minChanges ( int [ ] A , int n ) { int cnt = 0 ; for ( int i = 0 ; i < n - 2 ; ++ i ) { if ( ( i - 1 >= 0 ) && A [ i - 1 ] == 1 && A [ i + 1 ] == 1 && A [ i ] == 0 ) { A [ i + 1 ] = 0 ; cnt ++ ; } } return cnt ; } public static void Main ( ) { int [ ] A = { 1 , 1 , 0 , 1 , 1 , 0 , 1 , 0 , 1 , 0 } ; int n = A . Length ; Console . Write ( minChanges ( A , n ) ) ; } }

Index/key variables: i
Accumulator variables: cnt
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static void completeSequence ( String s ) { int n = s . Length ; int open = 0 , close = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( s [ i ] == ' ( ' ) open ++ ; else close ++ ; if ( close > open ) { Console . Write ( " IMPOSSIBLE " ) ; return ; } } Console . Write ( s ) ; for ( int i = 0 ; i < open - close ; i ++ ) Console . Write ( " ) " ) ; } static void Main ( ) { String s = " ( ( ) ( ( ) ( " ; completeSequence ( s ) ; } }

Index/key variables: i
Accumulator variables: close, i, open
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static void smallestPermute ( int n ) { char [ ] res = new char [ n + 1 ] ; if ( n % 2 == 0 ) { for ( int i = 0 ; i < n ; i ++ ) { if ( i % 2 == 0 ) res [ i ] = ( char ) ( 48 + i + 2 ) ; else res [ i ] = ( char ) ( 48 + i ) ; } } else { for ( int i = 0 ; i < n - 2 ; i ++ ) { if ( i % 2 == 0 ) res [ i ] = ( char ) ( 48 + i + 2 ) ; else res [ i ] = ( char ) ( 48 + i ) ; } res [ n - 1 ] = ( char ) ( 48 + n - 2 ) ; res [ n - 2 ] = ( char ) ( 48 + n ) ; res [ n - 3 ] = ( char ) ( 48 + n - 1 ) ; } res [ n ] = ' \0' ; for ( int i = 0 ; i < n ; i ++ ) { Console . Write ( res [ i ] ) ; } } public static void Main ( ) { int n = 7 ; smallestPermute ( n ) ; } }

Index/key variables: i, n
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static int minInsertions ( int [ ] H , int n , int K ) { int inser = 0 ; for ( int i = 1 ; i < n ; ++ i ) { float diff = Math . Abs ( H [ i ] - H [ i - 1 ] ) ; if ( diff <= K ) continue ; else inser += ( int ) Math . Ceiling ( diff / K ) - 1 ; } return inser ; } static void Main ( ) { int [ ] H = new int [ ] { 2 , 4 , 8 , 16 } ; int K = 3 ; int n = H . Length ; Console . WriteLine ( minInsertions ( H , n , K ) ) ; } }

Index/key variables: i
Accumulator variables: inser
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; public class GFG { static int count_minimum_operations ( long n ) { int count = 0 ; while ( n > 1 ) { if ( n % 3 == 0 ) n /= 3 ; else if ( n % 3 == 1 ) n -- ; else { if ( n == 2 ) n -- ; else n ++ ; } count ++ ; } return count ; } static public void Main ( ) { long n = 4 ; long ans = count_minimum_operations ( n ) ; Console . WriteLine ( ans ) ; } }

Accumulator variables: count, n
Class/struct names: GFG
C# program:
using System ; class GFG { static int count_minimum_operations ( int n ) { if ( n == 2 ) { return 1 ; } else if ( n == 1 ) { return 0 ; } if ( n % 3 == 0 ) { return 1 + count_minimum_operations ( n / 3 ) ; } else if ( n % 3 == 1 ) { return 1 + count_minimum_operations ( n - 1 ) ; } else { return 1 + count_minimum_operations ( n + 1 ) ; } } static void Main ( ) { int n = 4 ; int ans = count_minimum_operations ( n ) ; Console . WriteLine ( ans ) ; } }

Class/struct names: GFG
C# program:
using System ; using System . Collections . Generic ; class GFG { static void maxSum ( int [ ] a , int n ) { List < int > l = new List < int > ( ) ; int s = 0 ; for ( int i = 0 ; i < n ; i ++ ) { s += Math . Abs ( a [ i ] ) ; if ( a [ i ] >= 0 ) continue ; if ( i == 0 ) l . Add ( i + 1 ) ; else { l . Add ( i + 1 ) ; l . Add ( i ) ; } } Console . WriteLine ( s ) ; for ( int i = 0 ; i < l . Count ; i ++ ) Console . Write ( l [ i ] + " ▁ " ) ; } public static void Main ( String [ ] args ) { int n = 4 ; int [ ] a = { 1 , - 2 , - 3 , 4 } ; maxSum ( a , n ) ; } }

Index/key variables: i
Accumulator variables: i, s
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static void LengthLCP ( String x , String y ) { int [ ] fr = new int [ 26 ] ; for ( int i = 0 ; i < b ; i ++ ) { fr [ y [ i ] - 97 ] += 1 ; } int c = 0 ; for ( int i = 0 ; i < a ; i ++ ) { if ( fr [ x [ i ] - 97 ] > 0 ) { c += 1 ; fr [ x [ i ] - 97 ] -= 1 ; } else break ; } Console . Write ( ( c ) ) ; } public static void Main ( ) { String x = " here " , y = " there " ; LengthLCP ( x , y ) ; } }

Index/key variables: i
Accumulator variables: c, i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static void CountPair ( int L , int R ) { int x = ( R - L + 1 ) ; Console . WriteLine ( x / 2 + " STRNEWLINE " ) ; } public static void Main ( ) { int L , R ; L = 1 ; R = 8 ; CountPair ( L , R ) ; } }

Class/struct names: GFG
C# program:
using System ; class GFG { public static int problemsLeft ( int K , int P , int N ) { if ( K <= P ) return 0 ; else return ( ( K - P ) * N ) ; } public static void Main ( ) { int K , P , N ; K = 4 ; P = 1 ; N = 10 ; Console . WriteLine ( problemsLeft ( K , P , N ) ) ; } }

Class/struct names: GFG
C# program:
using System ; class GFG { static int V = 5 ; static int [ ] parent = new int [ V ] ; static int INF = int . MaxValue ; static int find ( int i ) { while ( parent [ i ] != i ) i = parent [ i ] ; return i ; } static void union1 ( int i , int j ) { int a = find ( i ) ; int b = find ( j ) ; parent [ a ] = b ; } static void kruskalMST ( int [ , ] cost ) { for ( int i = 0 ; i < V ; i ++ ) parent [ i ] = i ; int edge_count = 0 ; while ( edge_count < V - 1 ) { int min = INF , a = - 1 , b = - 1 ; for ( int i = 0 ; i < V ; i ++ ) { for ( int j = 0 ; j < V ; j ++ ) { if ( find ( i ) != find ( j ) && cost [ i , j ] < min ) { min = cost [ i , j ] ; a = i ; b = j ; } } } union1 ( a , b ) ; Console . Write ( " Edge ▁ { 0 } : ( { 1 } , ▁ { 2 } ) ▁ cost : { 3 } ▁ STRNEWLINE " , edge_count ++ , a , b , min ) ; mincost += min ; } Console . Write ( " cost = { 0 } " , mincost ) ; } public static void Main ( String [ ] args ) { int [ , ] cost = { { INF , 2 , INF , 6 , INF } , { 2 , INF , 3 , 8 , 5 } , { INF , 3 , INF , INF , 7 } , { 6 , 8 , INF , INF , 9 } , { INF , 5 , 7 , 9 , INF } , } ; kruskalMST ( cost ) ; } }

Index/key variables: V, a, i
Accumulator variables: edge_count, i, j, mincost
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; class GFG { static int results ( int n , int k ) { return ( int ) Math . Round ( Math . Pow ( n , ( 1.0 / Math . Pow ( 2.0 , k ) ) ) ) ; } public static void Main ( ) { int k = 3 , n = 100000000 ; Console . Write ( " Chocolates ▁ left ▁ after ▁ " + k + " ▁ iterations ▁ are ▁ " + results ( n , k ) ) ; } }

Class/struct names: GFG
C# program:
using System ; class GFG { public static int [ ] getSubArray ( int [ ] arr , int n , int K ) { int i = - 1 ; int j = - 1 ; int currSum = 0 ; int [ ] result = { i , j , Math . Abs ( K - Math . Abs ( currSum ) ) } ; for ( i = 0 ; i < n ; i ++ ) { currSum = 0 ; for ( j = i ; j < n ; j ++ ) { currSum += arr [ j ] ; int currDev = Math . Abs ( K - Math . Abs ( currSum ) ) ; if ( currDev < result [ 2 ] ) { result [ 0 ] = i ; result [ 1 ] = j ; result [ 2 ] = currDev ; } if ( currDev == 0 ) return result ; } } return result ; } public static void Main ( string [ ] args ) { int [ ] arr = { 15 , - 3 , 5 , 2 , 7 , 6 , 34 , - 6 } ; int n = arr . Length ; int K = 50 ; int [ ] ans = getSubArray ( arr , n , K ) ; if ( ans [ 0 ] == - 1 ) { Console . Write ( " The ▁ empty ▁ array ▁ " + " shows ▁ minimum ▁ Deviation " ) ; } else { for ( int i = ans [ 0 ] ; i <= ans [ 1 ] ; i ++ ) Console . Write ( arr [ i ] + " ▁ " ) ; } } }

Index/key variables: i, j
Accumulator variables: currSum, i, j
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; class GFG { static void longestSubsequence ( int [ ] a , int n , int [ ] q , int m ) { Array . Sort ( a ) ; int sum = 0 ; int [ ] b = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { sum += a [ i ] ; double av = ( double ) ( sum ) / ( double ) ( i + 1 ) ; b [ i ] = ( ( int ) ( av + 1 ) ) ; } Array . Sort ( b ) ; for ( int i = 0 ; i < m ; i ++ ) { int k = q [ i ] ; int longest = upperBound ( b , 0 , n , k ) ; Console . WriteLine ( " Answer ▁ to ▁ Query " + ( i + 1 ) + " : ▁ " + longest ) ; } } private static int upperBound ( int [ ] a , int low , int high , int element ) { while ( low < high ) { int middle = low + ( high - low ) / 2 ; if ( a [ middle ] > element ) high = middle ; else low = middle + 1 ; } return low ; } static public void Main ( ) { int [ ] a = { 1 , 3 , 2 , 5 , 4 } ; int n = a . Length ; int [ ] q = { 4 , 2 , 1 , 5 } ; int m = q . Length ; longestSubsequence ( a , n , q , m ) ; } }

Index/key variables: i, middle, n
Accumulator variables: i, sum
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static int steps ( int N , int M ) { if ( N == 1 ) return 0 ; return M ; return 2 * M + ( N - 3 ) ; } public static void Main ( ) { int N = 4 , M = 4 ; Console . WriteLine ( steps ( N , M ) ) ; } }

Class/struct names: GFG
C# program:
using System ; using System . Collections . Generic ; class GFG { static int DecreasingArray ( int [ ] a , int n ) { int sum = 0 , dif = 0 ; List < int > pq = new List < int > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( pq . Count > 0 && pq [ 0 ] < a [ i ] ) { dif = a [ i ] - pq [ 0 ] ; sum += dif ; pq . RemoveAt ( 0 ) ; } pq . Add ( a [ i ] ) ; pq . Sort ( ) ; } return sum ; } static void Main ( ) { int [ ] a = { 3 , 1 , 2 , 1 } ; int n = a . Length ; Console . Write ( DecreasingArray ( a , n ) ) ; } }

Index/key variables: i
Accumulator variables: i, sum
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static int solve ( int [ ] a , int [ ] b , int n ) { int i ; int s = 0 ; for ( i = 0 ; i < n ; i ++ ) s += ( a [ i ] + b [ i ] ) ; if ( n == 1 ) return a [ 0 ] + b [ 0 ] ; if ( s % n != 0 ) return - 1 ; int x = s / n ; for ( i = 0 ; i < n ; i ++ ) { if ( a [ i ] > x ) return - 1 ; if ( i > 0 ) { a [ i ] += b [ i - 1 ] ; b [ i - 1 ] = 0 ; } if ( a [ i ] == x ) continue ; int y = a [ i ] + b [ i ] ; if ( i + 1 < n ) y += b [ i + 1 ] ; if ( y == x ) { a [ i ] = y ; b [ i ] = 0 ; continue ; } if ( a [ i ] + b [ i ] == x ) { a [ i ] += b [ i ] ; b [ i ] = 0 ; continue ; } if ( i + 1 < n && a [ i ] + b [ i + 1 ] == x ) { a [ i ] += b [ i + 1 ] ; b [ i + 1 ] = 0 ; continue ; } return - 1 ; } for ( i = 0 ; i < n ; i ++ ) if ( b [ i ] != 0 ) return - 1 ; return x ; } public static void Main ( String [ ] args ) { int [ ] a = { 6 , 14 , 21 , 1 } ; int [ ] b = { 15 , 7 , 10 , 10 } ; int n = a . Length ; Console . WriteLine ( solve ( a , b , n ) ) ; } }

Index/key variables: i
Accumulator variables: i, s, y
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static void survival ( int S , int N , int M ) { if ( ( ( N * 6 ) < ( M * 7 ) && S > 6 ) M > N ) Console . Write ( " No " ) ; else { int days = ( M * S ) / N ; if ( ( ( M * S ) % N ) != 0 ) days ++ ; Console . WriteLine ( " Yes ▁ " + days ) ; } } public static void Main ( ) { int S = 10 , N = 16 , M = 2 ; survival ( S , N , M ) ; } }

Accumulator variables: days
Class/struct names: GFG
C# program:
using System ; class GFG { static void subsequence ( char [ ] s , char [ ] t , int n , int k ) { int last = 0 , cnt = 0 , new_last = 0 , size = 0 ; for ( char ch = ' z ' ; ch >= ' a ' ; ch -- ) { cnt = 0 ; for ( int i = last ; i < n ; i ++ ) { if ( s [ i ] == ch ) cnt ++ ; } if ( cnt >= k ) { for ( int i = last ; i < n ; i ++ ) { if ( s [ i ] == ch ) { t [ size ++ ] = ch ; new_last = i ; } } last = new_last ; } } t [ size ] = ' \0' ; } public static void Main ( ) { char [ ] s = { ' b ' , ' a ' , ' n ' , ' a ' , ' n ' , ' a ' } ; int n = s . Length ; int k = 2 ; char [ ] t = new char [ n ] ; subsequence ( s , t , n - 1 , k ) ; for ( int i = 0 ; i < t . Length ; i ++ ) if ( t [ i ] != 0 ) Console . Write ( t [ i ] ) ; } }

Index/key variables: i, n, size
Accumulator variables: ch, cnt, i, size
Iterator variables: ch, i
Class/struct names: GFG