dhyuti-n/xlcost-variable-roles huggingface dataset:
C++ program:
#include <iostream>
using namespace std ; string decToHexa ( int n ) { char hexaDeciNum [ 2 ] ; int i = 0 ; while ( n != 0 ) { int temp = 0 ; temp = n % 16 ; if ( temp < 10 ) { hexaDeciNum [ i ] = temp + 48 ; i ++ ; } else { hexaDeciNum [ i ] = temp + 55 ; i ++ ; } n = n / 16 ; } string hexCode = " " ; if ( i == 2 ) { hexCode . push_back ( hexaDeciNum [ 0 ] ) ; hexCode . push_back ( hexaDeciNum [ 1 ] ) ; } else if ( i == 1 ) { hexCode = "0" ; hexCode . push_back ( hexaDeciNum [ 0 ] ) ; } else if ( i == 0 ) hexCode = "00" ; return hexCode ; } string convertRGBtoHex ( int R , int G , int B ) { if ( ( R >= 0 && R <= 255 ) && ( G >= 0 && G <= 255 ) && ( B >= 0 && B <= 255 ) ) { string hexCode = " # " ; hexCode += decToHexa ( R ) ; hexCode += decToHexa ( G ) ; hexCode += decToHexa ( B ) ; return hexCode ; } else return " - 1" ; } int main ( ) { int R = 0 , G = 0 , B = 0 ; cout << convertRGBtoHex ( R , G , B ) << endl ; R = 255 , G = 255 , B = 255 ; cout << convertRGBtoHex ( R , G , B ) << endl ; R = 25 , G = 56 , B = 123 ; cout << convertRGBtoHex ( R , G , B ) << endl ; R = 2 , G = 3 , B = 4 ; cout << convertRGBtoHex ( R , G , B ) << endl ; R = 255 , G = 255 , B = 256 ; cout << convertRGBtoHex ( R , G , B ) << endl ; return 0 ; }

Index/key variables: i
Accumulator variables: hexCode, i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void q1 ( string , int ) ; void q2 ( string , int ) ; void q3 ( string , int ) ; void q4 ( string , int ) ; void q1 ( string s , int i ) { if ( i == s . length ( ) ) { cout << " Yes ▁ STRNEWLINE " ; return ; } if ( s [ i ] == ' a ' ) q1 ( s , i + 1 ) ; else q2 ( s , i + 1 ) ; } void q2 ( string s , int i ) { if ( i == s . length ( ) ) { cout << " No ▁ STRNEWLINE " ; return ; } if ( s [ i ] == ' a ' ) q1 ( s , i + 1 ) ; else q2 ( s , i + 1 ) ; } void q3 ( string s , int i ) { if ( i == s . length ( ) ) { cout << " Yes ▁ STRNEWLINE " ; return ; } if ( s [ i ] == ' a ' ) q4 ( s , i + 1 ) ; else q3 ( s , i + 1 ) ; } void q4 ( string s , int i ) { if ( i == s . length ( ) ) { cout << " No ▁ STRNEWLINE " ; return ; } if ( s [ i ] == ' a ' ) q4 ( s , i + 1 ) ; else q3 ( s , i + 1 ) ; } void q0 ( string s , int i ) { if ( i == s . length ( ) ) { cout << " No ▁ STRNEWLINE " ; return ; } if ( s [ i ] == ' a ' ) q1 ( s , i + 1 ) ; else q3 ( s , i + 1 ) ; } int main ( ) { string s = " abbaabb " ; q0 ( s , 0 ) ; }

Index/key variables: i
Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; void prefix ( string str ) { int k = 1 , j ; int n = str . length ( ) ; vector < int > g ; int flag = 0 ; for ( int i = 1 ; i < n ; i ++ ) { if ( str [ i ] == str [ 0 ] ) { g . push_back ( i ) ; flag = 1 ; } } if ( flag == 0 ) { cout << str << endl ; } else { int len = g . size ( ) ; while ( k < g [ 0 ] ) { int cnt = 0 ; for ( j = 0 ; j < len ; j ++ ) { if ( str [ g [ j ] + k ] == str [ k ] ) { cnt ++ ; } } if ( cnt == len ) { k ++ ; } else { break ; } } for ( int i = 0 ; i < k ; i ++ ) { cout << str [ i ] ; } cout << endl ; } } int main ( ) { string str = " abcab " ; prefix ( str ) ; return 0 ; }

Index/key variables: i, j, k
Accumulator variables: cnt, i, j, k, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; void printPermutation ( int N , int K ) { vector < int > res ; int l = 1 , r = N , flag = 0 ; for ( int i = 0 ; i < K ; i ++ ) { if ( ! flag ) { res . push_back ( l ) ; l ++ ; } else { res . push_back ( r ) ; r -- ; } flag ^= 1 ; } if ( ! flag ) { for ( int i = r ; i >= l ; i -- ) res . push_back ( i ) ; } else { for ( int i = l ; i <= r ; i ++ ) res . push_back ( i ) ; } for ( auto i : res ) cout << i << " ▁ " ; } int main ( ) { int N = 10 , K = 4 ; printPermutation ( N , K ) ; return 0 ; }

Accumulator variables: flag, i, l, r, stdc
Iterator variables: i
C++ program:
#include <iostream>
using namespace std ; int fact ( int N ) { int i , product = 1 ; for ( i = 1 ; i <= N ; i ++ ) product = product * i ; return product ; } int nthTerm ( int N ) { return ( N * N ) * fact ( N ) ; } int main ( ) { int N = 4 ; cout << nthTerm ( N ) ; return 0 ; }

Accumulator variables: i
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define d  256 
void search ( char pat [ ] , char txt [ ] , int q ) { int M = strlen ( pat ) ; int N = strlen ( txt ) ; int i , j ; int h = 1 ; for ( i = 0 ; i < M - 1 ; i ++ ) h = ( h * d ) % q ; for ( i = 0 ; i < M ; i ++ ) { p = ( d * p + pat [ i ] ) % q ; t = ( d * t + txt [ i ] ) % q ; } for ( i = 0 ; i <= N - M ; i ++ ) { if ( p == t ) { bool flag = true ; for ( j = 0 ; j < M ; j ++ ) { if ( txt [ i + j ] != pat [ j ] ) { flag = false ; break ; } if ( flag ) cout << i << " ▁ " ; } if ( j == M ) cout << " Pattern ▁ found ▁ at ▁ index ▁ " << i << endl ; } if ( i < N - M ) { t = ( d * ( t - txt [ i ] * h ) + txt [ i + M ] ) % q ; if ( t < 0 ) t = ( t + q ) ; } } } int main ( ) { char txt [ ] = " GEEKS ▁ FOR ▁ GEEKS " ; char pat [ ] = " GEEK " ; int q = 101 ; search ( pat , txt , q ) ; return 0 ; }

Index/key variables: i, j
Accumulator variables: i, j, stdc
Iterator variables: i, j
Boolean variables: flag
C++ program:
#include " bits / stdc + + . h "
using namespace std ; #define MAXN  100001
int spf [ MAXN ] ; void sieve ( ) { spf [ 1 ] = 1 ; for ( int i = 2 ; i < MAXN ; i ++ ) spf [ i ] = i ; for ( int i = 4 ; i < MAXN ; i += 2 ) spf [ i ] = 2 ; for ( int i = 3 ; i * i < MAXN ; i ++ ) { if ( spf [ i ] == i ) { for ( int j = i * i ; j < MAXN ; j += i ) { if ( spf [ j ] == j ) spf [ j ] = i ; } } } } vector < int > getFactorization ( int x ) { vector < int > ret ; while ( x != 1 ) { ret . push_back ( spf [ x ] ) ; int value = spf [ x ] ; while ( x % value == 0 ) x = x / value ; } return ret ; } string flipString ( string S , int arr [ ] , int M ) { sieve ( ) ; int frequency [ MAXN ] = { 0 } ; for ( int i = 0 ; i < M ; i ++ ) { vector < int > primeFactors = getFactorization ( arr [ i ] ) ; for ( auto & factors : primeFactors ) { frequency [ factors ] ++ ; frequency [ factors ] %= 2 ; } } int N = S . length ( ) ; for ( int i = 0 ; i < MAXN ; i ++ ) { if ( frequency [ i ] & 1 ) { for ( int j = i ; j <= N ; j += i ) { S [ j - 1 ] = ( S [ j - 1 ] == '1' ? '0' : '1' ) ; } } } return S ; } int main ( ) { string S = "000000" ; int arr [ ] = { 2 , 4 , 6 } ; int M = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << flipString ( S , arr , M ) ; return 0 ; }

Index/key variables: MAXN, factors, i, j, x
Accumulator variables: i, j
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; void isOnesGreater ( string S , int N ) { int cnt0 = 0 ; int cnt1 = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( S [ i ] == '1' ) cnt1 ++ ; else cnt0 ++ ; } for ( int i = 0 ; i < N ; i ++ ) { if ( S [ i ] == '1' ) { if ( i > 0 && S [ i - 1 ] == '0' ) { S [ i - 1 ] = ' _ ' ; cnt0 -- ; } else if ( i < N && S [ i + 1 ] == '0' ) { S [ i + 1 ] = ' _ ' ; cnt0 -- ; } } } if ( cnt1 > cnt0 ) { cout << " Yes " ; } else { cout << " No " ; } } int main ( ) { string S = "01" ; int N = S . length ( ) ; isOnesGreater ( S , N ) ; return 0 ; }

Index/key variables: i
Accumulator variables: cnt0, cnt1, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void minOperation ( string S , int K , int N ) { int min = 0 ; int i ; for ( i = 0 ; i < N ; i ++ ) { if ( S [ i ] == '0' && i + K <= N ) { for ( int j = i ; j < i + K ; j ++ ) { if ( S [ j ] == '1' ) S [ j ] = '0' ; else S [ j ] = '1' ; } min ++ ; } } for ( i = 0 ; i < N ; i ++ ) { if ( S [ i ] == '0' ) break ; } if ( i == N ) cout << min ; else cout << -1 ; } int main ( ) { string S = "00010110" ; int K = 3 ; int N = S . length ( ) ; minOperation ( S , K , N ) ; return 0 ; }

Index/key variables: i, j
Accumulator variables: i, j, min, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool validInsertionstring ( string S1 , string S2 ) { int N = S1 . length ( ) ; int M = S2 . length ( ) ; stack < char > st ; for ( int i = 0 ; i < N ; i ++ ) { st . push ( S1 [ i ] ) ; if ( S1 [ i ] == S2 [ M - 1 ] ) { int idx = M - 1 ; while ( idx >= 0 ) { if ( st . empty ( ) ) { return false ; } char c = st . top ( ) ; st . pop ( ) ; if ( c != S2 [ idx ] ) { return false ; } idx -- ; } } } if ( ! st . empty ( ) ) { return false ; } else { return true ; } } int main ( ) { string S1 = " aabb " ; string S2 = " ab " ; validInsertionstring ( S1 , S2 ) ? cout << " Yes STRNEWLINE " : cout << " No STRNEWLINE " ; }

Index/key variables: i, idx
Accumulator variables: i, idx, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define MAX  256
bool can_form_palindrome ( int arr [ ] , int n ) { string str = " " ; for ( int i = 0 ; i < n ; i ++ ) { str += arr [ i ] ; } int freq [ MAX ] = { 0 } ; for ( int i = 0 ; str [ i ] ; i ++ ) { freq [ str [ i ] ] ++ ; } int count = 0 ; for ( int i = 0 ; i < MAX ; i ++ ) { if ( freq [ i ] & 1 ) { count ++ ; } if ( count > 1 ) { return false ; } } return true ; } int main ( ) { int arr [ ] = { 1 , 2 , 3 , 1 , 2 } ; int n = sizeof ( arr ) / sizeof ( int ) ; can_form_palindrome ( arr , n ) ? cout << " YES " : cout << " NO " ; return 0 ; }

Index/key variables: MAX, i
Accumulator variables: count, i, stdc, str
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int minimumFlips ( string s ) { int n = s . size ( ) ; int cnt0 = count ( s . begin ( ) , s . end ( ) , '0' ) ; int cnt1 = 0 ; int res = n - cnt0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( s [ i ] == '0' ) { cnt0 -= 1 ; } else if ( s [ i ] == '1' ) { res = min ( res , cnt1 + cnt0 ) ; cnt1 ++ ; } } return res ; } int main ( ) { string S = "000110" ; cout << minimumFlips ( S ) ; return 0 ; }

Index/key variables: i
Accumulator variables: cnt0, cnt1, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; set < string > presentSubstring ( string s , int k ) { set < string > st ; int n = s . length ( ) ; for ( int i = 0 ; i < n ; i ++ ) { string s1 = " " ; for ( int j = 0 ; j < k && i + j < n ; j ++ ) { s1 . push_back ( s [ i + j ] ) ; st . insert ( s1 ) ; } } return st ; } string smallestSubstring ( string s , int k ) { set < string > st ; st = presentSubstring ( s , k ) ; int index ; for ( int len = 1 ; len <= k ; len ++ ) { string t ( len , ' a ' ) ; while ( true ) { if ( st . count ( t ) == 0 ) { return t ; } index = len - 1 ; while ( index >= 0 && t [ index ] == ' z ' ) { t [ index ] = ' a ' ; index -- ; } if ( index >= 0 ) t [ index ] ++ ; else break ; } } return " - 1" ; } int main ( ) { string s = " sdhaacbdefghijklmnopqrstuvwxyz " ; int K = 3 ; cout << smallestSubstring ( s , K ) << endl ; return 0 ; }

Index/key variables: index
Accumulator variables: i, index, j, len, stdc
Iterator variables: i, j, len
C++ program:
#include <bits/stdc++.h>
using namespace std ; int maximumK ( string & S ) { int N = S . length ( ) ; int ans = N ; int flag = 0 ; for ( int i = 0 ; i < N - 1 ; i ++ ) { if ( S [ i ] != S [ i + 1 ] ) { flag = 1 ; ans = min ( ans , max ( i + 1 , N - i - 1 ) ) ; } } if ( flag == 0 ) return 0 ; return ans ; } int main ( ) { string S = "010" ; cout << maximumK ( S ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; string checkhappy ( vector < string > arr , char K , int N ) { set < string > visited ; for ( string s : arr ) { if ( s [ 0 ] == K ) if ( visited . find ( s . substr ( 1 ) ) != visited . end ( ) ) return " Yes " ; else if ( visited . find ( ( K + s ) ) != visited . end ( ) ) return " Yes " ; visited . insert ( s ) ; } return " No " ; } int main ( ) { vector < string > arr = { " a " , " ! ▁ a " , " b " , " ! ▁ c " , " d " , " ! ▁ d " } ; char K = ' ! ' ; int N = arr . size ( ) ; cout << checkhappy ( arr , K , N ) << endl ; return 0 ; }

Accumulator variables: stdc
Iterator variables: s
C++ program:
#include <bits/stdc++.h>
using namespace std ; void minimumTimeToConvertString ( string S , int N ) { int upper = 0 , lower = 0 ; for ( int i = 0 ; i < N ; i ++ ) { char c = S [ i ] ; if ( isupper ( c ) ) { upper ++ ; } else { lower ++ ; } } int moves = 0 ; if ( upper > N / 2 ) { int i = 0 ; while ( upper > N / 2 && i < N ) { if ( isupper ( S [ i ] ) ) { S [ i ] += 32 ; moves ++ ; upper -- ; lower ++ ; } i ++ ; } } else if ( lower > N / 2 ) { int i = 0 ; while ( lower > N / 2 && i < N ) { if ( islower ( S [ i ] ) ) { S [ i ] -= 32 ; moves ++ ; upper ++ ; lower -- ; } i ++ ; } } cout << moves << endl ; cout << S << endl ; } int main ( ) { string S = " AbcdEf " ; int N = S . length ( ) ; minimumTimeToConvertString ( S , N ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, lower, moves, stdc, upper
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void zigzag ( string s , int rows ) { int interval = 2 * rows - 2 ; for ( int i = 0 ; i < rows ; i ++ ) { int step = interval - 2 * i ; for ( int j = i ; j < s . length ( ) ; j = j + interval ) { cout << s [ j ] ; if ( step > 0 && step < interval && step + j < s . length ( ) ) { for ( int k = 0 ; k < ( interval - rows - i ) ; k ++ ) cout << " ▁ " ; cout << s [ j + step ] ; for ( int k = 0 ; k < i - 1 ; k ++ ) cout << " ▁ " ; } else { for ( int k = 0 ; k < ( interval - rows ) ; k ++ ) cout << " ▁ " ; } } cout << endl ; } } int main ( ) { string s = "123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefgh " " ijklmnopqrstuvwxyz " ; int rows = 9 ; zigzag ( s , rows ) ; }

Index/key variables: j
Accumulator variables: i, k, stdc
Iterator variables: i, j, k
C++ program:
#include <bits/stdc++.h>
using namespace std ; int subString ( string s , int n ) { map < int , int > hash ; hash [ 0 ] = 1 ; int pre = 0 ; int count = 0 ; for ( int i = 0 ; i < n ; i ++ ) { pre ^= ( 1 << int ( s [ i ] ) - 97 ) ; count += hash [ pre ] ; hash [ pre ] = hash [ pre ] + 1 ; } return count ; } int main ( ) { string S = " abbaa " ; int N = S . length ( ) ; cout << ( subString ( S , N ) ) ; }

Index/key variables: i, pre
Accumulator variables: count, i, pre, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void atleastkDistinctChars ( string s , int k ) { int n = s . size ( ) ; unordered_map < char , int > mp ; int begin = 0 , end = 0 ; int ans = 0 ; while ( end < n ) { char c = s [ end ] ; mp ++ ; end ++ ; while ( mp . size ( ) >= k ) { char pre = s [ begin ] ; mp [ pre ] -- ; if ( mp [ pre ] == 0 ) { mp . erase ( pre ) ; } ans += s . length ( ) - end + 1 ; begin ++ ; } } cout << ans ; } int main ( ) { string S = " abcca " ; int K = 3 ; atleastkDistinctChars ( S , K ) ; return 0 ; }

Index/key variables: begin, end, pre
Accumulator variables: ans, begin, end, mp, stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; void canSplit ( string & S ) { vector < int > frequency ( 26 , 0 ) ; int cnt_singles = 0 ; int k = 0 ; for ( int i = 0 ; i < S . length ( ) ; i ++ ) frequency [ S [ i ] - ' a ' ] ++ ; int odd = 0 , eve = 0 ; for ( int i = 0 ; i < 26 ; i ++ ) { if ( frequency [ i ] ) { odd += ( frequency [ i ] & 1 ) ; eve += frequency [ i ] / 2 ; } } if ( eve >= odd ) cout << " Yes " ; else cout << " No " ; } int main ( ) { string S = " aaabbbccc " ; canSplit ( S ) ; return 0 ; }

Index/key variables: i
Accumulator variables: eve, i, odd, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int getMaxRepetitions ( string s1 , int n1 , string s2 , int n2 ) { int temp1 [ 26 ] = { 0 } , temp2 [ 26 ] = { 0 } ; for ( char i : s1 ) temp1 [ i - ' a ' ] ++ ; for ( char i : s2 ) temp2 [ i - ' a ' ] ++ ; for ( int i = 0 ; i < 26 ; i ++ ) { if ( temp2 [ i ] > temp1 [ i ] ) return 0 ; } int s1_reps = 0 ; int s2_reps = 0 ; map < int , pair < int , int > > s2_index_to_reps ; s2_index_to_reps [ 0 ] = { 0 , 0 } ; int i = 0 ; int j = 0 ; while ( s1_reps < n1 ) { if ( s1 [ i ] == s2 [ j ] ) j += 1 ; i += 1 ; if ( j == s2 . size ( ) ) { j = 0 ; s2_reps += 1 ; } if ( i == s1 . size ( ) ) { i = 0 ; s1_reps += 1 ; if ( s2_index_to_reps . find ( j ) != s2_index_to_reps . end ( ) ) break ; s2_index_to_reps [ j ] = { s1_reps , s2_reps } ; } } if ( s1_reps == n1 ) return s2_reps / n2 ; int initial_s1_reps = s2_index_to_reps [ j ] . first , initial_s2_reps = s2_index_to_reps [ j ] . second ; int loop_s1_reps = s1_reps - initial_s1_reps ; int loop_s2_reps = s2_reps - initial_s2_reps ; int loops = ( n1 - initial_s1_reps ) ; s2_reps = initial_s2_reps + loops * loop_s2_reps ; s1_reps = initial_s1_reps + loops * loop_s1_reps ; while ( s1_reps < n1 ) { if ( s1 [ i ] == s2 [ j ] ) j += 1 ; i += 1 ; if ( i == s1 . size ( ) ) { i = 0 ; s1_reps += 1 ; } if ( j == s2 . size ( ) ) { j = 0 ; s2_reps += 1 ; } } return s2_reps / n2 ; } int main ( ) { string s1 = " acb " ; int n1 = 4 ; string s2 = " ab " ; int n2 = 2 ; cout << ( getMaxRepetitions ( s1 , n1 , s2 , n2 ) ) ; return 0 ; }

Index/key variables: i, j
Accumulator variables: i, j, s1_reps, s2_reps, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; string removeAdjacent ( string s ) { if ( s . length ( ) == 1 ) return s ; string sb = " " ; for ( int i = 0 ; i < s . length ( ) - 1 ; i ++ ) { char c = s [ i ] ; char d = s [ i + 1 ] ; if ( c != d ) { sb = sb + c ; if ( i == s . length ( ) - 2 ) { sb = sb + d ; } } else { for ( int j = i + 2 ; j < s . length ( ) ; j ++ ) sb = sb + s [ j ] ; return sb ; } } return sb ; } void reduceString ( string s ) { string result = " " ; string pre = s ; while ( true ) { result = removeAdjacent ( pre ) ; if ( result == pre ) break ; pre = result ; } if ( result . length ( ) != 0 ) cout << ( result ) << endl ; else cout << " Empty ▁ String " << endl ; } int main ( ) { string S = " aaabccddd " ; reduceString ( S ) ; return 0 ; }

Index/key variables: i, j
Accumulator variables: i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; int minDeletions ( string str ) { int fre [ 26 ] ; memset ( fre , 0 , sizeof ( fre ) ) ; int n = str . size ( ) ; cout << n ; for ( int i = 0 ; i < n ; i ++ ) { fre [ str [ i ] - ' a ' ] += 1 ; } for ( int i = 0 ; i < n ; i ++ ) { cout << fre [ i ] ; } int count = 0 ; for ( int i = 0 ; i < 26 ; i ++ ) { if ( fre [ i ] % 2 ) { count += 1 ; } } if ( count == 0 count == 1 ) { return 0 ; } else { return count - 1 ; } } int main ( ) { string str = " ababbccca " ; cout << minDeletions ( str ) << endl ; }

Index/key variables: i
Accumulator variables: count, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void scoreOfParentheses ( string s ) { stack < int > stack ; stack . push ( 0 ) ; for ( char c : s ) { if ( c == ' ( ' ) stack . push ( 0 ) ; else { int tmp = stack . top ( ) ; stack . pop ( ) ; int val = 0 ; if ( tmp > 0 ) val = tmp * 2 ; else val = 1 ; stack . top ( ) += val ; } } cout << stack . top ( ) ; } int main ( ) { string S = " ( ( ) ( ( ) ) ) " ; scoreOfParentheses ( S ) ; return 0 ; }

Accumulator variables: stdc
Iterator variables: c
C++ program:
#include <bits/stdc++.h>
using namespace std ; int findSubstringInWraproundString ( string p ) { int ans = 0 ; int curLen = 0 ; int arr [ 26 ] = { 0 } ; for ( int i = 0 ; i < ( int ) p . length ( ) ; i ++ ) { int curr = p [ i ] - ' a ' ; if ( i > 0 && ( p [ i - 1 ] != ( ( curr + 26 - 1 ) % 26 + ' a ' ) ) ) { curLen = 0 ; } curLen ++ ; if ( curLen > arr [ curr ] ) { ans += ( curLen - arr [ curr ] ) ; arr [ curr ] = curLen ; } } cout << ans ; } int main ( ) { string p = " zab " ; findSubstringInWraproundString ( p ) ; return 0 ; }

Index/key variables: curr, i
Accumulator variables: ans, curLen, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int remove ( int N , int digit ) { string strN = to_string ( N ) ; string ans = " " ; for ( char i : strN ) { if ( ( i - '0' ) == digit ) { continue ; } ans += i ; } return stoi ( ans ) ; } void getMin ( vector < int > arr ) { int minSum = INT_MAX ; for ( int i = 0 ; i < 10 ; i ++ ) { int curSum = 0 ; for ( int num : arr ) curSum += remove ( num , i ) ; minSum = min ( minSum , curSum ) ; } cout << minSum ; } int main ( ) { vector < int > arr = { 34 , 23 , 85 , 93 } ; getMin ( arr ) ; return 0 ; }

Accumulator variables: ans, curSum, i, stdc
Iterator variables: i, num
C++ program:
#include <bits/stdc++.h>
using namespace std ; int maxUnique ( string S , set < string > st ) { int mx = 0 ; for ( int i = 1 ; i <= S . length ( ) ; i ++ ) { string tmp = S . substr ( 0 , i ) ; if ( st . find ( tmp ) == st . end ( ) ) { st . insert ( tmp ) ; mx = max ( mx , maxUnique ( S . substr ( i ) , st ) + 1 ) ; st . erase ( tmp ) ; } } return mx ; } int maxUniqueSplit ( string S ) { set < string > st ; return maxUnique ( S , st ) ; } int main ( ) { string S = " ababccc " ; int res = maxUniqueSplit ( S ) ; cout << res ; }

Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void removeValidBracketSequences ( string & str , int N ) { stack < int > A ; stack < int > B ; stack < int > C ; bool vis [ N ] ; memset ( vis , true , sizeof ( vis ) ) ; for ( int i = 0 ; i < N ; i ++ ) { if ( str [ i ] == ' ( ' ) { A . push ( i ) ; } else if ( str [ i ] == ' { ' ) { B . push ( i ) ; } else if ( str [ i ] == ' [ ' ) { C . push ( i ) ; } else if ( str [ i ] == ' ) ' && ! A . empty ( ) ) { vis [ A . top ( ) ] = false ; A . pop ( ) ; vis [ i ] = false ; } else if ( str [ i ] == ' } ' && ! B . empty ( ) ) { vis [ B . top ( ) ] = false ; B . pop ( ) ; vis [ i ] = false ; } else if ( str [ i ] == ' ] ' && ! C . empty ( ) ) { vis [ C . top ( ) ] = false ; C . pop ( ) ; vis [ i ] = false ; } } for ( int i = 0 ; i < N ; ++ i ) { if ( vis [ i ] ) cout << str [ i ] ; } } int main ( ) { string str = " ( ( ) { ( ) ( { } ) " ; int N = str . length ( ) ; removeValidBracketSequences ( str , N ) ; return 0 ; }

Index/key variables: N, i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void update ( int BIT [ 26 ] [ 10005 ] , int idx , int i , int val ) { while ( i < 10005 ) { BIT [ idx ] [ i ] += val ; i = i + ( i & ( - i ) ) ; } } int query ( int BIT [ 26 ] [ 10005 ] , int idx , int i ) { int ans = 0 ; while ( i > 0 ) { ans += BIT [ idx ] [ i ] ; i = i - ( i & ( - i ) ) ; } return ans ; } void maxDiffFreq ( string s , vector < pair < int , int > > queries ) { int BIT [ 26 ] [ 10005 ] ; int n = s . size ( ) ; for ( int i = 0 ; i < n ; i ++ ) { update ( BIT , s [ i ] - ' a ' , i + 1 , 1 ) ; } int Q = queries . size ( ) ; for ( int i = 0 ; i < Q ; ++ i ) { int mx = 0 ; int mn = INT_MAX ; int l = queries [ i ] . first ; int r = queries [ i ] . second ; for ( int j = 0 ; j < 26 ; j ++ ) { int p = query ( BIT , j , r ) ; int q = query ( BIT , j , l - 1 ) ; mx = max ( mx , p - q ) ; if ( p > 0 ) { mn = min ( mn , p - q ) ; } } cout << mx - mn << endl ; } } int main ( ) { string S = " abaabac " ; vector < pair < int , int > > queries = { { 2 , 6 } , { 1 , 7 } } ; maxDiffFreq ( S , queries ) ; }

Index/key variables: i, idx
Accumulator variables: ans, i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; int minOperation ( string arr [ ] , int N ) { int cntMinOP = 0 ; int M = arr [ 0 ] . length ( ) ; int hash [ 256 ] [ M ] ; memset ( hash , 0 , sizeof ( hash ) ) ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < M ; j ++ ) { hash [ arr [ i ] [ j ] ] [ j ] ++ ; } } for ( int i = 0 ; i < M ; i ++ ) { int Sum = 0 ; int Max = 0 ; for ( int j = 0 ; j < 256 ; j ++ ) { Sum += hash [ j ] [ i ] ; Max = max ( Max , hash [ j ] [ i ] ) ; } cntMinOP += ( Sum - Max ) ; } return cntMinOP ; } int main ( ) { string arr [ ] = { " abcd " , " bcde " , " cdef " } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << minOperation ( arr , N ) << " STRNEWLINE " ; }

Index/key variables: M, i, j
Accumulator variables: Sum, cntMinOP, i, j, stdc
Iterator variables: i, j