dhyuti-n/xlcost-variable-roles huggingface dataset:
C++ program:
#include <bits/stdc++.h>
using namespace std ; int getSum ( int n ) { int ans = 0 ; string arr = to_string ( n ) ; for ( int i = 0 ; i < arr . length ( ) ; i ++ ) { ans += int ( arr [ i ] ) ; } return ans ; } void getMax ( int arr [ ] , int n ) { int maxRem0 = 0 ; int rem1 = 0 ; int rem2 = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int digitSum = getSum ( arr [ i ] ) ; if ( digitSum % 3 == 0 ) maxRem0 = max ( maxRem0 , arr [ i ] ) ; else if ( digitSum % 3 == 1 ) rem1 += arr [ i ] ; else rem2 += arr [ i ] ; } cout << ( maxRem0 + max ( rem1 , rem2 ) ) ; } int main ( ) { int arr [ ] = { 23 , 12 , 43 , 3 , 56 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; getMax ( arr , n ) ; }

Index/key variables: i
Accumulator variables: ans, i, rem1, rem2, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int dfs ( vector < pair < int , int > > g [ ] , pair < int , int > disRev [ ] , bool visit [ ] , int u ) { visit [ u ] = true ; int totalRev = 0 ; for ( int i = 0 ; i < g [ u ] . size ( ) ; i ++ ) { int v = g [ u ] [ i ] . first ; if ( ! visit [ v ] ) { disRev [ v ] . first = disRev [ u ] . first + 1 ; disRev [ v ] . second = disRev [ u ] . second ; if ( g [ u ] [ i ] . second ) { disRev [ v ] . second = disRev [ u ] . second + 1 ; totalRev ++ ; } totalRev += dfs ( g , disRev , visit , v ) ; } } return totalRev ; } void printMinEdgeReverseForRootNode ( int edges [ ] [ 2 ] , int e ) { int V = e + 1 ; vector < pair < int , int > > g [ V ] ; pair < int , int > disRev [ V ] ; bool visit [ V ] ; int u , v ; for ( int i = 0 ; i < e ; i ++ ) { u = edges [ i ] [ 0 ] ; v = edges [ i ] [ 1 ] ; g [ u ] . push_back ( make_pair ( v , 0 ) ) ; g [ v ] . push_back ( make_pair ( u , 1 ) ) ; } for ( int i = 0 ; i < V ; i ++ ) { visit [ i ] = false ; disRev [ i ] . first = disRev [ i ] . second = 0 ; } int root = 0 ; int totalRev = dfs ( g , disRev , visit , root ) ; int res = INT_MAX ; for ( int i = 0 ; i < V ; i ++ ) { int edgesToRev = ( totalRev - disRev [ i ] . second ) + ( disRev [ i ] . first - disRev [ i ] . second ) ; if ( edgesToRev < res ) { res = edgesToRev ; root = i ; } } cout << root << " ▁ " << res << endl ; } int main ( ) { int edges [ ] [ 2 ] = { { 0 , 1 } , { 2 , 1 } , { 3 , 2 } , { 3 , 4 } , { 5 , 4 } , { 5 , 6 } , { 7 , 6 } } ; int e = sizeof ( edges ) / sizeof ( edges [ 0 ] ) ; printMinEdgeReverseForRootNode ( edges , e ) ; return 0 ; }

Index/key variables: V, i, u, v
Accumulator variables: i, stdc, totalRev
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void checkString ( string s , int k ) { int n = s . size ( ) ; if ( 2 * k + 1 > n ) { cout << " No " ; return ; } string a = s . substr ( 0 , k ) ; string b = s . substr ( n - k , k ) ; reverse ( b . begin ( ) , b . end ( ) ) ; if ( a == b ) cout << " Yes " ; else cout << " No " ; } int main ( ) { string S = " qwqwq " ; int K = 1 ; checkString ( S , K ) ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <iostream>
using namespace std ; int findMin ( int arr [ ] , int N , int k ) { int pairs = 0 ; for ( int i = 0 ; i < N ; i ++ ) { pairs += arr [ i ] / 2 ; } if ( k > pairs ) return -1 ; else return 2 * k + N - 1 ; } int main ( ) { int arr [ 3 ] = { 4 , 5 , 6 } ; int K = 3 ; cout << findMin ( arr , 3 , K ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, pairs
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int minimumFlips ( int A , int B , int C ) { int res = 0 ; for ( int i = 0 ; i < 32 ; i ++ ) { int x = 0 , y = 0 , z = 0 ; if ( A & ( 1 << i ) ) { x = 1 ; } if ( B & ( 1 << i ) ) { y = 1 ; } if ( C & ( 1 << i ) ) { z = 1 ; } if ( z == 0 ) { if ( x ) { res ++ ; } if ( y ) { res ++ ; } } if ( z == 1 ) { if ( x == 0 && y == 0 ) { res ++ ; } } } return res ; } int main ( ) { int A = 2 , B = 6 , C = 5 ; cout << minimumFlips ( A , B , C ) ; return 0 ; }

Accumulator variables: i, res, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int prefixCount [ 32 ] [ 10000 ] ; void findPrefixCount ( vector < int > arr , int size ) { for ( int i = 0 ; i < 32 ; i ++ ) { prefixCount [ i ] [ 0 ] = ( ( arr [ 0 ] >> i ) & 1 ) ; for ( int j = 1 ; j < size ; j ++ ) { prefixCount [ i ] [ j ] = ( ( arr [ j ] >> i ) & 1 ) ; prefixCount [ i ] [ j ] += prefixCount [ i ] [ j - 1 ] ; } } } void arrayBitwiseAND ( int size ) { int result = 0 ; for ( int i = 0 ; i < 32 ; i ++ ) { int temp = prefixCount [ i ] [ size - 1 ] ; if ( temp == size ) result = ( result | ( 1 << i ) ) ; } cout << result << " ▁ " ; } void applyQuery ( int currentVal , int newVal , int size ) { for ( int i = 0 ; i < 32 ; i ++ ) { int bit1 = ( ( currentVal >> i ) & 1 ) ; int bit2 = ( ( newVal >> i ) & 1 ) ; if ( bit2 > 0 && bit1 == 0 ) prefixCount [ i ] [ size - 1 ] ++ ; else if ( bit1 > 0 && bit2 == 0 ) prefixCount [ i ] [ size - 1 ] -- ; } } void findbitwiseAND ( vector < vector < int > > queries , vector < int > arr , int N , int M ) { findPrefixCount ( arr , N ) ; for ( int i = 0 ; i < M ; i ++ ) { int id = queries [ i ] [ 0 ] ; int newVal = queries [ i ] [ 1 ] ; int currentVal = arr [ id ] ; arr [ id ] = newVal ; applyQuery ( currentVal , newVal , N ) ; arrayBitwiseAND ( N ) ; } } int main ( ) { vector < int > arr { 1 , 2 , 3 , 4 , 5 } ; vector < vector < int > > queries { { 0 , 2 } , { 3 , 3 } , { 4 , 2 } } ; int N = arr . size ( ) ; int M = queries . size ( ) ; findbitwiseAND ( queries , arr , N , M ) ; return 0 ; }

Index/key variables: i, id, j
Accumulator variables: i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; int stepscount ( int a , int b ) { int chanceA = 2 * a - 1 ; int chanceB = 2 * b ; if ( chanceA < chanceB ) { cout << " B " ; } else if ( chanceB < chanceA ) { cout << " A " ; } return 0 ; } int main ( ) { int A = 2 ; int B = 3 ; stepscount ( A , B ) ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; void checkpoint ( int h , int k , int x , int y , int a , int b ) { int p = ( pow ( ( x - h ) , 2 ) / pow ( a , 2 ) ) - ( pow ( ( y - k ) , 2 ) / pow ( b , 2 ) ) ; if ( p > 1 ) { cout << " Outside " ; } else if ( p == 1 ) { cout << " On ▁ the ▁ Hyperbola " ; } else { cout << " Inside " ; } } int main ( ) { int h = 0 , k = 0 , x = 2 ; int y = 1 , a = 4 , b = 5 ; checkpoint ( h , k , x , y , a , b ) ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; void evenXorSubarray ( int arr [ ] , int n ) { int ans = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int XOR = 0 ; for ( int j = i ; j < n ; j ++ ) { XOR = XOR ^ arr [ j ] ; if ( ( XOR & 1 ) == 0 ) ans ++ ; } } cout << ans ; } int main ( ) { int arr [ ] = { 1 , 2 , 3 , 4 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; evenXorSubarray ( arr , N ) ; return 0 ; }

Index/key variables: j
Accumulator variables: ans, i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; void findKthElement ( int N , int K ) { int ans = 0 ; if ( K <= N / 2 ) { ans = K * 2 ; } else { if ( N % 2 == 0 ) { ans = ( K * 2 ) - N - 1 ; } else { ans = ( K * 2 ) - N ; } } cout << ans ; } int main ( ) { int N = 10 , K = 3 ; findKthElement ( N , K ) ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; int makeSumEqual ( vector < int > a , vector < int > b , int K , int M , int N ) { int sum1 = 0 ; int sum2 = 0 ; for ( int el : a ) sum1 += el ; for ( int el : b ) sum2 += el ; int diff = sum1 - sum2 ; int l1 = 0 , r1 = M - 1 ; int l2 = 0 , r2 = N - 1 ; int res = 0 ; sort ( a . begin ( ) , a . end ( ) ) ; sort ( b . begin ( ) , b . end ( ) ) ; while ( l1 <= r1 l2 <= r2 ) { if ( diff == 0 ) { break ; } if ( diff > 0 ) { if ( l2 <= r2 && l1 <= r1 ) { if ( K - b [ l2 ] < a [ r1 ] - 1 ) { int sub = min ( a [ r1 ] - 1 , diff ) ; diff -= sub ; a [ r1 ] -= sub ; r1 -- ; } else { int sub = min ( K - b [ l2 ] , diff ) ; diff -= sub ; b [ l2 ] += sub ; l2 ++ ; } } else if ( l1 <= r1 ) { int sub = min ( a [ r1 ] - 1 , diff ) ; diff -= sub ; a [ r1 ] -= sub ; r1 -- ; } else { int sub = min ( K - b [ l2 ] , diff ) ; diff -= sub ; b [ l2 ] += sub ; l2 ++ ; } } else { if ( l1 <= r1 && l2 <= r2 ) { if ( K - a [ l1 ] < b [ r2 ] - 1 ) { int sub = min ( b [ r2 ] - 1 , -1 * diff ) ; diff += sub ; b [ r2 ] -= sub ; r2 -- ; } else { int sub = min ( K - a [ l1 ] , -1 * diff ) ; diff += sub ; a [ l1 ] -= sub ; l1 ++ ; } } else if ( l2 <= r2 ) { int sub = min ( b [ r2 ] - 1 , -1 * diff ) ; diff += sub ; b [ r2 ] -= sub ; r2 -- ; } else { int sub = min ( K - a [ l1 ] , diff ) ; diff += sub ; a [ l1 ] += sub ; l1 ++ ; } } res ++ ; } if ( diff == 0 ) return res ; else return -1 ; } int main ( ) { vector < int > A = { 1 , 4 , 3 } ; vector < int > B = { 6 , 6 , 6 } ; int M = A . size ( ) ; int N = B . size ( ) ; int K = 6 ; cout << makeSumEqual ( A , B , K , M , N ) ; return 0 ; }

Index/key variables: l1, l2, r1, r2
Accumulator variables: diff, l1, l2, r1, r2, res, stdc, sum1, sum2
Iterator variables: el
C++ program:
#include <iostream>
using namespace std ; void findString ( char S [ ] , int N ) { int strLen = 4 * N ; for ( int i = 1 ; i <= N ; i ++ ) { S [ strLen - 1 ] = '1' ; strLen -= 2 ; } for ( int i = 0 ; i < 4 * N ; i ++ ) { cout << S [ i ] ; } } int main ( ) { int N = 2 ; char S [ 4 * N ] ; for ( int i = 0 ; i < 4 * N ; i ++ ) S [ i ] = '0' ; findString ( S , N ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, strLen
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool isVowel ( char ch ) { if ( ch == ' a ' ch == ' e ' ch == ' i ' ch == ' o ' ch == ' u ' ) return true ; if ( ch == ' A ' ch == ' E ' ch == ' I ' ch == ' O ' ch == ' U ' ) return true ; return false ; } string containsEqualStrings ( string S ) { int totalVowels = 0 ; for ( int i = 0 ; i < S . size ( ) ; i ++ ) { if ( isVowel ( S [ i ] ) ) totalVowels ++ ; } int vowelsTillNow = 0 ; for ( int i = 0 ; i < S . size ( ) ; i ++ ) { if ( isVowel ( S [ i ] ) ) { vowelsTillNow ++ ; totalVowels -- ; if ( vowelsTillNow == totalVowels ) { return " Yes " ; } } } return " No " ; } int main ( ) { string S = " geeks " ; cout << ( containsEqualStrings ( S ) ) ; }

Index/key variables: i
Accumulator variables: i, stdc, totalVowels, vowelsTillNow
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void getMaxSum ( vector < vector < int > > A , int M , int N ) { int sum = 0 ; int negative = 0 ; int minVal = INT_MAX ; for ( int i = 0 ; i < M ; i ++ ) { for ( int j = 0 ; j < N ; j ++ ) { sum += abs ( A [ i ] [ j ] ) ; if ( A [ i ] [ j ] < 0 ) { negative ++ ; } minVal = min ( minVal , abs ( A [ i ] [ j ] ) ) ; } } if ( negative % 2 ) { sum -= 2 * minVal ; } cout << sum ; } int main ( ) { vector < vector < int > > A = { { 4 , -8 , 6 } , { 3 , 7 , 2 } } ; int M = A . size ( ) ; int N = A [ 0 ] . size ( ) ; getMaxSum ( A , M , N ) ; return 0 ; }

Index/key variables: i, j
Accumulator variables: i, j, negative, stdc, sum
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; void areaToPaint ( int N , int W , int L , int Heights [ ] ) { int total = 0 ; for ( int i = 0 ; i < N ; i ++ ) { total += 2 * Heights [ i ] * W ; } total += L * ( Heights [ 0 ] + Heights [ N - 1 ] ) ; for ( int i = 1 ; i < N ; i ++ ) { total += L * abs ( Heights [ i ] - Heights [ i - 1 ] ) ; } cout << total ; } int main ( ) { int N = 7 , W = 1 , L = 1 ; int Heights [ N ] = { 4 , 3 , 1 , 2 , 3 , 4 , 2 } ; areaToPaint ( N , W , L , Heights ) ; }

Index/key variables: N, i
Accumulator variables: i, stdc, total
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; vector < vector < int > > restoreGem ( vector < int > & r , vector < int > & c ) { vector < vector < int > > dp ( r . size ( ) , vector < int > ( c . size ( ) , 0 ) ) ; for ( int i = 0 ; i < r . size ( ) ; i ++ ) { for ( int j = 0 ; j < c . size ( ) ; j ++ ) { int m = min ( r [ i ] , c [ j ] ) ; dp [ i ] [ j ] = m ; r [ i ] -= m ; c [ j ] -= m ; } } return dp ; } void printMatrix ( vector < vector < int > > ans , int N , int M ) { for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < M ; j ++ ) { cout << ans [ i ] [ j ] << " ▁ " ; } cout << endl ; } } int main ( ) { vector < int > rowSum = { 5 , 7 , 10 } ; vector < int > colSum = { 8 , 6 , 8 } ; vector < vector < int > > ans = restoreGem ( rowSum , colSum ) ; printMatrix ( ans , rowSum . size ( ) , colSum . size ( ) ) ; }

Index/key variables: i, j
Accumulator variables: i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define MAX  1000000
int maxSumOfDistinctPrimeFactors ( int arr [ ] , int N , int K ) { int CountDistinct [ MAX + 1 ] ; bool prime [ MAX + 1 ] ; for ( int i = 0 ; i <= MAX ; i ++ ) { CountDistinct [ i ] = 0 ; prime [ i ] = true ; } for ( long long int i = 2 ; i <= MAX ; i ++ ) { if ( prime [ i ] == true ) { CountDistinct [ i ] = 1 ; for ( long long int j = i * 2 ; j <= MAX ; j += i ) { CountDistinct [ j ] ++ ; prime [ j ] = false ; } } } int sum = 0 ; int PrimeFactor [ 20 ] = { 0 } ; for ( int i = 0 ; i < N ; i ++ ) { PrimeFactor [ CountDistinct [ arr [ i ] ] ] ++ ; } for ( int i = 19 ; i >= 1 ; i -- ) { while ( PrimeFactor [ i ] > 0 ) { sum += i ; PrimeFactor [ i ] -- ; K -- ; if ( K == 0 ) break ; } if ( K == 0 ) break ; } cout << sum ; } int main ( ) { int arr [ ] = { 6 , 9 , 12 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int K = 2 ; maxSumOfDistinctPrimeFactors ( arr , N , K ) ; return 0 ; }

Index/key variables: i, j
Accumulator variables: K, i, j, stdc, sum
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; int maxChange ( string str ) { if ( str . size ( ) <= 1 ) { return 0 ; } int minChanges = 0 ; for ( int i = 0 ; i < str . size ( ) - 1 ; i ++ ) { if ( str [ i ] == str [ i + 1 ] ) { str [ i + 1 ] = ' N ' ; minChanges += 1 ; } else if ( i > 0 && str [ i - 1 ] == str [ i + 1 ] ) { str [ i + 1 ] = ' N ' ; minChanges += 1 ; } } return minChanges ; } int main ( ) { string str = " bbbbbbb " ; cout << maxChange ( str ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, minChanges, stdc
Iterator variables: i
C++ program:
#include <iostream>
#include <set>
using namespace std ; void findMinKToMakeAllEqual ( int N , int A [ ] ) { set < int > B ; for ( int i = 0 ; i < N ; i ++ ) B . insert ( A [ i ] ) ; int M = B . size ( ) ; set < int > :: iterator itr = B . begin ( ) ; if ( M > 3 ) printf ( " - 1" ) ; else if ( M == 3 ) { int B_1 = * itr ; int B_2 = * ( ++ itr ) ; int B_3 = * ( ++ itr ) ; if ( B_2 - B_1 == B_3 - B_2 ) printf ( " % d " , B_2 - B_1 ) ; else printf ( " - 1" ) ; } else if ( M == 2 ) { int B_1 = * itr ; int B_2 = * ( ++ itr ) ; if ( ( B_2 - B_1 ) % 2 == 0 ) printf ( " % d " , ( B_2 - B_1 ) / 2 ) ; else printf ( " % d " , B_2 - B_1 ) ; } else printf ( " % d " , 0 ) ; } int main ( ) { int A [ ] = { 1 , 3 , 5 , 1 } ; int N = sizeof ( A ) / sizeof ( A [ 0 ] ) ; findMinKToMakeAllEqual ( N , A ) ; }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void computeLPSArray ( string pat , int M , int * lps ) { int len = 0 ; lps [ 0 ] = 0 ; int i = 1 ; while ( i < M ) { if ( pat [ i ] == pat [ len ] ) { len ++ ; lps [ i ] = len ; i ++ ; } else { if ( len != 0 ) { len = lps [ len - 1 ] ; } else { lps [ i ] = 0 ; i ++ ; } } } } int KMPSearch ( string pat , string txt ) { int M = pat . size ( ) ; int N = txt . size ( ) ; int lps [ M ] ; computeLPSArray ( pat , M , lps ) ; int i = 0 ; int j = 0 ; while ( i < N ) { if ( pat [ j ] == txt [ i ] ) { j ++ ; i ++ ; } if ( j == M ) { return 1 ; j = lps [ j - 1 ] ; } else if ( i < N && pat [ j ] != txt [ i ] ) { if ( j != 0 ) j = lps [ j - 1 ] ; else i = i + 1 ; } } return 0 ; } void maxRepeating ( string seq , string word ) { int resCount = 0 ; string curWord = word ; int numWords = seq . length ( ) / word . length ( ) ; for ( int i = 0 ; i < numWords ; i ++ ) { if ( KMPSearch ( curWord , seq ) ) { curWord += word ; resCount ++ ; } else break ; } cout << resCount ; } int main ( ) { string S1 = " ababc " , S2 = " ab " ; maxRepeating ( S1 , S2 ) ; return 0 ; }

Index/key variables: M, i, j, len
Accumulator variables: curWord, i, j, len, resCount, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; long long int countNumberOfStrings ( string s ) { int length = s . length ( ) ; int n = length - 1 ; long long int count = pow ( 2 , n ) ; return count ; } int main ( ) { string S = " ABCD " ; cout << countNumberOfStrings ( S ) ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; void findMinimumTime ( int * p , int n , int target ) { unordered_map < int , int > um ; for ( int i = 0 ; i < n ; i ++ ) { um [ p [ i ] ] ++ ; } int time = 0 ; int sum = 0 ; while ( sum < target ) { sum = 0 ; time ++ ; for ( auto & it : um ) { sum += it . second * ( time / it . first ) ; } } cout << time ; } int main ( ) { int arr [ ] = { 1 , 3 , 3 , 4 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int target = 10 ; findMinimumTime ( arr , N , target ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc, sum, time
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define MAXN  100001
void constructMEX ( int arr [ ] , int N ) { int hash [ MAXN ] = { 0 } ; for ( int i = 0 ; i < N ; i ++ ) { hash [ arr [ i ] ] = 1 ; } int MexOfArr ; for ( int i = 1 ; i < MAXN ; i ++ ) { if ( hash [ i ] == 0 ) { MexOfArr = i ; break ; } } int B [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { if ( arr [ i ] < MexOfArr ) B [ i ] = arr [ i ] ; else B [ i ] = MexOfArr ; } for ( int i = 0 ; i < N ; i ++ ) cout << B [ i ] << ' ▁ ' ; } int main ( ) { int arr [ ] = { 2 , 1 , 5 , 3 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; constructMEX ( arr , N ) ; return 0 ; }

Index/key variables: MAXN, N, i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void smallestNumberLeftInPQ ( int arr [ ] , int N ) { priority_queue < int > pq ; vector < pair < int , int > > pairsArr ; for ( int i = 0 ; i < N ; i ++ ) { pq . push ( arr [ i ] ) ; } while ( pq . size ( ) > 1 ) { int X = pq . top ( ) ; pq . pop ( ) ; int Y = pq . top ( ) ; pq . pop ( ) ; pq . push ( ( X + Y + 1 ) / 2 ) ; pairsArr . push_back ( { X , Y } ) ; } cout << " { " << pq . top ( ) << " } , ▁ " ; int sz = pairsArr . size ( ) ; for ( int i = 0 ; i < sz ; i ++ ) { if ( i == 0 ) { cout << " { ▁ " ; } cout << " ( " << pairsArr [ i ] . first << " , ▁ " << pairsArr [ i ] . second << " ) " ; if ( i != sz - 1 ) { cout << " , ▁ " ; } if ( i == sz - 1 ) { cout << " ▁ } " ; } } } int main ( ) { int arr [ ] = { 3 , 2 , 1 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; smallestNumberLeftInPQ ( arr , N ) ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool dfs ( int residue , int curStep , int wt [ ] , int arr [ ] , int N , int steps ) { if ( curStep > steps ) return true ; for ( int i = 0 ; i < N ; i ++ ) { if ( arr [ i ] > residue && arr [ i ] != wt [ curStep - 1 ] ) { wt [ curStep ] = arr [ i ] ; if ( dfs ( arr [ i ] - residue , curStep + 1 , wt , arr , N , steps ) ) return true ; } } return false ; } void printWeightsOnScale ( int arr [ ] , int N , int steps ) { int wt [ steps ] ; if ( dfs ( 0 , 0 , wt , arr , N , steps ) ) { for ( int i = 0 ; i < steps ; i ++ ) cout << wt [ i ] << " ▁ " ; cout << endl ; } else cout << " Not ▁ possible STRNEWLINE " ; } int main ( ) { int arr [ ] = { 2 , 3 , 5 , 6 } ; int N = sizeof ( arr ) / sizeof ( int ) ; int steps = 10 ; printWeightsOnScale ( arr , N , steps ) ; return 0 ; }

Index/key variables: curStep, i, steps
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int findSum ( vector < int > S , int n , int x ) { vector < vector < int > > table ( n + 1 , vector < int > ( x + 1 , 0 ) ) ; for ( int i = 1 ; i <= x ; i ++ ) { table [ 0 ] [ i ] = INT_MAX - 1 ; } for ( int i = 1 ; i <= n ; i ++ ) { for ( int j = 1 ; j <= x ; j ++ ) { if ( S [ i - 1 ] > j ) { table [ i ] [ j ] = table [ i - 1 ] [ j ] ; } else { table [ i ] [ j ] = min ( table [ i - 1 ] [ j ] , table [ i ] [ j - S [ i - 1 ] ] + 1 ) ; } } } return ( table [ n ] [ x ] > n ) ? -1 : table [ n ] [ x ] ; } void minRemovals ( vector < int > arr , int n , int m , int x ) { int sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) { sum += arr [ i ] ; } int requied_Sum = 0 ; if ( sum % m < x ) requied_Sum = m + sum % m - x ; else requied_Sum = sum % m - x ; cout << findSum ( arr , n , requied_Sum ) ; } int main ( ) { vector < int > arr = { 3 , 2 , 1 , 2 } ; int n = arr . size ( ) ; int m = 4 , x = 2 ; minRemovals ( arr , n , m , x % m ) ; return 0 ; }

Index/key variables: i, j, n, x
Accumulator variables: i, j, stdc, sum
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; int minChange ( string s , int n ) { int L [ 26 ] = { 0 } ; int R [ 26 ] = { 0 } ; for ( int i = 0 ; i < n / 2 ; i ++ ) { char ch = s [ i ] ; L [ ch - ' a ' ] ++ ; } for ( int i = n / 2 ; i < n ; i ++ ) { char ch = s [ i ] ; R [ ch - ' a ' ] ++ ; } int count = n ; for ( char ch = ' a ' ; ch <= ' z ' ; ch ++ ) { count = min ( count , n - L [ ch - ' a ' ] - R [ ch - ' a ' ] ) ; } int change = n / 2 ; for ( int d = 0 ; d + 1 < 26 ; d ++ ) { change -= L [ d ] ; change += R [ d ] ; count = min ( count , change ) ; } change = n / 2 ; for ( int d = 0 ; d + 1 < 26 ; d ++ ) { change -= R [ d ] ; change += L [ d ] ; count = min ( change , count ) ; } return count ; } int main ( ) { string S = " aababc " ; int N = S . length ( ) ; cout << minChange ( S , N ) << " STRNEWLINE " ; }

Index/key variables: d, i
Accumulator variables: ch, change, d, i, stdc
Iterator variables: ch, d, i
C++ program:
#include <bits/stdc++.h>
using namespace std ; string longestPalinSub ( string str ) { int N = str . length ( ) ; int hash [ 256 ] = { 0 } ; for ( int i = 0 ; i < N ; i ++ ) { hash [ str [ i ] ] ++ ; } string res1 = " " ; string res2 = " " ; for ( int i = 0 ; i < 256 ; i ++ ) { for ( int j = 0 ; j < hash [ i ] / 2 ; j ++ ) { res1 . push_back ( i ) ; } for ( int j = ( hash [ i ] + 1 ) / 2 ; j < hash [ i ] ; j ++ ) { res2 . push_back ( i ) ; } } reverse ( res2 . begin ( ) , res2 . end ( ) ) ; string res3 ; bool f = false ; for ( int i = 0 ; i < 256 ; i ++ ) { if ( hash [ i ] % 2 ) { if ( ! f ) { res1 . push_back ( i ) ; f = true ; } else { res3 . push_back ( i ) ; } } } return ( res1 + res2 + res3 ) ; } int main ( ) { string str = " geeksforgeeks " ; cout << longestPalinSub ( str ) ; }

Index/key variables: i
Accumulator variables: i, j, stdc
Iterator variables: i, j
Boolean variables: f
C++ program:
#include <bits/stdc++.h>
using namespace std ; int No_Of_subsequences ( map < int , int > mp ) { int count = 0 ; int left = 0 ; for ( auto x : mp ) { x . second += left ; count += ( x . second / x . first ) ; left = x . second % x . first ; } return count ; } void maximumsubsequences ( int arr [ ] , int n ) { map < int , int > mp ; for ( int i = 0 ; i < n ; i ++ ) mp [ arr [ i ] ] ++ ; cout << No_Of_subsequences ( mp ) ; } int main ( ) { int arr [ ] = { 1 , 1 , 1 , 1 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; maximumsubsequences ( arr , N ) ; return 0 ; }

Index/key variables: i
Accumulator variables: count, i, second, stdc
Iterator variables: i, x