dhyuti-n/xlcost-variable-roles huggingface dataset:
C# program:
using System ; using System . Collections . Generic ; class GFG { static Dictionary < int , int > getFrequencyMap ( int [ ] arr ) { Dictionary < int , int > hashMap = new Dictionary < int , int > ( ) ; for ( int i = 0 ; i < arr . Length ; i ++ ) { if ( hashMap . ContainsKey ( arr [ i ] ) ) { hashMap [ arr [ i ] ] = hashMap [ arr [ i ] ] + 1 ; } else { hashMap . Add ( arr [ i ] , 1 ) ; } } return hashMap ; } static bool hasDigit ( Dictionary < int , int > hashMap , int digit ) { if ( hashMap . ContainsKey ( digit ) && hashMap [ digit ] > 0 ) { hashMap [ digit ] = hashMap [ digit ] - 1 ; return true ; } return false ; } static String getMaxTime ( int [ ] arr ) { Dictionary < int , int > hashMap = getFrequencyMap ( arr ) ; int i ; bool flag ; String time = " " ; flag = false ; for ( i = 2 ; i >= 0 ; i -- ) { if ( hasDigit ( hashMap , i ) ) { flag = true ; time += i ; break ; } } if ( ! flag ) { return " - 1" ; } flag = false ; if ( time [ 0 ] == '2' ) { for ( i = 3 ; i >= 0 ; i -- ) { if ( hasDigit ( hashMap , i ) ) { flag = true ; time += i ; break ; } } } else { for ( i = 9 ; i >= 0 ; i -- ) { if ( hasDigit ( hashMap , i ) ) { flag = true ; time += i ; break ; } } } if ( ! flag ) { return " - 1" ; } time += " : " ; flag = false ; for ( i = 5 ; i >= 0 ; i -- ) { if ( hasDigit ( hashMap , i ) ) { flag = true ; time += i ; break ; } } if ( ! flag ) { return " - 1" ; } flag = false ; for ( i = 9 ; i >= 0 ; i -- ) { if ( hasDigit ( hashMap , i ) ) { flag = true ; time += i ; break ; } } if ( ! flag ) { return " - 1" ; } return time ; } public static void Main ( String [ ] args ) { int [ ] arr = { 0 , 0 , 0 , 9 } ; Console . WriteLine ( getMaxTime ( arr ) ) ; } }

Index/key variables: digit, i
Accumulator variables: i, time
Iterator variables: i
Boolean variables: flag
Class/struct names: GFG
C# program:
using System ; using System . Collections . Generic ; class GFG { static String smallestFreq ( String S1 , String S2 ) { Dictionary < String , int > banned = new Dictionary < String , int > ( ) ; for ( int i = 0 ; i < S2 . Length ; i ++ ) { String s = " " ; while ( i < S2 . Length && S2 [ i ] != ' ▁ ' ) s += S2 [ i ++ ] ; if ( banned . ContainsKey ( s ) ) { var val = banned [ s ] ; banned . Remove ( s ) ; banned . Add ( s , val + 1 ) ; } else { banned . Add ( s , 1 ) ; } } Dictionary < String , int > result = new Dictionary < String , int > ( ) ; String ans = " " ; int freq = 0 ; for ( int i = 0 ; i < S1 . Length ; i ++ ) { String s = " " ; while ( i < S1 . Length && S1 [ i ] != ' ▁ ' ) s += S1 [ i ++ ] ; if ( ! banned . ContainsKey ( s ) ) { if ( result . ContainsKey ( s ) ) { var val = result [ s ] ; result . Remove ( s ) ; result . Add ( s , val + 1 ) ; } else { result . Add ( s , 1 ) ; } if ( result [ s ] > freq || ( result [ s ] == freq && s . CompareTo ( ans ) < 0 ) ) { ans = s ; freq = result [ s ] ; } } } return ans ; } public static void Main ( String [ ] args ) { String S1 = " geeks ▁ for ▁ geeks ▁ is ▁ best ▁ place ▁ to ▁ learn " ; String S2 = " bad ▁ place " ; Console . WriteLine ( smallestFreq ( S1 , S2 ) ) ; } }

Index/key variables: i, s
Accumulator variables: i, s
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { public static int replace ( string A , string B ) { int n = A . Length , m = B . Length ; int count = 0 , i , j ; for ( i = 0 ; i < n ; i ++ ) { for ( j = 0 ; j < m ; j ++ ) { if ( i + j >= n ) { break ; } else if ( A [ i + j ] != B [ j ] ) { break ; } } if ( j == m ) { count ++ ; i += m - 1 ; } } return count ; } public static void Main ( string [ ] args ) { string str1 = " aaaaaaaa " ; string str2 = " aaa " ; Console . WriteLine ( replace ( str1 , str2 ) ) ; } }

Index/key variables: j
Accumulator variables: count, i, j
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; class GFG { static int isSubstring ( string s1 , string s2 ) { int M = s1 . Length ; int N = s2 . Length ; for ( int i = 0 ; i <= N - M ; i ++ ) { int j ; for ( j = 0 ; j < M ; j ++ ) if ( s2 [ i + j ] != s1 [ j ] ) break ; if ( j == M ) return i ; } return - 1 ; } public static void Main ( ) { string s1 = " for " ; string s2 = " geeksforgeeks " ; int res = isSubstring ( s1 , s2 ) ; if ( res == - 1 ) Console . Write ( " Not ▁ present " ) ; else Console . Write ( " Present ▁ at ▁ index ▁ " + res ) ; } }

Index/key variables: j
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; class GFG { static void split ( string str ) { int len = str . Length ; if ( len == 1 ) { Console . WriteLine ( " Not ▁ Possible " ) ; return ; } string s1 = " " , s2 = " " ; long num1 , num2 ; for ( int i = 0 ; i < len / 2 ; i ++ ) { int flag = 0 ; s1 = str . Substring ( 0 , i + 1 ) ; num1 = Convert . ToInt64 ( ( s1 ) ) ; num2 = num1 + 1 ; s2 = num2 . ToString ( ) ; int k = i + 1 ; while ( flag == 0 ) { int l = s2 . Length ; if ( k + l > len ) { flag = 1 ; break ; } if ( ( str . Substring ( k , l ) . Equals ( s2 ) ) ) { flag = 0 ; num2 ++ ; k = k + l ; if ( k == len ) break ; s2 = num2 . ToString ( ) ; l = s2 . Length ; if ( k + 1 > len ) { flag = 1 ; break ; } } else flag = 1 ; } if ( flag == 0 ) { Console . WriteLine ( " Possible " + " ▁ " + s1 ) ; break ; } else if ( flag == 1 && i > len / 2 - 1 ) { Console . WriteLine ( " Not ▁ Possible " ) ; break ; } } } static void Main ( ) { string str = "99100" ; split ( str ) ; } }

Accumulator variables: i, num2
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static void KMP ( int m , int n , String str2 , String str1 ) { int pos = 0 , len = 0 ; int [ ] p = new int [ m + 1 ] ; int k = 0 ; char [ ] ch1 = str1 . ToCharArray ( ) ; char [ ] ch2 = str2 . ToCharArray ( ) ; for ( int i = 2 ; i <= n ; i ++ ) { while ( k > 0 && ch1 [ k ] != ch1 [ i - 1 ] ) k = p [ k ] ; if ( ch1 [ k ] == ch1 [ i - 1 ] ) ++ k ; p [ i ] = k ; } for ( int j = 0 , i = 0 ; i < m ; i ++ ) { while ( j > 0 && j < n && ch1 [ j ] != ch2 [ i ] ) j = p [ j ] ; if ( j < n && ch1 [ j ] == ch2 [ i ] ) j ++ ; if ( j > len ) { len = j ; pos = i - j + 1 ; } } Console . WriteLine ( " Shift ▁ = ▁ " + pos ) ; Console . WriteLine ( " Prefix ▁ = ▁ " + str1 . Substring ( 0 , len ) ) ; } public static void Main ( String [ ] args ) { String str1 = " geeksforgeeks " ; String str2 = " forgeeksgeeks " ; int n = str1 . Length ; str2 = str2 + str2 ; KMP ( 2 * n , n , str2 , str1 ) ; } }

Index/key variables: i, j, k
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; class GFG { static int patternCount ( String str ) { char last = str [ 0 ] ; int i = 1 , counter = 0 ; while ( i < str . Length ) { if ( str [ i ] == '0' && last == '1' ) { while ( str [ i ] == '0' ) i ++ ; if ( str [ i ] == '1' ) counter ++ ; } last = str [ i ] ; i ++ ; } return counter ; } public static void Main ( ) { String str = "1001ab010abc01001" ; Console . Write ( patternCount ( str ) ) ; } }

Index/key variables: i
Accumulator variables: counter, i
Class/struct names: GFG
C# program:
using System ; class GFG { static void preprocess_strong_suffix ( int [ ] shift , int [ ] bpos , char [ ] pat , int m ) { int i = m , j = m + 1 ; bpos [ i ] = j ; while ( i > 0 ) { while ( j <= m && pat [ i - 1 ] != pat [ j - 1 ] ) { if ( shift [ j ] == 0 ) shift [ j ] = j - i ; j = bpos [ j ] ; } i -- ; j -- ; bpos [ i ] = j ; } } static void preprocess_case2 ( int [ ] shift , int [ ] bpos , char [ ] pat , int m ) { int i , j ; j = bpos [ 0 ] ; for ( i = 0 ; i <= m ; i ++ ) { if ( shift [ i ] == 0 ) shift [ i ] = j ; if ( i == j ) j = bpos [ j ] ; } } static void search ( char [ ] text , char [ ] pat ) { int s = 0 , j ; int m = pat . Length ; int n = text . Length ; int [ ] bpos = new int [ m + 1 ] ; int [ ] shift = new int [ m + 1 ] ; for ( int i = 0 ; i < m + 1 ; i ++ ) shift [ i ] = 0 ; preprocess_strong_suffix ( shift , bpos , pat , m ) ; preprocess_case2 ( shift , bpos , pat , m ) ; while ( s <= n - m ) { j = m - 1 ; while ( j >= 0 && pat [ j ] == text [ s + j ] ) j -- ; if ( j < 0 ) { Console . Write ( " pattern ▁ occurs ▁ at ▁ shift ▁ = ▁ { 0 } STRNEWLINE " , s ) ; s += shift [ 0 ] ; } else s += shift [ j + 1 ] ; } } public static void Main ( String [ ] args ) { char [ ] text = " ABAAAABAACD " . ToCharArray ( ) ; char [ ] pat = " ABA " . ToCharArray ( ) ; search ( text , pat ) ; } }

Index/key variables: i, j
Accumulator variables: i, j, s
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static int maxPrefix ( String s , String t ) { int count = 0 ; for ( int i = 0 ; i < t . Length ; i ++ ) { if ( count == s . Length ) break ; if ( t [ i ] == s [ count ] ) count ++ ; } return count ; } public static void Main ( ) { String S = " digger " ; String T = " biggerdiagram " ; Console . Write ( maxPrefix ( S , T ) ) ; } }

Index/key variables: count, i
Accumulator variables: count, i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static void translate ( char [ ] str ) { for ( int i = 1 ; i < str . Length ; i ++ ) { if ( str [ i - 1 ] == ' A ' && str [ i ] == ' B ' ) { str [ i - 1 ] = ' C ' ; int j ; for ( j = i ; j < str . Length - 1 ; j ++ ) str [ j ] = str [ j + 1 ] ; str [ j ] = ' ▁ ' ; } } return ; } public static void Main ( ) { String st = " helloABworldABGfG " ; char [ ] str = st . ToCharArray ( ) ; translate ( str ) ; Console . WriteLine ( " The ▁ modified ▁ string ▁ is ▁ : " ) ; Console . Write ( str ) ; } }

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; class GFG { static readonly int ROW = 3 ; static readonly int COL = 5 ; static bool isvalid ( int row , int col , int prevRow , int prevCol ) { return ( row >= 0 ) && ( row < ROW ) && ( col >= 0 ) && ( col < COL ) && ! ( row == prevRow && col == prevCol ) ; } static int [ ] rowNum = { - 1 , - 1 , - 1 , 0 , 0 , 1 , 1 , 1 } ; static int [ ] colNum = { - 1 , 0 , 1 , - 1 , 1 , - 1 , 0 , 1 } ; static void DFS ( char [ , ] mat , int row , int col , int prevRow , int prevCol , char [ ] word , String path , int index , int n ) { if ( index > n mat [ row , col ] != word [ index ] ) return ; path += ( word [ index ] ) + " ( " + String . Join ( " " , row ) + " , ▁ " + String . Join ( " " , col ) + " ) ▁ " ; if ( index == n ) { Console . Write ( path + " STRNEWLINE " ) ; return ; } for ( int k = 0 ; k < 8 ; ++ k ) if ( isvalid ( row + rowNum [ k ] , col + colNum [ k ] , prevRow , prevCol ) ) DFS ( mat , row + rowNum [ k ] , col + colNum [ k ] , row , col , word , path , index + 1 , n ) ; } static void findWords ( char [ , ] mat , char [ ] word , int n ) { for ( int i = 0 ; i < ROW ; ++ i ) for ( int j = 0 ; j < COL ; ++ j ) if ( mat [ i , j ] == word [ 0 ] ) DFS ( mat , i , j , - 1 , - 1 , word , " " , 0 , n ) ; } public static void Main ( String [ ] args ) { char [ , ] mat = { { ' B ' , ' N ' , ' E ' , ' Y ' , ' S ' } , { ' H ' , ' E ' , ' D ' , ' E ' , ' S ' } , { ' S ' , ' G ' , ' N ' , ' D ' , ' E ' } } ; char [ ] word = " DES " . ToCharArray ( ) ; findWords ( mat , word , word . Length - 1 ) ; } }

Index/key variables: index, k
Accumulator variables: path
Iterator variables: i, j, k
Class/struct names: GFG
C# program:
using System ; public class index { static int max = 0 ; static String ans1 = " " ; static void calculate ( String ans ) { int [ ] dp = new int [ 26 ] ; for ( int i = 0 ; i < ans . Length ; ++ i ) { dp [ ( int ) ans [ i ] - ( int ) ' A ' ] ++ ; } for ( int i = 0 ; i < dp . Length ; ++ i ) { if ( dp [ i ] % 2 == 1 ) { return ; } } if ( max < ans . Length ) { max = ans . Length ; ans1 = ans ; } } static void longestString ( String [ ] arr , int index , String str ) { if ( index == arr . Length ) { return ; } longestString ( arr , index + 1 , str ) ; str += arr [ index ] ; calculate ( str ) ; longestString ( arr , index + 1 , str ) ; } public static void Main ( ) { String [ ] A = { " ABAB " , " ABF " , " CDA " , " AD " , " CCC " } ; longestString ( A , 0 , " " ) ; Console . WriteLine ( ans1 + " ▁ " + ans1 . Length ) ; } }

Index/key variables: i, index
Accumulator variables: str
Iterator variables: i
Class/struct names: index
C# program:
using System ; public class GFG { public static String generateNumber ( string number ) { int temp = 0 , adding_number = 0 ; string result = " " ; int len = number . Length ; for ( int i = len - 1 ; i >= 0 ; i -- ) { int digit = ( int ) number [ i ] - ( int ) '0' ; if ( temp % 2 == 0 ) { adding_number += 1 ; digit += adding_number ; if ( digit >= 10 ) { digit %= 9 ; if ( digit == 0 ) digit = 9 ; } } result = digit + result ; temp += 1 ; } return result ; } public static void Main ( string [ ] args ) { string S = "1345" ; Console . WriteLine ( generateNumber ( S ) ) ; } }

Index/key variables: i
Accumulator variables: adding_number, digit, i, temp
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static int findTheSum ( string str ) { string alpha = " " ; for ( int i = 0 ; i < str . Length ; i ++ ) { if ( ( str [ i ] >= ' A ' && str [ i ] <= ' Z ' ) || ( str [ i ] >= ' a ' && str [ i ] <= ' z ' ) ) alpha += ( str [ i ] ) ; } int score = 0 , n = 0 ; for ( int i = 0 ; i < alpha . Length ; i ++ ) { if ( alpha [ i ] >= ' A ' && alpha [ i ] <= ' Z ' ) score += alpha [ i ] - ' A ' + 1 ; else score += alpha [ i ] - ' a ' + 1 ; } while ( score > 0 n > 9 ) { if ( score == 0 ) { score = n ; n = 0 ; } n += score % 10 ; score /= 10 ; } return n ; } public static void Main ( ) { string S = " GeeksforGeeks " ; Console . WriteLine ( findTheSum ( S ) ) ; } }

Index/key variables: i
Accumulator variables: alpha, i, n, score
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static int Find ( int [ ] parent , int a ) { return parent [ a ] = ( parent [ a ] == a ? a : Find ( parent , parent [ a ] ) ) ; } static void Union ( int [ ] parent , int [ ] rank , int a , int b ) { a = Find ( parent , a ) ; b = Find ( parent , b ) ; if ( rank [ a ] == rank [ b ] ) rank [ a ] ++ ; if ( rank [ a ] > rank [ b ] ) parent [ b ] = a ; else parent [ a ] = b ; } static void numOfDistinctStrings ( string [ ] arr , int N ) { int [ ] parent = new int [ ( 27 ) ] ; int [ ] rank = new int [ ( 27 ) ] ; for ( int j = 0 ; j < 27 ; j ++ ) { parent [ j ] = j ; } bool [ ] total = new bool [ 26 ] ; bool [ ] current = new bool [ 26 ] ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < 26 ; j ++ ) { current [ j ] = false ; } foreach ( char ch in arr [ i ] ) { current [ ch - ' a ' ] = true ; } for ( int j = 0 ; j < 26 ; j ++ ) { if ( current [ j ] ) { total [ j ] = true ; Union ( parent , rank , arr [ i ] [ 0 ] - ' a ' , j ) ; } } } int distCount = 0 ; for ( int i = 0 ; i < 26 ; i ++ ) { if ( total [ i ] && Find ( parent , i ) == i ) { distCount ++ ; } } Console . WriteLine ( distCount ) ; } public static void Main ( ) { string [ ] arr = { " a " , " ab " , " b " , " d " } ; int N = arr . Length ; numOfDistinctStrings ( arr , N ) ; } }

Index/key variables: a, b, i, j
Accumulator variables: distCount, i, j
Iterator variables: ch, i, j
Class/struct names: GFG
C# program:
using System ; class GFG { static int minSwaps ( String s ) { int ones = 0 , zeros = 0 ; int N = s . Length ; for ( int i = 0 ; i < N ; i ++ ) { if ( s [ i ] == '1' ) ones ++ ; else zeros ++ ; } if ( ( N % 2 == 0 && ones != zeros ) || ( N % 2 == 1 && Math . Abs ( ones - zeros ) != 1 ) ) { return - 1 ; } int ans_1 = 0 ; int j = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( s [ i ] == '1' ) { ans_1 += Math . Abs ( j - i ) ; j += 2 ; } } int ans_0 = 0 ; int k = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( s [ i ] == '0' ) { ans_0 += Math . Abs ( k - i ) ; k += 2 ; } } if ( N % 2 == 0 ) return Math . Min ( ans_1 , ans_0 ) ; else { if ( ones > zeros ) return ans_1 ; else return ans_0 ; } } public static void Main ( ) { String S = "110100" ; Console . WriteLine ( minSwaps ( S ) ) ; } }

Index/key variables: i
Accumulator variables: ans_0, ans_1, i, j, k, ones, zeros
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; using System . Collections . Generic ; class GFG { static List < string > TotalPossibleJumps ( int N ) { if ( ( N - 1 ) == 0 ) { List < string > newvec = new List < string > ( ) ; newvec . Add ( " " ) ; return newvec ; } else { if ( N < 0 ) { List < string > newvec = new List < string > ( ) ; return newvec ; } } List < string > jump1 = TotalPossibleJumps ( N - 1 ) ; List < string > jump2 = TotalPossibleJumps ( N - 2 ) ; List < string > totaljumps = new List < string > ( ) ; foreach ( string s in jump1 ) { totaljumps . Add ( "1" + s ) ; } foreach ( string s in jump2 ) { totaljumps . Add ( "2" + s ) ; } return totaljumps ; } public static void Main ( ) { int N = 3 ; List < string > Ans = TotalPossibleJumps ( N ) ; foreach ( string it in Ans ) Console . WriteLine ( it ) ; } }

Iterator variables: it, s
Class/struct names: GFG
C# program:
using System ; class GFG { static string findString ( string [ ] arr , int N ) { string ans = " " ; for ( int i = 0 ; i < N ; i ++ ) { ans += arr [ i ] [ i ] == '0' ? '1' : '0' ; } return ans ; } public static void Main ( String [ ] args ) { string [ ] arr = { "111" , "011" , "001" } ; int N = arr . Length ; Console . WriteLine ( findString ( arr , N ) ) ; } }

Index/key variables: i
Accumulator variables: ans, i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static void commonSubstring ( string s ) { int n = s . Length ; int i = 0 ; int j = n - 1 ; string ans = " " ; while ( j >= 0 ) { if ( s [ i ] == s [ j ] ) { ans += s [ i ] ; i ++ ; j -- ; } else { break ; } } if ( ans . Length == 0 ) Console . WriteLine ( " False " ) ; else { Console . WriteLine ( " True ▁ " ) ; Console . WriteLine ( ans ) ; } } public static void Main ( ) { string S = " abca " ; commonSubstring ( S ) ; } }

Index/key variables: i, j
Accumulator variables: ans, i, j
Class/struct names: GFG
C# program:
using System ; class GFG { static void findMinimumSubsequence ( string S ) { bool flag = false ; string dummy = " " ; for ( int j = 0 ; j < S . Length ; j ++ ) { if ( S [ j ] != '2' && S [ j ] != '3' && S [ j ] != '5' && S [ j ] != '7' ) { Console . WriteLine ( 1 ) ; flag = true ; break ; } } if ( ! flag ) { for ( int j = 0 ; j < S . Length - 1 ; j ++ ) { for ( int j1 = j + 1 ; j1 < S . Length ; j1 ++ ) { dummy = S [ j ] . ToString ( ) + S [ j1 ] . ToString ( ) ; if ( dummy != "23" && dummy != "37" && dummy != "53" && dummy != "73" ) { Console . WriteLine ( 2 ) ; } if ( flag == true ) break ; else flag = true ; } if ( flag == true ) break ; } } if ( flag == false ) { if ( S . Length >= 3 ) { Console . WriteLine ( 3 ) ; } else { Console . WriteLine ( - 1 ) ; } } } public static void Main ( ) { string S = "237" ; findMinimumSubsequence ( S ) ; } }

Index/key variables: j, j1
Accumulator variables: j, j1
Iterator variables: j, j1
Boolean variables: flag
Class/struct names: GFG
C# program:
using System ; using System . Collections . Generic ; class GFG { static int [ , ] dp = new int [ 505 , 505 ] ; static int [ , ] choose = new int [ 502 , 502 ] ; static int calc ( int l , int r , string s ) { if ( Math . Abs ( r - l ) % 2 == 0 ) { return 0 ; } if ( l > r ) { return dp [ l , r ] = 1 ; } if ( dp [ l , r ] != - 1 ) { return dp [ l , r ] ; } if ( ( r - l ) == 1 ) { if ( s [ l ] == s [ r ] ) { dp [ l , r ] = 1 ; } else { dp [ l , r ] = 0 ; } return dp [ l , r ] ; } int ans = 0 ; for ( int k = l + 1 ; k <= r ; k += 2 ) { int temp = 1 ; if ( s [ l ] == s [ k ] ) { temp = calc ( l + 1 , k - 1 , s ) * calc ( k + 1 , r , s ) * choose [ ( r - l + 1 ) / 2 , ( r - k ) / 2 ] ; ans += temp ; } } return dp [ l , r ] = ans ; } static int waysToClearString ( string S ) { for ( int i = 0 ; i < 505 ; i ++ ) { for ( int j = 0 ; j < 505 ; j ++ ) dp [ i , j ] = - 1 ; } int n = S . Length ; choose [ 0 , 0 ] = 1 ; for ( int i = 1 ; i <= n / 2 ; ++ i ) { choose [ i , 0 ] = 1 ; for ( int j = 1 ; j <= i ; ++ j ) { choose [ i , j ] = ( choose [ i - 1 , j ] + choose [ i - 1 , j - 1 ] ) ; } } return calc ( 0 , n - 1 , S ) ; } public static void Main ( ) { string S = " aabccb " ; Console . Write ( waysToClearString ( S ) ) ; } }

Index/key variables: k, l, r
Accumulator variables: ans, i, j, k
Iterator variables: i, j, k
Class/struct names: GFG
C# program:
using System ; using System . Collections . Generic ; class GFG { static void findSubsequence ( string str ) { int n = str . Length ; char [ ] res = new char [ n ] ; for ( int i = 0 ; i < n ; i ++ ) res [ i ] = '0' ; for ( int pos = 0 ; pos <= 9 ; pos ++ ) { char lst1 = '0' ; bool flag = true ; char lst2 = ( char ) ( pos + '0' ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( lst2 <= str [ i ] ) { res [ i ] = '2' ; lst2 = str [ i ] ; } else if ( lst1 <= str [ i ] ) { res [ i ] = '1' ; lst1 = str [ i ] ; } else flag = false ; } if ( lst1 > pos + '0' ) flag = false ; if ( flag ) { string S1 = " " ; string S2 = " " ; for ( int i = 0 ; i < n ; i ++ ) { if ( res [ i ] == '1' ) { S1 += str [ i ] ; } else { S2 += str [ i ] ; } } Console . WriteLine ( S1 + ' ▁ ' + S2 ) ; return ; } } Console . Write ( " - 1" ) ; } public static void Main ( ) { string S = "040425524644" ; findSubsequence ( S ) ; S = "123456789" ; findSubsequence ( S ) ; } }

Index/key variables: i, n
Accumulator variables: S1, S2, i, pos
Iterator variables: i, pos
Boolean variables: flag
Class/struct names: GFG
C# program:
using System ; class GFG { static String ans , s ; static int K ; static void getString ( int curlen , int N , int [ ] prod ) { if ( curlen == N ) { K -- ; if ( K == 0 ) ans = s ; return ; } char ch ; int ok , t , i ; for ( ch = '2' ; ch <= '9' ; ch ++ ) { s += ch ; ok = 1 ; t = 1 ; for ( i = curlen ; i >= 0 && s . Length > i ; i -- ) { t *= s [ i ] - 48 ; if ( prod [ t ] != 0 ) ok = 0 ; prod [ t ] ++ ; } if ( ok != 0 ) getString ( curlen + 1 , N , prod ) ; t = 1 ; for ( i = curlen ; i >= 0 && s . Length > i ; i -- ) { t *= s [ i ] - 48 ; prod [ t ] -- ; } if ( s . Length > 0 ) s = s . Substring ( 0 , s . Length - 1 ) ; } } static String kthValidString ( int N ) { String s = " " ; if ( N > 10 ) { return " - 1" ; } if ( N == 1 ) { if ( K > 10 ) { return " - 1" ; } s = " " ; K -- ; s += ( K + '0' ) ; return s ; } ans = " - 1" ; s = " " ; int [ ] prod = new int [ 10005 ] ; getString ( 0 , N , prod ) ; return ans ; } public static void Main ( String [ ] args ) { int N = 3 ; K = 4 ; Console . Write ( kthValidString ( N ) ) ; } }

Index/key variables: i, t
Accumulator variables: K, ch, i, s, t
Iterator variables: ch, i
Class/struct names: GFG
C# program:
using System ; class GFG { static int BalancedStringBySwapping ( String s ) { int unbalancedPair = 0 ; for ( int i = 0 ; i < s . Length ; ++ i ) { if ( unbalancedPair > 0 && s [ i ] == ' ] ' ) { -- unbalancedPair ; } else if ( s [ i ] == ' [ ' ) { ++ unbalancedPair ; } } return ( unbalancedPair + 1 ) / 2 ; } public static void Main ( String [ ] args ) { String s = " ] ] ] [ [ [ " ; Console . Write ( BalancedStringBySwapping ( s ) ) ; } }

Index/key variables: i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static int lengthNPalindrome ( int N , int K ) { int half = N / 2 ; if ( N % 2 == 1 ) { half += 1 ; } int ans = 1 ; for ( int i = 1 ; i <= half ; i ++ ) { ans *= K ; K -- ; } return ans ; } static int palindromicStrings ( int N , int K ) { if ( N == 1 ) { return K ; } if ( N == 2 ) { return 2 * K ; } int ans = 0 ; ans += ( 2 * K ) ; for ( int i = 3 ; i <= N ; i ++ ) { ans += lengthNPalindrome ( i , K ) ; } return ans ; } public static void Main ( String [ ] args ) { int N = 4 , K = 3 ; Console . Write ( palindromicStrings ( N , K ) ) ; } }

Accumulator variables: K, ans, half, i
Iterator variables: i
Class/struct names: GFG