dhyuti-n/xlcost-variable-roles huggingface dataset:
C++ program:
#include <bits/stdc++.h>
using namespace std ; void preCalculate ( int binary [ ] , int n , pair < int , int > left [ ] ) { int count1 = 0 , count0 = 0 ; for ( int i = 0 ; i < n ; i ++ ) { left [ i ] . first = count1 ; left [ i ] . second = count0 ; if ( binary [ i ] ) count1 ++ ; else count0 ++ ; } } int main ( ) { int binary [ ] = { 1 , 1 , 1 , 0 , 0 , 1 , 0 , 1 , 1 } ; int n = sizeof ( binary ) / sizeof ( binary [ 0 ] ) ; pair < int , int > left [ n ] ; preCalculate ( binary , n , left ) ; int queries [ ] = { 0 , 1 , 2 , 4 } ; int q = sizeof ( queries ) / sizeof ( queries [ 0 ] ) ; for ( int i = 0 ; i < q ; i ++ ) cout << left [ queries [ i ] ] . first << " ▁ ones ▁ " << left [ queries [ i ] ] . second << " ▁ zeros STRNEWLINE " ; return 0 ; }

Index/key variables: i, n
Accumulator variables: count0, count1, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int countPairs ( int arr [ ] , int n ) { unordered_map < int , int > mp ; for ( int i = 0 ; i < n ; i ++ ) mp [ arr [ i ] ] ++ ; int ans = 0 ; for ( auto it = mp . begin ( ) ; it != mp . end ( ) ; it ++ ) { int count = it -> second ; ans += ( count * ( count - 1 ) ) / 2 ; } return ans ; } int main ( ) { int arr [ ] = { 1 , 1 , 2 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << countPairs ( arr , n ) << endl ; return 0 ; }

Index/key variables: i
Accumulator variables: ans, i, it, stdc
Iterator variables: i, it
C++ program:
#include <bits/stdc++.h>
using namespace std ; static int pos1 = -1 ; static int pos2 = -1 ; bool equiSumUtil ( int arr [ ] , int n ) { int pre [ n ] ; int sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) { sum += arr [ i ] ; pre [ i ] = sum ; } int suf [ n ] ; sum = 0 ; for ( int i = n - 1 ; i >= 0 ; i -- ) { sum += arr [ i ] ; suf [ i ] = sum ; } int total_sum = sum ; int i = 0 , j = n - 1 ; while ( i < j - 1 ) { if ( pre [ i ] == total_sum / 3 ) { pos1 = i ; } if ( suf [ j ] == total_sum / 3 ) { pos2 = j ; } if ( pos1 != -1 && pos2 != -1 ) { if ( suf [ pos1 + 1 ] - suf [ pos2 ] == total_sum / 3 ) { return true ; } else { return false ; } } if ( pre [ i ] < suf [ j ] ) { i ++ ; } else { j -- ; } } return false ; } void equiSum ( int arr [ ] , int n ) { bool ans = equiSumUtil ( arr , n ) ; if ( ans ) { cout << " First ▁ Segment ▁ : ▁ " ; for ( int i = 0 ; i <= pos1 ; i ++ ) { cout << arr [ i ] << " ▁ " ; } cout << endl ; cout << " Second ▁ Segment ▁ : ▁ " ; for ( int i = pos1 + 1 ; i < pos2 ; i ++ ) { cout << arr [ i ] << " ▁ " ; } cout << endl ; cout << " Third ▁ Segment ▁ : ▁ " ; for ( int i = pos2 ; i < n ; i ++ ) { cout << arr [ i ] << " ▁ " ; } cout << endl ; } else { cout << " Array ▁ cannot ▁ be ▁ divided ▁ into ▁ three ▁ equal ▁ sum ▁ segments " ; } } int main ( ) { int arr [ ] = { 1 , 3 , 6 , 2 , 7 , 1 , 2 , 8 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; equiSum ( arr , n ) ; return 0 ; }

Index/key variables: i, j, n, pos2
Accumulator variables: i, j, stdc, sum
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define p  101
#define MOD  1000000007
struct Query { int L , R ; } ; bool isPalindrome ( string str , int L , int R ) { while ( R > L ) if ( str [ L ++ ] != str [ R -- ] ) return ( false ) ; return ( true ) ; } unsigned long long int modPow ( unsigned long long int base , unsigned long long int exponent ) { if ( exponent == 0 ) return 1 ; if ( exponent == 1 ) return base ; unsigned long long int temp = modPow ( base , exponent / 2 ) ; if ( exponent % 2 == 0 ) return ( temp % MOD * temp % MOD ) % MOD ; else return ( ( ( temp % MOD * temp % MOD ) % MOD ) * base % MOD ) % MOD ; } unsigned long long int findMMI ( unsigned long long int n ) { return modPow ( n , MOD - 2 ) ; } void computePrefixHash ( string str , int n , unsigned long long int prefix [ ] , unsigned long long int power [ ] ) { prefix [ 0 ] = 0 ; prefix [ 1 ] = str [ 0 ] ; for ( int i = 2 ; i <= n ; i ++ ) prefix [ i ] = ( prefix [ i - 1 ] % MOD + ( str [ i - 1 ] % MOD * power [ i - 1 ] % MOD ) % MOD ) % MOD ; return ; } void computeSuffixHash ( string str , int n , unsigned long long int suffix [ ] , unsigned long long int power [ ] ) { suffix [ 0 ] = 0 ; suffix [ 1 ] = str [ n - 1 ] ; for ( int i = n - 2 , j = 2 ; i >= 0 && j <= n ; i -- , j ++ ) suffix [ j ] = ( suffix [ j - 1 ] % MOD + ( str [ i ] % MOD * power [ j - 1 ] % MOD ) % MOD ) % MOD ; return ; } void queryResults ( string str , Query q [ ] , int m , int n , unsigned long long int prefix [ ] , unsigned long long int suffix [ ] , unsigned long long int power [ ] ) { for ( int i = 0 ; i <= m - 1 ; i ++ ) { int L = q [ i ] . L ; int R = q [ i ] . R ; unsigned long long hash_LR = ( ( prefix [ R + 1 ] - prefix [ L ] + MOD ) % MOD * findMMI ( power [ L ] ) % MOD ) % MOD ; unsigned long long reverse_hash_LR = ( ( suffix [ n - L ] - suffix [ n - R - 1 ] + MOD ) % MOD * findMMI ( power [ n - R - 1 ] ) % MOD ) % MOD ; if ( hash_LR == reverse_hash_LR ) { if ( isPalindrome ( str , L , R ) == true ) printf ( " The ▁ Substring ▁ [ % d ▁ % d ] ▁ is ▁ a ▁ " " palindrome STRNEWLINE " , L , R ) ; else printf ( " The ▁ Substring ▁ [ % d ▁ % d ] ▁ is ▁ not ▁ a ▁ " " palindrome STRNEWLINE " , L , R ) ; } else printf ( " The ▁ Substring ▁ [ % d ▁ % d ] ▁ is ▁ not ▁ a ▁ " " palindrome STRNEWLINE " , L , R ) ; } return ; } void computePowers ( unsigned long long int power [ ] , int n ) { power [ 0 ] = 1 ; for ( int i = 1 ; i <= n ; i ++ ) power [ i ] = ( power [ i - 1 ] % MOD * p % MOD ) % MOD ; return ; } int main ( ) { string str = " abaaabaaaba " ; int n = str . length ( ) ; unsigned long long int power [ n + 1 ] ; computePowers ( power , n ) ; unsigned long long int prefix [ n + 1 ] , suffix [ n + 1 ] ; computePrefixHash ( str , n , prefix , power ) ; computeSuffixHash ( str , n , suffix , power ) ; Query q [ ] = { { 0 , 10 } , { 5 , 8 } , { 2 , 5 } , { 5 , 9 } } ; int m = sizeof ( q ) / sizeof ( q [ 0 ] ) ; queryResults ( str , q , m , n , prefix , suffix , power ) ; return ( 0 ) ; }

Index/key variables: L, i, j
Accumulator variables: L, R, i, j, stdc
Iterator variables: i
Class/struct names: Query
C++ program:
#include <bits/stdc++.h>
using namespace std ; struct Node { int data ; Node * left , * right ; } ; Node * newNode ( int item ) { Node * temp = new Node ; temp -> data = item ; temp -> left = temp -> right = NULL ; return temp ; } int getLevel ( Node * root , Node * node , int level ) { if ( root == NULL ) return 0 ; if ( root == node ) return level ; int downlevel = getLevel ( root -> left , node , level + 1 ) ; if ( downlevel != 0 ) return downlevel ; return getLevel ( root -> right , node , level + 1 ) ; } void printGivenLevel ( Node * root , Node * node , int level ) { if ( root == NULL level < 2 ) return ; if ( level == 2 ) { if ( root -> left == node root -> right == node ) return ; if ( root -> left ) cout << root -> left -> data << " ▁ " ; if ( root -> right ) cout << root -> right -> data ; } else if ( level > 2 ) { printGivenLevel ( root -> left , node , level - 1 ) ; printGivenLevel ( root -> right , node , level - 1 ) ; } } void printCousins ( Node * root , Node * node ) { int level = getLevel ( root , node , 1 ) ; printGivenLevel ( root , node , level ) ; } 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 -> left -> right -> right = newNode ( 15 ) ; root -> right -> left = newNode ( 6 ) ; root -> right -> right = newNode ( 7 ) ; root -> right -> left -> right = newNode ( 8 ) ; printCousins ( root , root -> left -> right ) ; return 0 ; }

Accumulator variables: stdc
Class/struct names: Node
C++ program:
#include <bits/stdc++.h>
using namespace std ; int getRightMin ( int arr [ ] , int n ) { int min = arr [ 0 ] ; int rightMin = 0 ; int i = 1 ; while ( i < n ) { if ( arr [ i ] == min ) rightMin = i ; i *= 2 ; } i = rightMin + 1 ; while ( i < n && arr [ i ] == min ) { rightMin = i ; i ++ ; } return rightMin ; } int getLeftMax ( int arr [ ] , int n ) { int max = arr [ n - 1 ] ; int leftMax = n - 1 ; int i = n - 2 ; while ( i > 0 ) { if ( arr [ i ] == max ) leftMax = i ; i /= 2 ; } i = leftMax - 1 ; while ( i >= 0 && arr [ i ] == max ) { leftMax = i ; i -- ; } return leftMax ; } int main ( ) { int arr [ ] = { 0 , 0 , 1 , 2 , 5 , 5 , 6 , 8 , 8 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << " Minimum ▁ left ▁ : ▁ " << 0 << " STRNEWLINE " ; cout << " Minimum ▁ right ▁ : ▁ " << getRightMin ( arr , n ) << " STRNEWLINE " ; cout << " Maximum ▁ left ▁ : ▁ " << getLeftMax ( arr , n ) << " STRNEWLINE " ; cout << " Maximum ▁ right ▁ : ▁ " << ( n - 1 ) ; }

Index/key variables: i
Accumulator variables: i, stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; int countNum ( int arr [ ] , int n ) { int count = 0 ; sort ( arr , arr + n ) ; for ( int i = 0 ; i < n - 1 ; i ++ ) if ( arr [ i ] != arr [ i + 1 ] && arr [ i ] != arr [ i + 1 ] - 1 ) count += arr [ i + 1 ] - arr [ i ] - 1 ; return count ; } int main ( ) { int arr [ ] = { 3 , 5 , 8 , 6 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << countNum ( arr , n ) << endl ; return 0 ; }

Index/key variables: i
Accumulator variables: count, i, stdc
Iterator variables: i
C++ program:
#include " iostream "
#include " queue "
#include " unordered _ map "
#include " vector "
using namespace std ; void findElementsAfterDel ( int arr [ ] , int m , int del [ ] , int n , int k ) { unordered_map < int , int > mp ; for ( int i = 0 ; i < n ; ++ i ) { mp [ del [ i ] ] ++ ; } priority_queue < int , vector < int > , greater < int > > heap ; for ( int i = 0 ; i < m ; ++ i ) { if ( mp . find ( arr [ i ] ) != mp . end ( ) ) { mp [ arr [ i ] ] -- ; if ( mp [ arr [ i ] ] == 0 ) mp . erase ( arr [ i ] ) ; } else heap . push ( arr [ i ] ) ; } for ( int i = 0 ; i < k ; ++ i ) { cout << heap . top ( ) << " ▁ " ; heap . pop ( ) ; } } int main ( ) { int array [ ] = { 5 , 12 , 33 , 4 , 56 , 12 , 20 } ; int m = sizeof ( array ) / sizeof ( array [ 0 ] ) ; int del [ ] = { 12 , 56 , 5 } ; int n = sizeof ( del ) / sizeof ( del [ 0 ] ) ; int k = 3 ; findElementsAfterDel ( array , m , del , n , k ) ; return 0 ; }

Index/key variables: i
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int countNum ( int arr [ ] , int n ) { unordered_set < int > s ; int count = 0 , maxm = INT_MIN , minm = INT_MAX ; for ( int i = 0 ; i < n ; i ++ ) { s . insert ( arr [ i ] ) ; if ( arr [ i ] < minm ) minm = arr [ i ] ; if ( arr [ i ] > maxm ) maxm = arr [ i ] ; } for ( int i = minm ; i <= maxm ; i ++ ) if ( s . find ( arr [ i ] ) == s . end ( ) ) count ++ ; return count ; } int main ( ) { int arr [ ] = { 3 , 5 , 8 , 6 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << countNum ( arr , n ) << endl ; return 0 ; }

Index/key variables: i
Accumulator variables: count, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool isPossible ( int A [ ] , int n , int H , int K ) { int time = 0 ; for ( int i = 0 ; i < n ; ++ i ) time += ( A [ i ] - 1 ) / K + 1 ; return time <= H ; } int minJobSpeed ( int A [ ] , int n , int H ) { if ( H < n ) return -1 ; int * max = max_element ( A , A + n ) ; int lo = 1 , hi = * max ; while ( lo < hi ) { int mi = lo + ( hi - lo ) / 2 ; if ( ! isPossible ( A , n , H , mi ) ) lo = mi + 1 ; else hi = mi ; } return lo ; } int main ( ) { int A [ ] = { 3 , 6 , 7 , 11 } , H = 8 ; int n = sizeof ( A ) / sizeof ( A [ 0 ] ) ; cout << minJobSpeed ( A , n , H ) ; return 0 ; }

Index/key variables: i
Accumulator variables: stdc, time
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
#define MAXN  11
#define ver  2
int hashtable [ ver ] [ MAXN ] ; int pos [ ver ] ; void initTable ( ) { for ( int j = 0 ; j < MAXN ; j ++ ) for ( int i = 0 ; i < ver ; i ++ ) hashtable [ i ] [ j ] = INT_MIN ; } int hash ( int function , int key ) { switch ( function ) { case 1 : return key % MAXN ; case 2 : return ( key / MAXN ) % MAXN ; } } void place ( int key , int tableID , int cnt , int n ) { if ( cnt == n ) { printf ( " % d ▁ unpositioned STRNEWLINE " , key ) ; printf ( " Cycle ▁ present . ▁ REHASH . STRNEWLINE " ) ; return ; } for ( int i = 0 ; i < ver ; i ++ ) { pos [ i ] = hash ( i + 1 , key ) ; if ( hashtable [ i ] [ pos [ i ] ] == key ) return ; } if ( hashtable [ tableID ] [ pos [ tableID ] ] != INT_MIN ) { int dis = hashtable [ tableID ] [ pos [ tableID ] ] ; hashtable [ tableID ] [ pos [ tableID ] ] = key ; place ( dis , ( tableID + 1 ) % ver , cnt + 1 , n ) ; } else hashtable [ tableID ] [ pos [ tableID ] ] = key ; } void printTable ( ) { printf ( " Final ▁ hash ▁ tables : STRNEWLINE " ) ; for ( int i = 0 ; i < ver ; i ++ , printf ( " STRNEWLINE " ) ) for ( int j = 0 ; j < MAXN ; j ++ ) ( hashtable [ i ] [ j ] == INT_MIN ) ? printf ( " - ▁ " ) : printf ( " % d ▁ " , hashtable [ i ] [ j ] ) ; printf ( " STRNEWLINE " ) ; } void cuckoo ( int keys [ ] , int n ) { initTable ( ) ; for ( int i = 0 , cnt = 0 ; i < n ; i ++ , cnt = 0 ) place ( keys [ i ] , 0 , cnt , n ) ; printTable ( ) ; } int main ( ) { int keys_1 [ ] = { 20 , 50 , 53 , 75 , 100 , 67 , 105 , 3 , 36 , 39 } ; int n = sizeof ( keys_1 ) / sizeof ( int ) ; cuckoo ( keys_1 , n ) ; int keys_2 [ ] = { 20 , 50 , 53 , 75 , 100 , 67 , 105 , 3 , 36 , 39 , 6 } ; int m = sizeof ( keys_2 ) / sizeof ( int ) ; cuckoo ( keys_2 , m ) ; return 0 ; }

Index/key variables: MAXN, i, j, tableID, ver
Accumulator variables: i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; int countAnomalies ( int a [ ] , int n , int k ) { sort ( a , a + n ) ; int res = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int * u = upper_bound ( a , a + n , a [ i ] ) ; if ( u != a + n && ( ( * u ) - a [ i ] ) <= k ) continue ; int * s = lower_bound ( a , a + n , a [ i ] ) ; if ( u - s > 1 ) continue ; if ( s != a && ( * ( s - 1 ) - a [ i ] ) <= k ) continue ; res ++ ; } return res ; } int main ( ) { int arr [ ] = { 7 , 1 , 8 } , k = 5 ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << countAnomalies ( arr , n , k ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, res, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int sumoflength ( int arr [ ] , int n ) { unordered_set < int > s ; int j = 0 , ans = 0 ; for ( int i = 0 ; i < n ; i ++ ) { while ( j < n && s . find ( arr [ j ] ) == s . end ( ) ) { s . insert ( arr [ j ] ) ; j ++ ; } ans += ( ( j - i ) * ( j - i + 1 ) ) / 2 ; s . erase ( arr [ i ] ) ; } return ans ; } int main ( ) { int arr [ ] = { 1 , 2 , 3 , 4 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << sumoflength ( arr , n ) << endl ; return 0 ; }

Index/key variables: i, j
Accumulator variables: ans, i, j, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int countDistictSubarray ( int arr [ ] , int n ) { unordered_map < int , int > vis ; for ( int i = 0 ; i < n ; ++ i ) vis [ arr [ i ] ] = 1 ; int k = vis . size ( ) ; vis . clear ( ) ; int ans = 0 , right = 0 , window = 0 ; for ( int left = 0 ; left < n ; ++ left ) { while ( right < n && window < k ) { ++ vis [ arr [ right ] ] ; if ( vis [ arr [ right ] ] == 1 ) ++ window ; ++ right ; } if ( window == k ) ans += ( n - right + 1 ) ; -- vis [ arr [ left ] ] ; if ( vis [ arr [ left ] ] == 0 ) -- window ; } return ans ; } int main ( ) { int arr [ ] = { 2 , 1 , 3 , 2 , 3 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << countDistictSubarray ( arr , n ) << " n " ; return 0 ; }

Index/key variables: i, left, right
Accumulator variables: ans, stdc
Iterator variables: i, left
C++ program:
#include <bits/stdc++.h>
using namespace std ; int countSubarrays ( int arr [ ] , int n ) { int difference = 0 ; int ans = 0 ; int hash_positive [ n + 1 ] , hash_negative [ n + 1 ] ; fill_n ( hash_positive , n + 1 , 0 ) ; fill_n ( hash_negative , n + 1 , 0 ) ; hash_positive [ 0 ] = 1 ; for ( int i = 0 ; i < n ; i ++ ) { if ( arr [ i ] & 1 == 1 ) difference ++ ; else difference -- ; if ( difference < 0 ) { ans += hash_negative [ - difference ] ; hash_negative [ - difference ] ++ ; } else { ans += hash_positive [ difference ] ; hash_positive [ difference ] ++ ; } } return ans ; } int main ( ) { int arr [ ] = { 3 , 4 , 6 , 8 , 1 , 10 , 5 , 7 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << " Total ▁ Number ▁ of ▁ Even - Odd ▁ subarrays " " ▁ are ▁ " << countSubarrays ( arr , n ) ; return 0 ; }

Index/key variables: difference, i
Accumulator variables: ans, difference, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; class node { public : int data ; node * left ; node * right ; } ; void printArray ( int [ ] , int ) ; void printPathsRecur ( node * , int [ ] , int ) ; node * newNode ( int ) ; void printPaths ( node * ) ; void printPaths ( node * node ) { int path [ 1000 ] ; printPathsRecur ( node , path , 0 ) ; } void printPathsRecur ( node * node , int path [ ] , int pathLen ) { if ( node == NULL ) return ; path [ pathLen ] = node -> data ; pathLen ++ ; if ( node -> left == NULL && node -> right == NULL ) { printArray ( path , pathLen ) ; } else { printPathsRecur ( node -> left , path , pathLen ) ; printPathsRecur ( node -> right , path , pathLen ) ; } } node * newNode ( int data ) { node * Node = new node ( ) ; Node -> data = data ; Node -> left = NULL ; Node -> right = NULL ; return ( Node ) ; } void printArray ( int ints [ ] , int len ) { int i ; for ( i = 0 ; i < len ; i ++ ) { cout << ints [ i ] << " ▁ " ; } cout << endl ; } int main ( ) { node * root = newNode ( 1 ) ; root -> left = newNode ( 2 ) ; root -> right = newNode ( 3 ) ; root -> left -> left = newNode ( 4 ) ; root -> left -> right = newNode ( 5 ) ; printPaths ( root ) ; return 0 ; }

Index/key variables: i, pathLen
Accumulator variables: i, pathLen, stdc
Iterator variables: i
Class/struct names: node
C++ program:
#include <bits/stdc++.h>
using namespace std ; class node { public : string info ; node * left = NULL , * right = NULL ; node ( string x ) { info = x ; } } ; int toInt ( string s ) { int num = 0 ; if ( s [ 0 ] != ' - ' ) for ( int i = 0 ; i < s . length ( ) ; i ++ ) num = num * 10 + ( int ( s [ i ] ) - 48 ) ; else for ( int i = 1 ; i < s . length ( ) ; i ++ ) { num = num * 10 + ( int ( s [ i ] ) - 48 ) ; num = num * -1 ; } return num ; } int eval ( node * root ) { if ( ! root ) return 0 ; if ( ! root -> left && ! root -> right ) return toInt ( root -> info ) ; int l_val = eval ( root -> left ) ; int r_val = eval ( root -> right ) ; if ( root -> info == " + " ) return l_val + r_val ; if ( root -> info == " - " ) return l_val - r_val ; if ( root -> info == " * " ) return l_val * r_val ; return l_val / r_val ; } int main ( ) { node * root = new node ( " + " ) ; root -> left = new node ( " * " ) ; root -> left -> left = new node ( "5" ) ; root -> left -> right = new node ( " - 4" ) ; root -> right = new node ( " - " ) ; root -> right -> left = new node ( "100" ) ; root -> right -> right = new node ( "20" ) ; cout << eval ( root ) << endl ; delete ( root ) ; root = new node ( " + " ) ; root -> left = new node ( " * " ) ; root -> left -> left = new node ( "5" ) ; root -> left -> right = new node ( "4" ) ; root -> right = new node ( " - " ) ; root -> right -> left = new node ( "100" ) ; root -> right -> right = new node ( " / " ) ; root -> right -> right -> left = new node ( "20" ) ; root -> right -> right -> right = new node ( "2" ) ; cout << eval ( root ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
Class/struct names: node
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define MAX  100
bool search ( int mat [ ] [ MAX ] , int m , int n , int x ) { int i = m - 1 , j = 0 ; while ( i >= 0 && j < n ) { if ( mat [ i ] [ j ] == x ) return true ; if ( mat [ i ] [ j ] > x ) i -- ; else j ++ ; } return false ; } int main ( ) { int mat [ ] [ MAX ] = { { 10 , 20 , 30 , 40 } , { 15 , 25 , 35 , 45 } , { 27 , 29 , 37 , 48 } , { 32 , 33 , 39 , 50 } , { 50 , 60 , 70 , 80 } , } ; if ( search ( mat , 5 , 4 , 29 ) ) cout << " Yes " ; else cout << " No " ; return 0 ; }

Index/key variables: MAX, i, j
Accumulator variables: i, j, stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; int distinctIds ( int arr [ ] , int n , int mi ) { unordered_map < int , int > m ; vector < pair < int , int > > v ; int count = 0 ; for ( int i = 0 ; i < n ; i ++ ) m [ arr [ i ] ] ++ ; for ( auto it = m . begin ( ) ; it != m . end ( ) ; it ++ ) v . push_back ( make_pair ( it -> second , it -> first ) ) ; sort ( v . begin ( ) , v . end ( ) ) ; int size = v . size ( ) ; for ( int i = 0 ; i < size ; i ++ ) { if ( v [ i ] . first <= mi ) { mi -= v [ i ] . first ; count ++ ; } else return size - count ; } return size - count ; } int main ( ) { int arr [ ] = { 2 , 3 , 1 , 2 , 3 , 3 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int m = 3 ; cout << distinctIds ( arr , n , m ) ; return 0 ; }

Index/key variables: i
Accumulator variables: count, i, it, mi, stdc
Iterator variables: i, it
C++ program:
#include <bits/stdc++.h>
using namespace std ; void printGreaterCount ( string str ) { int len = str . length ( ) , right [ len ] = { 0 } ; for ( int i = 0 ; i < len ; i ++ ) for ( int j = i + 1 ; j < len ; j ++ ) if ( str [ i ] < str [ j ] ) right [ i ] ++ ; for ( int i = 0 ; i < len ; i ++ ) cout << right [ i ] << " ▁ " ; } int main ( ) { string str = " abcd " ; printGreaterCount ( str ) ; return 0 ; }

Index/key variables: i, j, len
Accumulator variables: i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; int findLongestConseqSubseq ( int arr [ ] , int n ) { unordered_set < int > S ; for ( int i = 0 ; i < n ; i ++ ) S . insert ( arr [ i ] ) ; int ans = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( S . find ( arr [ i ] - 1 ) == S . end ( ) ) { int j = arr [ i ] ; while ( S . find ( j ) != S . end ( ) ) j ++ ; ans = max ( ans , j - arr [ i ] ) ; } } return ans ; } int main ( ) { int arr [ ] = { 1 , 94 , 93 , 1000 , 5 , 92 , 78 } ; int n = sizeof ( arr ) / sizeof ( int ) ; cout << findLongestConseqSubseq ( arr , n ) << endl ; return 0 ; }

Index/key variables: i
Accumulator variables: i, j, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int appearsNBy3 ( int arr [ ] , int n ) { int count1 = 0 , count2 = 0 ; int first = INT_MAX , second = INT_MAX ; for ( int i = 0 ; i < n ; i ++ ) { if ( first == arr [ i ] ) count1 ++ ; else if ( second == arr [ i ] ) count2 ++ ; else if ( count1 == 0 ) { count1 ++ ; first = arr [ i ] ; } else if ( count2 == 0 ) { count2 ++ ; second = arr [ i ] ; } else { count1 -- ; count2 -- ; } } count1 = 0 ; count2 = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( arr [ i ] == first ) count1 ++ ; else if ( arr [ i ] == second ) count2 ++ ; } if ( count1 > n / 3 ) return first ; if ( count2 > n / 3 ) return second ; return -1 ; } int main ( ) { int arr [ ] = { 1 , 2 , 3 , 1 , 1 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << appearsNBy3 ( arr , n ) << endl ; return 0 ; }

Index/key variables: i
Accumulator variables: count1, count2, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int count4Divisibiles ( int arr [ ] , int n ) { int freq [ 4 ] = { 0 , 0 , 0 , 0 } ; for ( int i = 0 ; i < n ; i ++ ) ++ freq [ arr [ i ] % 4 ] ; int ans = freq [ 0 ] * ( freq [ 0 ] - 1 ) / 2 ; ans += freq [ 2 ] * ( freq [ 2 ] - 1 ) / 2 ; ans += freq [ 1 ] * freq [ 3 ] ; return ans ; } int main ( ) { int arr [ ] = { 2 , 2 , 1 , 7 , 5 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << count4Divisibiles ( arr , n ) ; return 0 ; }

Index/key variables: i
Accumulator variables: ans, i, stdc
Iterator variables: i