dhyuti-n/xlcost-variable-roles huggingface dataset:
C++ program:
#include <bits/stdc++.h>
using namespace std ; int number_of_tower ( int house [ ] , int range , int n ) { sort ( house , house + n ) ; int numOfTower = 0 ; int i = 0 ; while ( i < n ) { numOfTower ++ ; int loc = house [ i ] + range ; while ( i < n && house [ i ] <= loc ) i ++ ; -- i ; loc = house [ i ] + range ; while ( i < n && house [ i ] <= loc ) i ++ ; } return numOfTower ; } int main ( ) { int house [ ] = { 7 , 2 , 4 , 6 , 5 , 9 , 12 , 11 } ; int range = 2 ; int n = sizeof ( house ) / sizeof ( house [ 0 ] ) ; cout << number_of_tower ( house , range , n ) ; }

Index/key variables: i
Accumulator variables: i, numOfTower, stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool isAlphabaticOrder ( string s ) { int n = s . length ( ) ; char c [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { c [ i ] = s [ i ] ; } sort ( c , c + n ) ; for ( int i = 0 ; i < n ; i ++ ) if ( c [ i ] != s [ i ] ) return false ; return true ; } int main ( ) { string s = " aabbbcc " ; if ( isAlphabaticOrder ( s ) ) cout << " Yes " ; else cout << " No " ; return 0 ; }

Index/key variables: i, n
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void printOrder ( int arr [ ] , int n , int k ) { sort ( arr , arr + k ) ; sort ( arr + k , arr + n , greater < int > ( ) ) ; } int main ( ) { int arr [ ] = { 5 , 4 , 6 , 2 , 1 , 3 , 8 , 9 , -1 } ; int k = 4 ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; printOrder ( arr , n , k ) ; for ( int i = 0 ; i < n ; i ++ ) cout << arr [ i ] << " ▁ " ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; struct Node { int data ; struct Node * left ; struct Node * right ; } ; int maxWidth ( struct Node * root ) { if ( root == NULL ) return 0 ; int result = 0 ; queue < Node * > q ; q . push ( root ) ; while ( ! q . empty ( ) ) { int count = q . size ( ) ; result = max ( count , result ) ; while ( count -- ) { Node * temp = q . front ( ) ; q . pop ( ) ; if ( temp -> left != NULL ) q . push ( temp -> left ) ; if ( temp -> right != NULL ) q . push ( temp -> right ) ; } } return result ; } struct Node * newNode ( int data ) { struct Node * node = new Node ; node -> data = data ; node -> left = node -> right = NULL ; return ( node ) ; } int main ( ) { struct Node * root = newNode ( 1 ) ; root -> left = newNode ( 2 ) ; root -> right = newNode ( 3 ) ; root -> left -> left = newNode ( 4 ) ; root -> left -> right = newNode ( 5 ) ; root -> right -> right = newNode ( 8 ) ; root -> right -> right -> left = newNode ( 6 ) ; root -> right -> right -> right = newNode ( 7 ) ; cout << " Maximum ▁ width ▁ is ▁ " << maxWidth ( root ) << endl ; return 0 ; }

Accumulator variables: count, stdc
Class/struct names: Node
C++ program:
#include <bits/stdc++.h>
using namespace std ; stack < int > sortStack ( stack < int > & input ) { stack < int > tmpStack ; while ( ! input . empty ( ) ) { int tmp = input . top ( ) ; input . pop ( ) ; while ( ! tmpStack . empty ( ) && tmpStack . top ( ) > tmp ) { input . push ( tmpStack . top ( ) ) ; tmpStack . pop ( ) ; } tmpStack . push ( tmp ) ; } return tmpStack ; } stack < int > sortedMerge ( stack < int > & s1 , stack < int > & s2 ) { stack < int > res ; while ( ! s1 . empty ( ) ) { res . push ( s1 . top ( ) ) ; s1 . pop ( ) ; } while ( ! s2 . empty ( ) ) { res . push ( s2 . top ( ) ) ; s2 . pop ( ) ; } return sortStack ( res ) ; } int main ( ) { stack < int > s1 , s2 ; s1 . push ( 34 ) ; s1 . push ( 3 ) ; s1 . push ( 31 ) ; s2 . push ( 1 ) ; s2 . push ( 12 ) ; s2 . push ( 23 ) ; stack < int > tmpStack = sortedMerge ( s1 , s2 ) ; cout << " Sorted ▁ and ▁ merged ▁ stack ▁ : STRNEWLINE " ; while ( ! tmpStack . empty ( ) ) { cout << tmpStack . top ( ) << " ▁ " ; tmpStack . pop ( ) ; } }

Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; string lexicographicSubConcat ( string s ) { int n = s . length ( ) ; int sub_count = n * ( n + 1 ) / 2 ; string arr [ sub_count ] ; int index = 0 ; for ( int i = 0 ; i < n ; i ++ ) for ( int len = 1 ; len <= n - i ; len ++ ) arr [ index ++ ] = s . substr ( i , len ) ; sort ( arr , arr + sub_count ) ; string res = " " ; for ( int i = 0 ; i < sub_count ; i ++ ) res += arr [ i ] ; return res ; } int main ( ) { string s = " abc " ; cout << lexicographicSubConcat ( s ) ; return 0 ; }

Index/key variables: i, sub_count
Accumulator variables: i, index, len, res, stdc
Iterator variables: i, len
C++ program:
#include <iostream>
#include <vector>
using namespace std ; using Vector = vector < int > ; void printVector ( const Vector & V ) { for ( auto e : V ) { cout << e << " ▁ " ; } cout << endl ; } void insertionSort ( Vector & V ) { int N = V . size ( ) ; int i , j , key ; for ( i = 1 ; i < N ; i ++ ) { j = i ; while ( j > 0 and V [ j ] < V [ j - 1 ] ) { swap ( V [ j ] , V [ j - 1 ] ) ; j -= 1 ; } } } int main ( ) { Vector A = { 9 , 8 , 7 , 5 , 2 , 1 , 2 , 3 } ; cout << " Array : ▁ " << endl ; printVector ( A ) ; cout << " After ▁ Sorting ▁ : " << endl ; insertionSort ( A ) ; printVector ( A ) ; return 0 ; }

Index/key variables: j
Accumulator variables: i, j
Iterator variables: e, i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void descOrder ( string s ) { sort ( s . begin ( ) , s . end ( ) , greater < char > ( ) ) ; } int main ( ) { string s = " geeksforgeeks " ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; const int MAX_CHAR = 26 ; void sortString ( string & str ) { int charCount [ MAX_CHAR ] = { 0 } ; for ( int i = 0 ; i < str . length ( ) ; i ++ ) charCount [ str [ i ] - ' a ' ] ++ ; for ( int i = 0 ; i < MAX_CHAR ; i ++ ) for ( int j = 0 ; j < charCount [ i ] ; j ++ ) cout << ( char ) ( ' a ' + i ) ; } int main ( ) { string s = " geeksforgeeks " ; sortString ( s ) ; return 0 ; }

Index/key variables: MAX_CHAR, i
Accumulator variables: i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; const int MAX = 1000 ; int findDuplicate ( int arr [ ] , int n , int k ) { int freq [ MAX ] ; memset ( freq , 0 , sizeof ( freq ) ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( arr [ i ] < 1 && arr [ i ] > MAX ) { cout << " Out ▁ of ▁ range " ; return -1 ; } freq [ arr [ i ] ] += 1 ; } for ( int i = 0 ; i < MAX ; i ++ ) { if ( freq [ i ] == k ) return i ; } return -1 ; } int main ( ) { int arr [ ] = { 2 , 2 , 1 , 3 , 1 } ; int k = 2 ; int n = sizeof ( arr ) / ( sizeof ( arr [ 0 ] ) ) ; cout << findDuplicate ( arr , n , k ) ; return 0 ; }

Index/key variables: MAX, i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; struct prefix { int sum ; int index ; } ; bool comparison ( prefix a , prefix b ) { return a . sum < b . sum ; } pair < int , int > findSubArray ( int arr [ ] , int n ) { int start , end , min_diff = INT_MAX ; prefix pre_sum [ n + 1 ] ; pre_sum [ 0 ] . sum = 0 ; pre_sum [ 0 ] . index = -1 ; for ( int i = 1 ; i <= n ; i ++ ) { pre_sum [ i ] . sum = pre_sum [ i - 1 ] . sum + arr [ i - 1 ] ; pre_sum [ i ] . index = i - 1 ; } sort ( pre_sum , pre_sum + ( n + 1 ) , comparison ) ; for ( int i = 1 ; i <= n ; i ++ ) { int diff = pre_sum [ i ] . sum - pre_sum [ i - 1 ] . sum ; if ( min_diff > diff ) { min_diff = diff ; start = pre_sum [ i - 1 ] . index ; end = pre_sum [ i ] . index ; } } pair < int , int > p = make_pair ( start + 1 , end ) ; return p ; } int main ( ) { int arr [ ] = { 2 , 3 , -4 , -1 , 6 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; pair < int , int > point = findSubArray ( arr , n ) ; cout << " Subarray ▁ starting ▁ from ▁ " ; cout << point . first << " ▁ to ▁ " << point . second ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
Class/struct names: prefix
C++ program:
#include <bits / stdc++.h>
using namespace std ; int binarySearch ( int arr [ ] , int low , int high , int x ) { while ( low <= high ) { int mid = ( low + high ) / 2 ; if ( arr [ mid ] == x ) return mid ; else if ( arr [ mid ] > x ) high = mid - 1 ; else low = mid + 1 ; } } string isKSortedArray ( int arr [ ] , int n , int k ) { int aux [ n ] ; for ( int i = 0 ; i < n ; i ++ ) aux [ i ] = arr [ i ] ; sort ( aux , aux + n ) ; for ( int i = 0 ; i < n ; i ++ ) { int j = binarySearch ( aux , 0 , n - 1 , arr [ i ] ) ; if ( abs ( i - j ) > k ) return " No " ; } return " Yes " ; } int main ( ) { int arr [ ] = { 3 , 2 , 1 , 5 , 6 , 4 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int k = 2 ; cout << " Is ▁ it ▁ a ▁ k ▁ sorted ▁ array ? : ▁ " << isKSortedArray ( arr , n , k ) ; return 0 ; }

Index/key variables: i, mid, n
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; const int RUN = 32 ; void insertionSort ( int arr [ ] , int left , int right ) { for ( int i = left + 1 ; i <= right ; i ++ ) { int temp = arr [ i ] ; int j = i - 1 ; while ( j >= left && arr [ j ] > temp ) { arr [ j + 1 ] = arr [ j ] ; j -- ; } arr [ j + 1 ] = temp ; } } void merge ( int arr [ ] , int l , int m , int r ) { int len1 = m - l + 1 , len2 = r - m ; int left [ len1 ] , right [ len2 ] ; for ( int i = 0 ; i < len1 ; i ++ ) left [ i ] = arr [ l + i ] ; for ( int i = 0 ; i < len2 ; i ++ ) right [ i ] = arr [ m + 1 + i ] ; int i = 0 ; int j = 0 ; int k = l ; while ( i < len1 && j < len2 ) { if ( left [ i ] <= right [ j ] ) { arr [ k ] = left [ i ] ; i ++ ; } else { arr [ k ] = right [ j ] ; j ++ ; } k ++ ; } while ( i < len1 ) { arr [ k ] = left [ i ] ; k ++ ; i ++ ; } while ( j < len2 ) { arr [ k ] = right [ j ] ; k ++ ; j ++ ; } } void timSort ( int arr [ ] , int n ) { for ( int i = 0 ; i < n ; i += RUN ) insertionSort ( arr , i , min ( ( i + RUN - 1 ) , ( n - 1 ) ) ) ; for ( int size = RUN ; size < n ; size = 2 * size ) { for ( int left = 0 ; left < n ; left += 2 * size ) { int mid = left + size - 1 ; int right = min ( ( left + 2 * size - 1 ) , ( n - 1 ) ) ; if ( mid < right ) merge ( arr , left , mid , right ) ; } } } void printArray ( int arr [ ] , int n ) { for ( int i = 0 ; i < n ; i ++ ) printf ( " % d ▁ " , arr [ i ] ) ; printf ( " STRNEWLINE " ) ; } int main ( ) { int arr [ ] = { -2 , 7 , 15 , -14 , 0 , 15 , 0 , 7 , -7 , -4 , -13 , 5 , 8 , -14 , 12 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; printf ( " Given ▁ Array ▁ is STRNEWLINE " ) ; printArray ( arr , n ) ; timSort ( arr , n ) ; printf ( " After ▁ Sorting ▁ Array ▁ is STRNEWLINE " ) ; printArray ( arr , n ) ; return 0 ; }

Index/key variables: i, j, k, len1, len2
Accumulator variables: i, j, k, left, stdc
Iterator variables: i, left, size
C++ program:
#include <bits/stdc++.h>
using namespace std ; void pendulumArrangement ( int arr [ ] , int n ) { sort ( arr , arr + n ) ; int op [ n ] ; int mid = ( n - 1 ) / 2 ; int j = 1 , i = 1 ; op [ mid ] = arr [ 0 ] ; for ( i = 1 ; i <= mid ; i ++ ) { op [ mid + i ] = arr [ j ++ ] ; op [ mid - i ] = arr [ j ++ ] ; } if ( n % 2 == 0 ) op [ mid + i ] = arr [ j ] ; cout << " Pendulum ▁ arrangement : " << endl ; for ( i = 0 ; i < n ; i ++ ) cout << op [ i ] << " ▁ " ; cout << endl ; } int main ( ) { int arr [ ] = { 14 , 6 , 19 , 21 , 12 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; pendulumArrangement ( arr , n ) ; return 0 ; }

Index/key variables: i, j, mid, n
Accumulator variables: i, j, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; class node { public : int data ; node * left ; node * right ; } ; int height ( node * node ) ; node * newNode ( int data ) ; void getMaxWidthRecur ( node * root , int count [ ] , int level ) ; int getMax ( int arr [ ] , int n ) ; int getMaxWidth ( node * root ) { int width ; int h = height ( root ) ; int * count = new int [ h ] ; int level = 0 ; getMaxWidthRecur ( root , count , level ) ; return getMax ( count , h ) ; } void getMaxWidthRecur ( node * root , int count [ ] , int level ) { if ( root ) { count [ level ] ++ ; getMaxWidthRecur ( root -> left , count , level + 1 ) ; getMaxWidthRecur ( root -> right , count , level + 1 ) ; } } int height ( node * node ) { if ( node == NULL ) return 0 ; else { int lHeight = height ( node -> left ) ; int rHeight = height ( node -> right ) ; return ( lHeight > rHeight ) ? ( lHeight + 1 ) : ( rHeight + 1 ) ; } } node * newNode ( int data ) { node * Node = new node ( ) ; Node -> data = data ; Node -> left = NULL ; Node -> right = NULL ; return ( Node ) ; } int getMax ( int arr [ ] , int n ) { int max = arr [ 0 ] ; int i ; for ( i = 0 ; i < n ; i ++ ) { if ( arr [ i ] > max ) max = arr [ i ] ; } return max ; } int main ( ) { node * root = newNode ( 1 ) ; root -> left = newNode ( 2 ) ; root -> right = newNode ( 3 ) ; root -> left -> left = newNode ( 4 ) ; root -> left -> right = newNode ( 5 ) ; root -> right -> right = newNode ( 8 ) ; root -> right -> right -> left = newNode ( 6 ) ; root -> right -> right -> right = newNode ( 7 ) ; cout << " Maximum ▁ width ▁ is ▁ " << getMaxWidth ( root ) << endl ; return 0 ; }

Index/key variables: h, i, level
Accumulator variables: i, stdc
Iterator variables: i
Class/struct names: node
C++ program:
#include <bits/stdc++.h>
using namespace std ; long long int minValue ( int A [ ] , int B [ ] , int n ) { sort ( A , A + n ) ; sort ( B , B + n ) ; long long int result = 0 ; for ( int i = 0 ; i < n ; i ++ ) result += ( A [ i ] * B [ n - i - 1 ] ) ; return result ; } int main ( ) { int A [ ] = { 3 , 1 , 1 } ; int B [ ] = { 6 , 5 , 4 } ; int n = sizeof ( A ) / sizeof ( A [ 0 ] ) ; cout << minValue ( A , B , n ) << endl ; return 0 ; }

Index/key variables: i
Accumulator variables: i, result, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int TotalPerfectPowerSum ( long long L , long long R ) { vector < long long > pows ; pows . push_back ( 0 ) ; pows . push_back ( 1 ) ; for ( int p = 2 ; p < 25 ; p ++ ) { long long int num = 2 ; while ( ( long long int ) ( pow ( num , p ) + 0.5 ) <= R ) { pows . push_back ( ( long long int ) ( pow ( num , p ) + 0.5 ) ) ; num ++ ; } } int ok [ R + 1 ] ; memset ( ok , 0 , sizeof ( ok ) ) ; for ( int i = 0 ; i < pows . size ( ) ; i ++ ) { for ( int j = 0 ; j < pows . size ( ) ; j ++ ) { if ( pows [ i ] + pows [ j ] <= R and pows [ i ] + pows [ j ] >= L ) { ok [ pows [ i ] + pows [ j ] ] = 1 ; } } } for ( int i = 0 ; i <= R ; i ++ ) { ok [ i ] += ok [ i - 1 ] ; } return ok [ R ] - ok [ L - 1 ] ; } signed main ( ) { int L = 5 , R = 8 ; cout << TotalPerfectPowerSum ( L , R ) ; return 0 ; }

Index/key variables: R, i, j
Accumulator variables: i, j, num, p, stdc
Iterator variables: i, j, p
C++ program:
#include <bits/stdc++.h>
using namespace std ; struct Node { int data ; struct Node * left , * right ; } ; void lengthUtil ( Node * root , int & maximum , int & minimum , int curr = 0 ) { if ( root == NULL ) return ; lengthUtil ( root -> left , maximum , minimum , curr - 1 ) ; if ( minimum > curr ) minimum = curr ; if ( maximum < curr ) maximum = curr ; lengthUtil ( root -> right , maximum , minimum , curr + 1 ) ; } int getLength ( Node * root ) { int maximum = 0 , minimum = 0 ; lengthUtil ( root , maximum , minimum , 0 ) ; return ( abs ( minimum ) + maximum ) + 1 ; } Node * newNode ( int data ) { Node * curr = new Node ; curr -> data = data ; curr -> left = curr -> right = NULL ; return curr ; } int main ( ) { Node * root = newNode ( 7 ) ; root -> left = newNode ( 6 ) ; root -> right = newNode ( 5 ) ; root -> left -> left = newNode ( 4 ) ; root -> left -> right = newNode ( 3 ) ; root -> right -> left = newNode ( 2 ) ; root -> right -> right = newNode ( 1 ) ; cout << getLength ( root ) << " STRNEWLINE " ; return 0 ; }

Accumulator variables: stdc
Class/struct names: Node
C++ program:
#include <bits/stdc++.h>
using namespace std ; void findMaximumSumWithMflips ( int arr [ ] , int N , int M ) { priority_queue < int , vector < int > , greater < int > > pq ; int sum = 0 ; for ( int i = 0 ; i < N ; i ++ ) { pq . push ( arr [ i ] ) ; sum += arr [ i ] ; } while ( M -- ) { sum -= pq . top ( ) ; int temp = -1 * pq . top ( ) ; pq . pop ( ) ; sum += temp ; pq . push ( temp ) ; } cout << sum ; } int main ( ) { int arr [ ] = { -3 , 7 , -1 , -5 , -3 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int M = 4 ; findMaximumSumWithMflips ( arr , N , M ) ; return 0 ; }

Index/key variables: i
Accumulator variables: M, i, stdc, sum
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void miniOperToMakeAllEleEqual ( int arr [ ] , int n , int k ) { int sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) { sum += arr [ i ] ; } if ( sum % n ) { cout << -1 ; return ; } int valueAfterDivision = sum / n ; int count = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( abs ( valueAfterDivision - arr [ i ] ) % k != 0 ) { cout << -1 ; return ; } count += abs ( valueAfterDivision - arr [ i ] ) / k ; } cout << count / 2 << endl ; } int main ( ) { int n = 3 , k = 3 ; int arr [ 3 ] = { 5 , 8 , 11 } ; miniOperToMakeAllEleEqual ( arr , n , k ) ; return 0 ; }

Index/key variables: i
Accumulator variables: count, i, stdc, sum
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void minOperations ( vector < int > a ) { int res = INT_MAX ; int N = a . size ( ) ; for ( int r = 0 ; r < 2 ; r ++ ) { int sum = 0 , ans = 0 ; for ( int i = 0 ; i < N ; i ++ ) { sum += a [ i ] ; if ( ( i + r ) % 2 ) { if ( sum <= 0 ) { ans += - sum + 1 ; sum = 1 ; } } else { if ( sum >= 0 ) { ans += sum + 1 ; sum = -1 ; } } } res = min ( res , ans ) ; } cout << res ; } int main ( ) { vector < int > a { 1 , -3 , 1 , 0 } ; minOperations ( a ) ; return 0 ; }

Index/key variables: i
Accumulator variables: ans, i, r, stdc, sum
Iterator variables: i, r
C++ program:
#include <bits/stdc++.h>
using namespace std ; void print1 ( vector < int > & a , vector < int > & b ) { int minProd = 0 ; for ( int i = 0 ; i < a . size ( ) ; ++ i ) { cout << a [ i ] << " ▁ " ; } cout << endl ; for ( int i = 0 ; i < b . size ( ) ; ++ i ) { cout << b [ i ] << " ▁ " ; minProd += a [ i ] * b [ i ] ; } cout << endl ; cout << minProd ; } void reverse1 ( int left , int right , vector < int > & arr ) { while ( left < right ) { int temp = arr [ left ] ; arr [ left ] = arr [ right ] ; arr [ right ] = temp ; ++ left ; -- right ; } } void minimumProdArray ( vector < int > & a , vector < int > & b , int l ) { int total = 0 ; for ( int i = 0 ; i < a . size ( ) ; ++ i ) { total += a [ i ] * b [ i ] ; } int min = INT_MAX ; int first = 0 ; int second = 0 ; for ( int i = 0 ; i < a . size ( ) ; ++ i ) { int left = i - 1 ; int right = i + 1 ; int total1 = total ; while ( left >= 0 && right < a . size ( ) ) { total1 -= a [ left ] * b [ left ] + a [ right ] * b [ right ] ; total1 += a [ left ] * b [ right ] + a [ right ] * b [ left ] ; if ( min >= total1 ) { min = total1 ; first = left ; second = right ; } -- left ; ++ right ; } } for ( int i = 0 ; i < a . size ( ) ; ++ i ) { int left = i ; int right = i + 1 ; int total1 = total ; while ( left >= 0 && right < a . size ( ) ) { total1 -= a [ left ] * b [ left ] + a [ right ] * b [ right ] ; total1 += a [ left ] * b [ right ] + a [ right ] * b [ left ] ; if ( min >= total1 ) { min = total1 ; first = left ; second = right ; } -- left ; ++ right ; } } if ( min < total ) { reverse1 ( first , second , a ) ; print1 ( a , b ) ; } else { print1 ( a , b ) ; } } int main ( ) { int n = 4 ; vector < int > a { 2 , 3 , 1 , 5 } ; vector < int > b { 8 , 2 , 4 , 3 } ; minimumProdArray ( a , b , n ) ; }

Index/key variables: i, left, right
Accumulator variables: minProd, stdc, total, total1
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int MaxCollection ( string S , int P , int Q ) { char maxstr [ 2 ] ; string x = ( P >= Q ? " ab " : " ba " ) ; strcpy ( maxstr , x . c_str ( ) ) ; char minstr [ 2 ] ; x = ( P >= Q ? " ba " : " ab " ) ; strcpy ( minstr , x . c_str ( ) ) ; int maxp = max ( P , Q ) ; int minp = min ( P , Q ) ; int cost = 0 ; stack < char > stack1 ; char s [ S . length ( ) ] ; strcpy ( s , S . c_str ( ) ) ; for ( auto & ch : s ) { if ( ! stack1 . empty ( ) && ( stack1 . top ( ) == maxstr [ 0 ] && ch == maxstr [ 1 ] ) ) { stack1 . pop ( ) ; cost += maxp ; } else { stack1 . push ( ch ) ; } } string sb = " " ; while ( stack1 . size ( ) > 0 ) { sb = sb + stack1 . top ( ) ; stack1 . pop ( ) ; } reverse ( sb . begin ( ) , sb . end ( ) ) ; for ( auto & ch : sb ) { if ( ! stack1 . empty ( ) && ( stack1 . top ( ) == minstr [ 0 ] && ch == minstr [ 1 ] ) ) { stack1 . pop ( ) ; cost += minp ; } else { stack1 . push ( ch ) ; } } return cost ; } int main ( ) { string S = " cbbaabbaab " ; int P = 6 ; int Q = 4 ; cout << MaxCollection ( S , P , Q ) ; return 0 ; }

Accumulator variables: cost, stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; class Node { public : int data ; Node * left , * right ; Node ( int data_new ) { data = data_new ; left = right = NULL ; } } ; void fillSet ( Node * root , unordered_set < int > & s , int hd ) { if ( ! root ) return ; fillSet ( root -> left , s , hd - 1 ) ; s . insert ( hd ) ; fillSet ( root -> right , s , hd + 1 ) ; } int verticalWidth ( Node * root ) { unordered_set < int > s ; fillSet ( root , s , 0 ) ; return s . size ( ) ; } int main ( ) { Node * root = NULL ; root = new Node ( 1 ) ; root -> left = new Node ( 2 ) ; root -> right = new Node ( 3 ) ; root -> left -> left = new Node ( 4 ) ; root -> left -> right = new Node ( 5 ) ; root -> right -> left = new Node ( 6 ) ; root -> right -> right = new Node ( 7 ) ; root -> right -> left -> right = new Node ( 8 ) ; root -> right -> right -> right = new Node ( 9 ) ; cout << verticalWidth ( root ) << " STRNEWLINE " ; return 0 ; }

Accumulator variables: stdc
Class/struct names: Node
C++ program:
#include <bits/stdc++.h>
using namespace std ; int calc ( int a , int b ) { return a * b + ( b - a ) ; } int findMaximum ( vector < int > arr , int N ) { sort ( arr . begin ( ) , arr . end ( ) ) ; int ans = -1e9 ; ans = max ( ans , calc ( arr [ 0 ] , arr [ 1 ] ) ) ; ans = max ( ans , calc ( arr [ N - 2 ] , arr [ N - 1 ] ) ) ; return ans ; } int main ( ) { vector < int > arr = { 0 , -47 , 12 } ; int N = ( int ) arr . size ( ) ; cout << findMaximum ( arr , N ) ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; int minKBitFlips ( int A [ ] , int K , int N ) { queue < int > flip ; int count = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( flip . size ( ) > 0 && ( i - flip . front ( ) >= K ) ) { flip . pop ( ) ; } if ( A [ i ] % 2 == flip . size ( ) % 2 ) { if ( i + K - 1 >= N ) { return -1 ; } count ++ ; } } return count ; } int main ( ) { int A [ ] = { 0 , 1 , 0 } ; int N = sizeof ( A ) / sizeof ( A [ 0 ] ) ; int K = 1 ; int ans = minKBitFlips ( A , K , 3 ) ; cout << ans ; return 0 ; }

Index/key variables: i
Accumulator variables: count, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int minKBitFlips ( int A [ ] , int K , int N ) { int temp [ N ] ; memset ( temp , 0 , N ) ; int count = 0 ; int flip = 0 ; count ++ ; for ( int i = 0 ; i < N ; ++ i ) { flip ^= temp [ i ] ; if ( A [ i ] == flip ) { count ++ ; if ( i + K > N ) { return -1 ; } flip ^= 1 ; if ( i + K < N ) { temp [ i + K ] ^= 1 ; } } } return count ; } int main ( ) { int A [ ] = { 0 , 1 , 0 } ; int N = sizeof ( A ) / sizeof ( A [ 0 ] ) ; int K = 1 ; int ans = minKBitFlips ( A , K , N ) ; cout << ans ; return 0 ; }

Index/key variables: N, i
Accumulator variables: count, flip, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void findKthElement ( int N , int K ) { vector < int > v ; for ( int i = 1 ; i <= N ; i ++ ) { if ( i % 2 == 0 ) { v . push_back ( i ) ; } } for ( int i = 1 ; i <= N ; i ++ ) { if ( i % 2 != 0 ) { v . push_back ( i ) ; } } cout << v [ K - 1 ] ; } int main ( ) { int N = 10 , K = 3 ; findKthElement ( N , K ) ; return 0 ; }

Accumulator variables: i, stdc
Iterator variables: i